boolean (final PsiElement psiElement) { if (psiElement instanceof ScopeOwner) { return true; //Do not go any further } if (!isRequiredStatement(psiElement)) { return false; //Parent has wrong type, skip } final List<PyExpression> varsDeclaredInStatement = getNamedElementsOfForAndWithStatements(psiElement); for (PyExpression varDeclaredInStatement : varsDeclaredInStatement) { //For each variable, declared by this parent take first declaration and open subscription list if any final PsiReference reference = handleSubscriptionsAndResolveSafely(varDeclaredInStatement).getReference(); if ((reference != null) && reference.isReferenceTo(myNode)) { return true; //One of variables declared by this parent refers to node } } return false; }