Search in sources :

Example 1 with ResolveResult

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

the class NestedTest method testReference.

public void testReference() {
    myFixture.configureByFiles("reference.ex", "suffix.ex", "nested.ex");
    PsiElement alias = myFixture.getFile().findElementAt(myFixture.getCaretOffset()).getParent().getPrevSibling();
    assertInstanceOf(alias, QualifiedAlias.class);
    PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) alias.getReference();
    assertNotNull(polyVariantReference);
    ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
    assertEquals(2, resolveResults.length);
    // alias
    assertEquals("alias Prefix.Suffix, as: As", resolveResults[0].getElement().getParent().getParent().getParent().getParent().getParent().getText());
    // defmodule
    assertEquals("defmodule Prefix.Suffix.Nested do\nend", resolveResults[1].getElement().getText());
}
Also used : ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 2 with ResolveResult

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

the class ImportTest method testImportModule.

/*
     * Tests
     */
public void testImportModule() {
    myFixture.configureByFiles("import_module.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertEquals("imported", call.functionName());
    assertEquals(0, call.resolvedFinalArity());
    PsiReference reference = call.getReference();
    assertNotNull(reference);
    assertInstanceOf(reference, PsiPolyVariantReference.class);
    PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
    ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
    assertEquals(2, resolveResults.length);
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 3 with ResolveResult

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

the class ImportTest method testImportModuleOnlyNameArity.

public void testImportModuleOnlyNameArity() {
    myFixture.configureByFiles("import_module_only_name_arity.ex", "imported.ex");
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assertNotNull(elementAtCaret);
    PsiElement maybeCall = elementAtCaret.getParent().getParent();
    assertInstanceOf(maybeCall, Call.class);
    Call call = (Call) maybeCall;
    assertEquals("imported", call.functionName());
    assertEquals(0, call.resolvedFinalArity());
    PsiReference reference = call.getReference();
    assertNotNull(reference);
    assertInstanceOf(reference, PsiPolyVariantReference.class);
    PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
    ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
    assertEquals(2, resolveResults.length);
}
Also used : Call(org.elixir_lang.psi.call.Call) PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference)

Example 4 with ResolveResult

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

the class PyDocReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    ResolveResult[] results = super.multiResolve(incompleteCode);
    if (results.length == 0) {
        final InjectedLanguageManager languageManager = InjectedLanguageManager.getInstance(myElement.getProject());
        final PsiLanguageInjectionHost host = languageManager.getInjectionHost(myElement);
        final String referencedName = myElement.getReferencedName();
        if (referencedName == null)
            return ResolveResult.EMPTY_ARRAY;
        if (host != null) {
            final List<Pair<PsiElement, TextRange>> files = languageManager.getInjectedPsiFiles(host);
            if (files != null) {
                for (Pair<PsiElement, TextRange> pair : files) {
                    final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
                    PyResolveUtil.scopeCrawlUp(processor, (ScopeOwner) pair.getFirst(), referencedName, pair.getFirst());
                    final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, pair.getFirst(), pair.getFirst());
                    if (resultList.size() > 0) {
                        List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
                        return ret.toArray(new RatedResolveResult[ret.size()]);
                    }
                }
            }
            final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
            final ScopeOwner scopeOwner = getHostScopeOwner();
            if (scopeOwner != null) {
                final PsiFile topLevel = scopeOwner.getContainingFile();
                PyResolveUtil.scopeCrawlUp(processor, scopeOwner, referencedName, topLevel);
                final PsiElement referenceAnchor = getScopeControlFlowAnchor(host);
                final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, referenceAnchor, topLevel);
                if (resultList.size() > 0) {
                    final List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
                    return ret.toArray(new RatedResolveResult[ret.size()]);
                }
            }
        }
    }
    return results;
}
Also used : TextRange(com.intellij.openapi.util.TextRange) InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) ScopeOwner(com.jetbrains.python.codeInsight.controlflow.ScopeOwner) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) PsiFile(com.intellij.psi.PsiFile) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ResolveResult

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

the class PyResolveTest method testImplicitResolveInstanceAttribute.

public void testImplicitResolveInstanceAttribute() {
    ResolveResult[] resolveResults = multiResolve();
    assertEquals(1, resolveResults.length);
    final PsiElement psiElement = resolveResults[0].getElement();
    assertTrue(psiElement instanceof PyTargetExpression && "xyzzy".equals(((PyTargetExpression) psiElement).getName()));
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

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