private static void putCaretOnFieldName(Editor editor, PsiElement occurrence) { PyQualifiedExpression qExpr = PsiTreeUtil.getParentOfType(occurrence, PyQualifiedExpression.class, false); if (qExpr != null && !qExpr.isQualified()) { qExpr = PsiTreeUtil.getParentOfType(qExpr, PyQualifiedExpression.class); } if (qExpr != null) { final ASTNode nameElement = qExpr.getNameElement(); if (nameElement != null) { final int offset = nameElement.getTextRange().getStartOffset(); editor.getCaretModel().moveToOffset(offset); } } }
/** @param self should be this */ @NotNull private static List<PyAssignmentStatement> findAttributesStatic(@NotNull final PsiElement self) { final List<PyAssignmentStatement> result = new ArrayList<>(); for (final PyAssignmentStatement statement : new PsiQuery(self).siblings(PyAssignmentStatement.class).getElements()) { for (final PyQualifiedExpression targetExpression : new PsiQuery(statement.getTargets()).filter(PyQualifiedExpression.class).getElements()) { final PyExpression qualifier = targetExpression.getQualifier(); if (qualifier == null) { continue; } final PsiReference qualifierReference = qualifier.getReference(); if (qualifierReference == null) { continue; } if (qualifierReference.isReferenceTo(self)) { result.add(statement); } } } return result; }