private void checkExpression(PyQualifiedExpression node) { final PyExpression qualifier = node.getQualifier(); if (qualifier != null) { final PyType type = myTypeEvalContext.getType(qualifier); if (type instanceof PyClassType) { final PyClass cls = ((PyClassType) type).getPyClass(); final String name = node.getName(); if (name != null) { final Pair<PyClass, String> key = new Pair<PyClass, String>(cls, name); final Property property; if (myPropertyCache.containsKey(key)) { property = myPropertyCache.get(key); } else { property = cls.findProperty(name, true); } myPropertyCache.put( key, property); // we store nulls, too, to know that a property does not exist if (property != null) { final AccessDirection dir = AccessDirection.of(node); checkAccessor(node, name, dir, property); if (dir == AccessDirection.READ) { final PsiElement parent = node.getParent(); if (parent instanceof PyAugAssignmentStatement && ((PyAugAssignmentStatement) parent).getTarget() == node) { checkAccessor(node, name, AccessDirection.WRITE, property); } } } } } } }
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; }