PyStatementList (PsiElement psiElement, Editor editor) { if (psiElement instanceof PyStatementListContainer) { return ((PyStatementListContainer)psiElement).getStatementList(); } else { final CaretModel caretModel = editor.getCaretModel(); final PsiElement atCaret = psiElement.getContainingFile().findElementAt(caretModel.getOffset()); final PyStatementPart statementPart = PsiTreeUtil.getParentOfType(atCaret, PyStatementPart.class); if (statementPart != null) { return statementPart.getStatementList(); } } return null; }