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);
}
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;
}
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));
}
}
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());
}
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);
}
Aggregations