Search in sources :

Example 16 with PsiScopeProcessor

use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.

the class PyModuleType method getVisibleImports.

@NotNull
public static List<PyImportElement> getVisibleImports(@NotNull ScopeOwner owner) {
    final List<PyImportElement> visibleImports = new ArrayList<>();
    PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if (element instanceof PyImportElement) {
                visibleImports.add((PyImportElement) element);
            }
            return true;
        }

        @Nullable
        @Override
        public <T> T getHint(@NotNull Key<T> hintKey) {
            return null;
        }

        @Override
        public void handleEvent(@NotNull Event event, @Nullable Object associated) {
        }
    }, owner, null, null);
    return visibleImports;
}
Also used : ArrayList(java.util.ArrayList) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with PsiScopeProcessor

use of com.intellij.psi.scope.PsiScopeProcessor in project intellij-community by JetBrains.

the class PyDebugProcess method resolveInCurrentFrame.

@NotNull
private static Ref<PsiElement> resolveInCurrentFrame(final String name, XSourcePosition currentPosition, PsiFile file) {
    final Ref<PsiElement> elementRef = Ref.create();
    PsiElement currentElement = file.findElementAt(currentPosition.getOffset());
    if (currentElement == null) {
        return elementRef;
    }
    PyResolveUtil.scopeCrawlUp(new PsiScopeProcessor() {

        @Override
        public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) {
            if ((element instanceof PyImportElement)) {
                PyImportElement importElement = (PyImportElement) element;
                if (name.equals(importElement.getVisibleName())) {
                    if (elementRef.isNull()) {
                        elementRef.set(element);
                    }
                    return false;
                }
                return true;
            } else {
                if (elementRef.isNull()) {
                    elementRef.set(element);
                }
                return false;
            }
        }

        @Nullable
        @Override
        public <T> T getHint(@NotNull Key<T> hintKey) {
            return null;
        }

        @Override
        public void handleEvent(@NotNull Event event, @Nullable Object associated) {
        }
    }, currentElement, name, null);
    return elementRef;
}
Also used : AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ProcessEvent(com.intellij.execution.process.ProcessEvent) PsiScopeProcessor(com.intellij.psi.scope.PsiScopeProcessor) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable) ResolveState(com.intellij.psi.ResolveState) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)17 NotNull (org.jetbrains.annotations.NotNull)11 Nullable (org.jetbrains.annotations.Nullable)5 ASTNode (com.intellij.lang.ASTNode)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 com.intellij.psi (com.intellij.psi)3 DelegatingScopeProcessor (com.intellij.psi.scope.DelegatingScopeProcessor)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 Processor (com.intellij.util.Processor)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 GrCodeReferenceElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement)3 JavaCompletionProcessor (com.intellij.codeInsight.completion.scope.JavaCompletionProcessor)2 Project (com.intellij.openapi.project.Project)2 Key (com.intellij.openapi.util.Key)2 Ref (com.intellij.openapi.util.Ref)2 ResolveState (com.intellij.psi.ResolveState)2 com.intellij.psi.util (com.intellij.psi.util)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ArrayList (java.util.ArrayList)2 GrImportStatement (org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement)2