Search in sources :

Example 96 with PsiReference

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

the class FlexRenameTest method testRenameClassTwoTimes.

public void testRenameClassTwoTimes() throws Exception {
    final String name = getTestName(false);
    VirtualFile file = getVirtualFile(getBasePath() + name + "/mytest/foo/" + name + "_2.js2");
    VirtualFile[] files = { getVirtualFile(getBasePath() + name + "/mytest/boo/" + name + ".js2"), file };
    configureByFiles(new File(getTestDataPath() + getBasePath() + name), files);
    int referencesCount = findRenamedRefsToReferencedElementAtCaret().length;
    performAction(name + "_3", true);
    checkResultByFile(getBasePath() + name + "_after.js2");
    assertEquals(referencesCount, findRenamedRefsToReferencedElementAtCaret().length);
    performAction(name + "_4", true);
    checkResultByFile(getBasePath() + name + "_after2.js2");
    PsiReference[] refs = findRenamedRefsToReferencedElementAtCaret();
    assertEquals(referencesCount, refs.length);
    for (PsiReference ref : refs) {
        PsiElement refElement = ref.getElement();
        PsiElement refElementParent = refElement.getParent();
        assertFalse(refElementParent instanceof JSReferenceExpression);
        if (!(refElementParent instanceof JSImportStatement)) {
            assertEquals(name + "_4", refElement.getText());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSImportStatement(com.intellij.lang.javascript.psi.ecmal4.JSImportStatement) PsiReference(com.intellij.psi.PsiReference) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiElement(com.intellij.psi.PsiElement)

Example 97 with PsiReference

use of com.intellij.psi.PsiReference in project android by JetBrains.

the class AndroidGotoDeclarationHandlerTest method getDeclarationsFrom.

@Nullable
private PsiElement[] getDeclarationsFrom(VirtualFile file) {
    myFixture.configureFromExistingVirtualFile(file);
    // AndroidGotoDeclarationHandler only handles .java files. We also want to check .xml files, so
    // we use GotoDeclarationAction instead of creating AndroidGotoDeclarationHandler and invoking getGotoDeclarationTargets
    // on it directly.
    PsiElement[] elements = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
    if (elements.length == 0) {
        final PsiReference reference = TargetElementUtil.findReference(myFixture.getEditor(), myFixture.getCaretOffset());
        if (reference != null) {
            final Collection<PsiElement> candidates = TargetElementUtil.getInstance().getTargetCandidates(reference);
            elements = PsiUtilCore.toPsiElementArray(candidates);
        }
    }
    return elements;
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 98 with PsiReference

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

the class FiltersTest method testFilterBuiltinResolve.

public void testFilterBuiltinResolve() {
    myFixture.configureByFiles("filterBuiltin.resolve.html", "angular.js");
    int offsetBySignature = AngularTestUtil.findOffsetBySignature("js<caret>on", myFixture.getFile());
    PsiReference ref = myFixture.getFile().findReferenceAt(offsetBySignature);
    assertNotNull(ref);
    PsiElement resolve = ref.resolve();
    assertNotNull(resolve);
    assertEquals("angular.js", resolve.getContainingFile().getName());
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 99 with PsiReference

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

the class FiltersTest method testPipeResolve.

public void testPipeResolve() {
    JSTestUtils.testWithinLanguageLevel(JSLanguageLevel.ES6, getProject(), () -> {
        myFixture.configureByFiles("filterCustom.resolve.html", "angular2.js", "custom.ts");
        int offsetBySignature = AngularTestUtil.findOffsetBySignature("fil<caret>ta", myFixture.getFile());
        PsiReference ref = myFixture.getFile().findReferenceAt(offsetBySignature);
        assertNotNull(ref);
        PsiElement resolve = ref.resolve();
        assertNotNull(resolve);
        assertEquals("custom.ts", resolve.getContainingFile().getName());
        assertEquals("Pipe({\n" + "    name: \"filta\"\n" + "})", resolve.getParent().getText());
    });
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 100 with PsiReference

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

the class FiltersTest method testFilterCustomResolve.

public void testFilterCustomResolve() {
    myFixture.configureByFiles("filterCustom.resolve.html", "angular.js", "custom.js");
    int offsetBySignature = AngularTestUtil.findOffsetBySignature("fil<caret>ta", myFixture.getFile());
    PsiReference ref = myFixture.getFile().findReferenceAt(offsetBySignature);
    assertNotNull(ref);
    PsiElement resolve = ref.resolve();
    assertNotNull(resolve);
    assertEquals("custom.js", resolve.getContainingFile().getName());
    assertEquals("\"filta\"", resolve.getParent().getText());
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiReference (com.intellij.psi.PsiReference)564 PsiElement (com.intellij.psi.PsiElement)327 NotNull (org.jetbrains.annotations.NotNull)97 Nullable (org.jetbrains.annotations.Nullable)55 TextRange (com.intellij.openapi.util.TextRange)54 PsiFile (com.intellij.psi.PsiFile)52 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)36 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)32 IdentifierPSINode (org.ballerinalang.plugins.idea.psi.IdentifierPSINode)25 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)23 XmlTag (com.intellij.psi.xml.XmlTag)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)20 PsiClass (com.intellij.psi.PsiClass)17 XmlAttribute (com.intellij.psi.xml.XmlAttribute)17 LinkedList (java.util.LinkedList)17 LookupElement (com.intellij.codeInsight.lookup.LookupElement)16 Project (com.intellij.openapi.project.Project)16