Search in sources :

Example 6 with PyFunctionStub

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

the class PyClassImpl method getTargetExpressions.

@NotNull
private static List<PyTargetExpression> getTargetExpressions(@NotNull PyFunction function) {
    final PyFunctionStub stub = function.getStub();
    if (stub != null) {
        return Arrays.asList(stub.getChildrenByType(PyElementTypes.TARGET_EXPRESSION, PyTargetExpression.EMPTY_ARRAY));
    } else {
        final PyStatementList statementList = function.getStatementList();
        final List<PyTargetExpression> result = new ArrayList<>();
        statementList.accept(new PyRecursiveElementVisitor() {

            @Override
            public void visitPyClass(PyClass node) {
            }

            public void visitPyAssignmentStatement(final PyAssignmentStatement node) {
                for (PyExpression expression : node.getTargets()) {
                    if (expression instanceof PyTargetExpression) {
                        result.add((PyTargetExpression) expression);
                    }
                }
            }

            @Override
            public void visitPyWithStatement(PyWithStatement node) {
                StreamEx.of(node.getWithItems()).map(PyWithItem::getTarget).select(PyTargetExpression.class).forEach(result::add);
            }
        });
        return result;
    }
}
Also used : PyFunctionStub(com.jetbrains.python.psi.stubs.PyFunctionStub) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PyFunctionStub (com.jetbrains.python.psi.stubs.PyFunctionStub)6 PsiElement (com.intellij.psi.PsiElement)3 StubElement (com.intellij.psi.stubs.StubElement)3 PyClassStub (com.jetbrains.python.psi.stubs.PyClassStub)3 Nullable (org.jetbrains.annotations.Nullable)3 ASTNode (com.intellij.lang.ASTNode)2 PsiComment (com.intellij.psi.PsiComment)2 StubBasedPsiElement (com.intellij.psi.StubBasedPsiElement)2 NotNull (org.jetbrains.annotations.NotNull)2 ItemPresentation (com.intellij.navigation.ItemPresentation)1 Extensions (com.intellij.openapi.extensions.Extensions)1 Key (com.intellij.openapi.util.Key)1 Ref (com.intellij.openapi.util.Ref)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 StringUtil.notNullize (com.intellij.openapi.util.text.StringUtil.notNullize)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiReference (com.intellij.psi.PsiReference)1 LocalSearchScope (com.intellij.psi.search.LocalSearchScope)1 SearchScope (com.intellij.psi.search.SearchScope)1 IStubElementType (com.intellij.psi.stubs.IStubElementType)1