Search in sources :

Example 6 with ResolveState

use of com.intellij.psi.ResolveState 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)

Example 7 with ResolveState

use of com.intellij.psi.ResolveState in project intellij-elixir by KronicDeth.

the class Variants method lookupElementList.

/*
     * Static Methods
     */
@Nullable
public static List<LookupElement> lookupElementList(@NotNull PsiElement entrance) {
    Variants variants = new Variants();
    Parameter parameter = Parameter.putParameterized(new Parameter(entrance));
    Call entranceCallDefinitionClause = null;
    if (parameter.isCallDefinitionClauseName()) {
        entranceCallDefinitionClause = (Call) parameter.parameterized;
    }
    ResolveState resolveState = ResolveState.initial().put(ENTRANCE, entrance).put(ENTRANCE_CALL_DEFINITION_CLAUSE, entranceCallDefinitionClause);
    PsiTreeUtil.treeWalkUp(variants, entrance, entrance.getContainingFile(), resolveState);
    List<LookupElement> lookupElementList = new ArrayList<LookupElement>();
    lookupElementList.addAll(variants.getLookupElementCollection());
    return lookupElementList;
}
Also used : Call(org.elixir_lang.psi.call.Call) Parameter(org.elixir_lang.annonator.Parameter) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ResolveState(com.intellij.psi.ResolveState) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with ResolveState

use of com.intellij.psi.ResolveState in project intellij-elixir by KronicDeth.

the class CallDefinitionClause method implicitImports.

private boolean implicitImports(@NotNull PsiElement element, @NotNull ResolveState state) {
    Project project = element.getProject();
    boolean keepProcessing = org.elixir_lang.reference.Module.forEachNavigationElement(project, KERNEL, new Function<PsiElement, Boolean>() {

        @Override
        public Boolean fun(PsiElement navigationElement) {
            boolean keepProcessingNavigationElements = true;
            if (navigationElement instanceof Call) {
                Call modular = (Call) navigationElement;
                keepProcessingNavigationElements = Modular.callDefinitionClauseCallWhile(modular, new Function<Call, Boolean>() {

                    @Override
                    public Boolean fun(Call callDefinitionClause) {
                        return executeOnCallDefinitionClause(callDefinitionClause, state);
                    }
                });
            }
            return keepProcessingNavigationElements;
        }
    });
    // the implicit `import Kernel.SpecialForms`
    if (keepProcessing) {
        ResolveState modularCanonicalNameState = state.put(MODULAR_CANONICAL_NAME, KERNEL_SPECIAL_FORMS);
        keepProcessing = org.elixir_lang.reference.Module.forEachNavigationElement(project, KERNEL_SPECIAL_FORMS, new Function<PsiElement, Boolean>() {

            @Override
            public Boolean fun(PsiElement navigationElement) {
                boolean keepProcessingNavigationElements = true;
                if (navigationElement instanceof Call) {
                    Call modular = (Call) navigationElement;
                    keepProcessingNavigationElements = Modular.callDefinitionClauseCallWhile(modular, new Function<Call, Boolean>() {

                        @Override
                        public Boolean fun(Call callDefinitionClause) {
                            return executeOnCallDefinitionClause(callDefinitionClause, modularCanonicalNameState);
                        }
                    });
                }
                return keepProcessingNavigationElements;
            }
        });
    }
    return keepProcessing;
}
Also used : Project(com.intellij.openapi.project.Project) Call(org.elixir_lang.psi.call.Call) Function(com.intellij.util.Function) PsiElement(com.intellij.psi.PsiElement) ResolveState(com.intellij.psi.ResolveState)

Aggregations

ResolveState (com.intellij.psi.ResolveState)8 PsiElement (com.intellij.psi.PsiElement)5 NotNull (org.jetbrains.annotations.NotNull)4 PsiScopeProcessor (com.intellij.psi.scope.PsiScopeProcessor)3 Call (org.elixir_lang.psi.call.Call)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 JSAttributeList (com.intellij.lang.javascript.psi.ecmal4.JSAttributeList)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Project (com.intellij.openapi.project.Project)2 Function (com.intellij.util.Function)2 Nullable (org.jetbrains.annotations.Nullable)2 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 MxmlJSClass (com.intellij.javascript.flex.mxml.MxmlJSClass)1 XmlBackedJSClassImpl (com.intellij.lang.javascript.flex.XmlBackedJSClassImpl)1 JSAttribute (com.intellij.lang.javascript.psi.ecmal4.JSAttribute)1 JSAttributeNameValuePair (com.intellij.lang.javascript.psi.ecmal4.JSAttributeNameValuePair)1 ResolveProcessor (com.intellij.lang.javascript.psi.resolve.ResolveProcessor)1 BaseCreateMethodsFix (com.intellij.lang.javascript.validation.fixes.BaseCreateMethodsFix)1 JSAttributeListWrapper (com.intellij.lang.javascript.validation.fixes.JSAttributeListWrapper)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1