Search in sources :

Example 1 with PyStatementPart

use of com.jetbrains.python.psi.PyStatementPart in project intellij-community by JetBrains.

the class PyPlainEnterProcessor method getStatementList.

@Nullable
private static PyStatementList getStatementList(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;
}
Also used : PyStatementListContainer(com.jetbrains.python.psi.PyStatementListContainer) CaretModel(com.intellij.openapi.editor.CaretModel) PyStatementPart(com.jetbrains.python.psi.PyStatementPart) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

CaretModel (com.intellij.openapi.editor.CaretModel)1 PsiElement (com.intellij.psi.PsiElement)1 PyStatementListContainer (com.jetbrains.python.psi.PyStatementListContainer)1 PyStatementPart (com.jetbrains.python.psi.PyStatementPart)1 Nullable (org.jetbrains.annotations.Nullable)1