Search in sources :

Example 1 with PyRecursiveElementVisitor

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

the class PyDependentModuleMembersCollector method collect.

@Override
public void collect(final PsiNamedElement member) {
    if (member.getContainingFile() == myModule) {
        final PyResolveContext resolveContext = PyResolveContext.defaultContext();
        final PsiElement memberBody = PyMoveModuleMembersHelper.expandNamedElementBody(member);
        assert memberBody != null;
        memberBody.accept(new PyRecursiveElementVisitor() {

            @Override
            public void visitElement(PsiElement element) {
                for (PsiElement result : PyUtil.multiResolveTopPriority(element, resolveContext)) {
                    if (result != null && isValidSameModuleDependency(result) && result != member) {
                        myCollection.add((PsiNamedElement) result);
                    }
                }
                super.visitElement(element);
            }
        });
    }
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PsiNamedElement(com.intellij.psi.PsiNamedElement) PyRecursiveElementVisitor(com.jetbrains.python.psi.PyRecursiveElementVisitor) PsiElement(com.intellij.psi.PsiElement)

Example 2 with PyRecursiveElementVisitor

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

the class PyRenameUnresolvedRefQuickFix method collectExpressionsToRename.

private static List<PyReferenceExpression> collectExpressionsToRename(@NotNull final PyReferenceExpression expression, @NotNull final ScopeOwner parentScope) {
    final List<PyReferenceExpression> result = new ArrayList<>();
    PyRecursiveElementVisitor visitor = new PyRecursiveElementVisitor() {

        @Override
        public void visitPyReferenceExpression(PyReferenceExpression node) {
            if (node.textMatches(expression) && !isValidReference(node.getReference())) {
                result.add(node);
            }
            super.visitPyReferenceExpression(node);
        }
    };
    parentScope.accept(visitor);
    return result;
}
Also used : PyRecursiveElementVisitor(com.jetbrains.python.psi.PyRecursiveElementVisitor) PyReferenceExpression(com.jetbrains.python.psi.PyReferenceExpression)

Aggregations

PyRecursiveElementVisitor (com.jetbrains.python.psi.PyRecursiveElementVisitor)2 PsiElement (com.intellij.psi.PsiElement)1 PsiNamedElement (com.intellij.psi.PsiNamedElement)1 PyReferenceExpression (com.jetbrains.python.psi.PyReferenceExpression)1 PyResolveContext (com.jetbrains.python.psi.resolve.PyResolveContext)1