Search in sources :

Example 16 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class ActionScriptResolveTest method testResolveInClassDynamic.

public void testResolveInClassDynamic() throws Exception {
    String fileText = "public class T {\n" + "  public function m() : String {\n" + "    return \"m\";\n" + "  }\n" + "\n" + "  public function test() : String {\n" + "    function foo():String {\n" + "      return this.<ref>m();\n" + "    }\n" + "    return foo();\n" + "  }\n" + "}\n" + "function m() {}";
    JSReferenceExpression ref = (JSReferenceExpression) configureByFileText(fileText, "sample.js2");
    ResolveResult[] results = ref.multiResolve(false);
    assertEquals(2, results.length);
}
Also used : JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) ResolveResult(com.intellij.psi.ResolveResult)

Example 17 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class CfmlResolveResult method create.

public static ResolveResult[] create(Collection<? extends PsiElement> from) {
    final ResolveResult[] results = from.size() > 0 ? new ResolveResult[from.size()] : EMPTY_ARRAY;
    int i = 0;
    for (PsiElement element : from) {
        results[i++] = new CfmlResolveResult(element);
    }
    return results;
}
Also used : PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 18 with ResolveResult

use of com.intellij.psi.ResolveResult in project intellij-plugins by JetBrains.

the class ActionScriptReferenceExpressionResolver method resolve.

@NotNull
@Override
public ResolveResult[] resolve(@NotNull JSReferenceExpressionImpl expression, boolean incompleteCode) {
    if (myReferencedName == null)
        return ResolveResult.EMPTY_ARRAY;
    PsiElement currentParent = JSResolveUtil.getTopReferenceParent(myParent);
    if (JSResolveUtil.isSelfReference(currentParent, myRef)) {
        if (!(currentParent instanceof JSPackageStatement) || myParent == currentParent) {
            return new ResolveResult[] { new JSResolveResult(currentParent) };
        }
    }
    if (isConditionalVariableReference(currentParent, myRef)) {
        if (ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
            // do not red highlight conditional compiler definitions in 3rd party library/SDK source code
            return new ResolveResult[] { new JSResolveResult(myRef) };
        } else {
            return resolveConditionalCompilationVariable(myRef);
        }
    }
    if (myRef.isAttributeReference()) {
        return dummyResult(myRef);
    }
    if (JSCommonTypeNames.ANY_TYPE.equals(myReferencedName)) {
        if (currentParent instanceof JSImportStatement && myQualifier instanceof JSReferenceExpression)
            return ((JSReferenceExpression) myQualifier).multiResolve(false);
        if (myParent instanceof JSE4XNamespaceReference)
            return dummyResult(myRef);
    }
    // nonqualified items in implements list in mxml
    if (myParent instanceof JSReferenceListMember && myParent.getParent().getNode().getElementType() == JSStubElementTypes.IMPLEMENTS_LIST && myRef.getQualifier() == null && myContainingFile instanceof JSFile && XmlBackedJSClassImpl.isImplementsAttribute((JSFile) myContainingFile)) {
        PsiElement byQName = ActionScriptClassResolver.findClassByQNameStatic(myRef.getText(), myRef);
        // for some reason Flex compiler allows to implement non-public interface in default package, so let's not check access type here
        if (byQName != null)
            return new ResolveResult[] { new JSResolveResult(byQName) };
        return ResolveResult.EMPTY_ARRAY;
    }
    SinkResolveProcessor<ResolveResultSink> localProcessor;
    if (myLocalResolve) {
        final PsiElement topParent = JSResolveUtil.getTopReferenceParent(myParent);
        localProcessor = new SinkResolveProcessor<ResolveResultSink>(myReferencedName, myRef, new ResolveResultSink(myRef, myReferencedName)) {

            @Override
            public boolean needPackages() {
                if (myParent instanceof JSReferenceExpression && topParent instanceof JSImportStatement) {
                    return true;
                }
                return super.needPackages();
            }
        };
        localProcessor.setToProcessHierarchy(true);
        JSReferenceExpressionImpl.doProcessLocalDeclarations(myRef, myQualifier, localProcessor, true, false, null);
        PsiElement jsElement = localProcessor.getResult();
        if (myQualifier instanceof JSThisExpression && localProcessor.processingEncounteredAnyTypeAccess() && // this is from ecma script closure, proceed it in JavaScript way
        jsElement != null) {
            localProcessor.getResults().clear();
            jsElement = null;
        }
        if (myQualifier == null) {
            final JSReferenceExpression namespaceReference = JSReferenceExpressionImpl.getNamespaceReference(myRef);
            ResolveResult[] resolveResultsAsConditionalCompilationVariable = null;
            if (namespaceReference != null && (namespaceReference == myRef || namespaceReference.resolve() == namespaceReference)) {
                if (jsElement == null && ModuleUtilCore.findModuleForPsiElement(myRef) == null) {
                    // do not red highlight conditional compiler definitions in 3rd party library/SDK source code
                    return new ResolveResult[] { new JSResolveResult(myRef) };
                }
                resolveResultsAsConditionalCompilationVariable = resolveConditionalCompilationVariable(myRef);
            }
            if (resolveResultsAsConditionalCompilationVariable != null && resolveResultsAsConditionalCompilationVariable.length > 0 && (jsElement == null || resolveResultsAsConditionalCompilationVariable[0].isValidResult())) {
                return resolveResultsAsConditionalCompilationVariable;
            }
        }
        if (jsElement != null || localProcessor.isEncounteredDynamicClasses() && myQualifier == null || !localProcessor.processingEncounteredAnyTypeAccess() && !localProcessor.isEncounteredDynamicClasses()) {
            return localProcessor.getResultsAsResolveResults();
        }
    } else {
        final QualifiedItemProcessor<ResolveResultSink> processor = new QualifiedItemProcessor<>(new ResolveResultSink(myRef, myReferencedName), myContainingFile);
        processor.setTypeContext(JSResolveUtil.isExprInTypeContext(myRef));
        JSTypeEvaluator.evaluateTypes(myQualifier, myContainingFile, processor);
        if (processor.resolved == QualifiedItemProcessor.TypeResolveState.PrefixUnknown) {
            return dummyResult(myRef);
        }
        if (processor.resolved == QualifiedItemProcessor.TypeResolveState.Resolved || processor.resolved == QualifiedItemProcessor.TypeResolveState.Undefined || processor.getResult() != null) {
            return processor.getResultsAsResolveResults();
        } else {
            localProcessor = processor;
        }
    }
    ResolveResult[] results = resolveFromIndices(localProcessor);
    if (results.length == 0 && localProcessor.isEncounteredXmlLiteral()) {
        return dummyResult(myRef);
    }
    return results;
}
Also used : JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSE4XNamespaceReference(com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference) JSReferenceListMember(com.intellij.lang.javascript.psi.ecmal4.JSReferenceListMember) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ResolveResult

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

