Search in sources :

Example 21 with ResolveResult

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

the class PyResolveTest method testToConstructorInherited.

public void testToConstructorInherited() {
    ResolveResult[] targets = multiResolve();
    // to class, to init
    assertEquals(2, targets.length);
    PsiElement elt;
    // class
    elt = targets[0].getElement();
    assertTrue(elt instanceof PyClass);
    assertEquals("Bar", ((PyClass) elt).getName());
    // init
    elt = targets[1].getElement();
    assertTrue(elt instanceof PyFunction);
    PyFunction fun = (PyFunction) elt;
    assertEquals(PyNames.INIT, fun.getName());
    PyClass cls = fun.getContainingClass();
    assertNotNull(cls);
    assertEquals("Foo", cls.getName());
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement)

Example 22 with ResolveResult

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

the class RngHighlightingTest method testResolveIncludedRef2.

public void testResolveIncludedRef2() throws Throwable {
    myTestFixture.copyFileToProject("include.rng");
    final PsiReference ref = myTestFixture.getReferenceAtCaretPositionWithAssertion("resolve-include-ref-2.rng");
    assertTrue("PolyVariantRef", ref instanceof PsiPolyVariantReference);
    final PsiElement element = ref.resolve();
    assertNull(element);
    final ResolveResult[] results = ((PsiPolyVariantReference) ref).multiResolve(false);
    assertEquals(2, results.length);
    for (ResolveResult result : results) {
        PsiElement e = result.getElement();
        assertTrue(e instanceof XmlTag);
        final int contentLength = ((XmlTag) e).getSubTags().length;
        if (e.getContainingFile() == ref.getElement().getContainingFile()) {
            assertEquals(1, contentLength);
        } else {
            assertEquals(0, contentLength);
        }
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) ResolveResult(com.intellij.psi.ResolveResult) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 23 with ResolveResult

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

the class PyResolveTest method testUnresolvedImport.

public void testUnresolvedImport() {
    final ResolveResult[] results = multiResolve();
    assertEquals(1, results.length);
    UsefulTestCase.assertInstanceOf(results[0], ImportedResolveResult.class);
    ImportedResolveResult result = (ImportedResolveResult) results[0];
    assertNull(result.getElement());
}
Also used : ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ImportedResolveResult(com.jetbrains.python.psi.resolve.ImportedResolveResult) ResolveResult(com.intellij.psi.ResolveResult)

Example 24 with ResolveResult

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

the class IpnbPyReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    ResolveResult[] results = super.multiResolve(incompleteCode);
    if (results.length == 0) {
        PsiFile file = myElement.getContainingFile();
        if (file instanceof IpnbPyFragment) {
            final IpnbFilePanel panel = ((IpnbPyFragment) file).getFilePanel();
            final List<IpnbEditablePanel> panels = panel.getIpnbPanels();
            final String referencedName = myElement.getReferencedName();
            if (referencedName == null)
                return ResolveResult.EMPTY_ARRAY;
            for (IpnbEditablePanel editablePanel : panels) {
                if (!(editablePanel instanceof IpnbCodePanel))
                    continue;
                final Editor editor = ((IpnbCodePanel) editablePanel).getEditor();
                final IpnbPyFragment psiFile = (IpnbPyFragment) PsiDocumentManager.getInstance(myElement.getProject()).getPsiFile(editor.getDocument());
                if (psiFile == null)
                    continue;
                final PyResolveProcessor processor = new PyResolveProcessor(referencedName);
                PyResolveUtil.scopeCrawlUp(processor, psiFile, referencedName, psiFile);
                final List<RatedResolveResult> resultList = getResultsFromProcessor(referencedName, processor, psiFile, psiFile);
                if (resultList.size() > 0) {
                    List<RatedResolveResult> ret = RatedResolveResult.sorted(resultList);
                    return ret.toArray(new RatedResolveResult[ret.size()]);
                }
            }
        }
    }
    return results;
}
Also used : IpnbEditablePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbEditablePanel) IpnbFilePanel(org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel) PsiFile(com.intellij.psi.PsiFile) IpnbCodePanel(org.jetbrains.plugins.ipnb.editor.panels.code.IpnbCodePanel) Editor(com.intellij.openapi.editor.Editor) ResolveResult(com.intellij.psi.ResolveResult) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with ResolveResult

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

the class ImportTest method testImportModuleExceptNameArity.

public void testImportModuleExceptNameArity() {
    myFixture.configureByFiles("import_module_except_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)

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