PyClass (@NotNull final Editor editor, @NotNull final PsiFile file) { int offset = editor.getCaretModel().getOffset(); PsiElement element = file.findElementAt(offset); if (element == null) { // are we in whitespace after last class? PY-440 final PsiElement lastChild = file.getLastChild(); if (lastChild != null && offset >= lastChild.getTextRange().getStartOffset() && offset <= lastChild.getTextRange().getEndOffset()) { element = lastChild; } } final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class, false); if (pyClass == null && element instanceof PsiWhiteSpace && element.getPrevSibling() instanceof PyClass) { return (PyClass)element.getPrevSibling(); } return pyClass; }