PsiElement (@NotNull DataContext dataContext) { PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(dataContext); if (element == null) { final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); if (editor != null && file != null) { element = file.findElementAt(editor.getCaretModel().getOffset()); } } if (!(element instanceof PyClass)) { element = PsiTreeUtil.getParentOfType(element, PyClass.class); } return element; }