the class MavenGroovyPomCompletionWeigher method weigh.

@Override
public Comparable weigh(@NotNull LookupElement element, @NotNull CompletionLocation location) {
    PsiFile containingFile = location.getCompletionParameters().getPosition().getContainingFile();
    if (!(containingFile instanceof GroovyFileBase)) {
        return null;
    }
    if (!"pom.groovy".equals(containingFile.getName()))
        return null;
    Object o = element.getObject();
    if (o instanceof ResolveResult) {
        o = ((ResolveResult) o).getElement();
    }
    if (o instanceof DynamicMemberUtils.DynamicElement) {
        return 1;
    } else {
        return -1;
    }
}
Also used : GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) PsiFile(com.intellij.psi.PsiFile) ResolveResult(com.intellij.psi.ResolveResult)

Example 20 with ResolveResult

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

the class TemplateReference method multiResolve.

@NotNull
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final PsiElement element = resolve();
    if (element != null) {
        return new ResolveResult[] { new PsiElementResolveResult(element) };
    }
    final XmlFile xmlFile = (XmlFile) getElement().getContainingFile();
    if (xmlFile != null) {
        final List<PsiElementResolveResult> targets = new SmartList<>();
        XsltIncludeIndex.processBackwardDependencies(xmlFile, xmlFile1 -> {
            final PsiElement e = ResolveUtil.resolve(new NamedTemplateMatcher(xmlFile1.getDocument(), myName));
            if (e != null) {
                targets.add(new PsiElementResolveResult(e));
            }
            return true;
        });
        return targets.toArray(new ResolveResult[targets.size()]);
    } else {
        return ResolveResult.EMPTY_ARRAY;
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) NamedTemplateMatcher(org.intellij.lang.xpath.xslt.util.NamedTemplateMatcher) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) SmartList(com.intellij.util.SmartList) PsiElementResolveResult(com.intellij.psi.PsiElementResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ResolveResult (com.intellij.psi.ResolveResult)30 PsiElement (com.intellij.psi.PsiElement)25 PsiPolyVariantReference (com.intellij.psi.PsiPolyVariantReference)10 NotNull (org.jetbrains.annotations.NotNull)8 PsiReference (com.intellij.psi.PsiReference)5 PsiElementResolveResult (com.intellij.psi.PsiElementResolveResult)4 PsiFile (com.intellij.psi.PsiFile)4 ImportedResolveResult (com.jetbrains.python.psi.resolve.ImportedResolveResult)3 Call (org.elixir_lang.psi.call.Call)3 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)2 JSE4XNamespaceReference (com.intellij.lang.javascript.psi.e4x.JSE4XNamespaceReference)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Nullable (org.jetbrains.annotations.Nullable)2 GoReference (com.goide.psi.impl.GoReference)1 LocalQuickFix (com.intellij.codeInspection.LocalQuickFix)1 ProblemHighlightType (com.intellij.codeInspection.ProblemHighlightType)1 ASTNode (com.intellij.lang.ASTNode)1 InjectedLanguageManager (com.intellij.lang.injection.InjectedLanguageManager)1