Search in sources :

Example 1 with PyForStatement

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

the class PyForStatementNavigator method getPyForStatementByIterable.

@Nullable
public static PyForStatement getPyForStatementByIterable(final PsiElement element) {
    final PyForStatement forStatement = PsiTreeUtil.getParentOfType(element, PyForStatement.class, false);
    if (forStatement == null) {
        return null;
    }
    final PyExpression target = forStatement.getForPart().getTarget();
    if (target != null && PsiTreeUtil.isAncestor(target, element, false)) {
        return forStatement;
    }
    return null;
}
Also used : PyForStatement(com.jetbrains.python.psi.PyForStatement) PyExpression(com.jetbrains.python.psi.PyExpression) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PyForStatement

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

the class PyForStatementNavigator method getPyForStatementByBody.

@Nullable
public static Object getPyForStatementByBody(final PsiElement element) {
    final PyForStatement forStatement = PsiTreeUtil.getParentOfType(element, PyForStatement.class, false);
    if (forStatement == null) {
        return null;
    }
    final PyForPart forPart = forStatement.getForPart();
    return forPart == element || forPart.getStatementList() == element ? forStatement : null;
}
Also used : PyForStatement(com.jetbrains.python.psi.PyForStatement) PyForPart(com.jetbrains.python.psi.PyForPart) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PyForStatement (com.jetbrains.python.psi.PyForStatement)2 Nullable (org.jetbrains.annotations.Nullable)2 PyExpression (com.jetbrains.python.psi.PyExpression)1 PyForPart (com.jetbrains.python.psi.PyForPart)1