Search in sources :

Example 6 with PyClassStub

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

the class PyClassImpl method getClassAttributes.

public List<PyTargetExpression> getClassAttributes() {
    PyClassStub stub = getStub();
    if (stub != null) {
        final PyTargetExpression[] children = stub.getChildrenByType(PyElementTypes.TARGET_EXPRESSION, PyTargetExpression.EMPTY_ARRAY);
        return Arrays.asList(children);
    }
    List<PyTargetExpression> result = new ArrayList<>();
    for (PsiElement psiElement : getStatementList().getChildren()) {
        if (psiElement instanceof PyAssignmentStatement) {
            final PyAssignmentStatement assignmentStatement = (PyAssignmentStatement) psiElement;
            final PyExpression[] targets = assignmentStatement.getTargets();
            for (PyExpression target : targets) {
                if (target instanceof PyTargetExpression) {
                    result.add((PyTargetExpression) target);
                }
            }
        }
    }
    return result;
}
Also used : PyClassStub(com.jetbrains.python.psi.stubs.PyClassStub)

Aggregations

PyClassStub (com.jetbrains.python.psi.stubs.PyClassStub)6 StubElement (com.intellij.psi.stubs.StubElement)3 PsiElement (com.intellij.psi.PsiElement)2 PyFunctionStub (com.jetbrains.python.psi.stubs.PyFunctionStub)2 PyTargetExpressionStub (com.jetbrains.python.psi.stubs.PyTargetExpressionStub)2 StubBasedPsiElement (com.intellij.psi.StubBasedPsiElement)1 PropertyStubStorage (com.jetbrains.python.psi.stubs.PropertyStubStorage)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1