Search in sources :

Example 51 with PsiReference

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

the class HighlightingTestBase method doTestQuickFix.

@SuppressWarnings({ "deprecation", "unchecked" })
protected void doTestQuickFix(String file, String ext) {
    final PsiReference psiReference = myTestFixture.getReferenceAtCaretPositionWithAssertion(file + "." + ext);
    assertNull("Reference", psiReference.resolve());
    assertTrue(psiReference.getClass().getName() + " is not a QuickFixProvider", psiReference instanceof LocalQuickFixProvider);
    final LocalQuickFix[] fixes = ((LocalQuickFixProvider) psiReference).getQuickFixes();
    assertTrue("One action expected", fixes != null && fixes.length == 1);
    final Project project = myTestFixture.getProject();
    final ProblemDescriptor problemDescriptor = InspectionManager.getInstance(project).createProblemDescriptor(psiReference.getElement(), "foo", fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true);
    new WriteCommandAction.Simple(project, myTestFixture.getFile()) {

        @Override
        protected void run() throws Throwable {
            fixes[0].applyFix(project, problemDescriptor);
        }
    }.execute();
    myTestFixture.checkResultByFile(file + "_after." + ext);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) PsiReference(com.intellij.psi.PsiReference)

Example 52 with PsiReference

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

the class MavenDomTestCase method doAssertResolved.

private PsiReference doAssertResolved(VirtualFile file, PsiElement expected) throws IOException {
    assertNotNull("expected reference is null", expected);
    PsiReference ref = getReferenceAtCaret(file);
    assertNotNull(ref);
    PsiElement resolved = ref.resolve();
    if (resolved instanceof MavenPsiElementWrapper) {
        resolved = ((MavenPsiElementWrapper) resolved).getWrappee();
    }
    assertEquals(expected, resolved);
    return ref;
}
Also used : PsiReference(com.intellij.psi.PsiReference) MavenPsiElementWrapper(org.jetbrains.idea.maven.dom.references.MavenPsiElementWrapper) PsiElement(com.intellij.psi.PsiElement)

Example 53 with PsiReference

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

the class MavenDomTestCase method assertNoReferences.

protected void assertNoReferences(VirtualFile file, Class refClass) throws IOException {
    PsiReference ref = getReferenceAtCaret(file);
    if (ref == null)
        return;
    PsiReference[] refs = ref instanceof PsiMultiReference ? ((PsiMultiReference) ref).getReferences() : new PsiReference[] { ref };
    for (PsiReference each : refs) {
        assertFalse(each.toString(), refClass.isInstance(each));
    }
}
Also used : PsiReference(com.intellij.psi.PsiReference) PsiMultiReference(com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)

Example 54 with PsiReference

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

the class MavenDomTestCase method search.

protected List<PsiElement> search(VirtualFile file) throws IOException {
    final MapDataContext context = createDataContext(file);
    UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            return context.getData(dataId);
        }
    });
    PsiElement target = ((PsiElement2UsageTargetAdapter) targets[0]).getElement();
    List<PsiReference> result = new ArrayList<>(ReferencesSearch.search(target).findAll());
    return ContainerUtil.map(result, psiReference -> psiReference.getElement());
}
Also used : DataProvider(com.intellij.openapi.actionSystem.DataProvider) MapDataContext(com.intellij.testFramework.MapDataContext) ArrayList(java.util.ArrayList) PsiElement2UsageTargetAdapter(com.intellij.find.findUsages.PsiElement2UsageTargetAdapter) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget)

Example 55 with PsiReference

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

the class MavenFilteredPropertiesCompletionAndResolutionTest method testReferencesInXml.

public void testReferencesInXml() throws Exception {
    createProjectSubDir("res");
    importProject("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<build>" + "  <resources>" + "    <resource>" + "      <directory>res</directory>" + "      <filtering>true</filtering>" + "    </resource>" + "  </resources>" + "</build>");
    VirtualFile f = createProjectSubFile("res/foo.xml", "<root attr='${based<caret>ir}'>" + "</root>");
    myFixture.configureFromExistingVirtualFile(f);
    XmlAttribute attribute = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getCaretOffset()), XmlAttribute.class);
    PsiReference[] references = attribute.getReferences();
    for (PsiReference ref : references) {
        if (ref.resolve() instanceof PsiDirectory) {
            // Maven references was added.
            return;
        }
    }
    assertTrue("Maven filter reference was not added", false);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) PsiDirectory(com.intellij.psi.PsiDirectory) MavenPropertyPsiReference(org.jetbrains.idea.maven.dom.references.MavenPropertyPsiReference) PsiReference(com.intellij.psi.PsiReference)

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