use of com.intellij.usages.PsiElementUsageTarget in project smali by JesusFreke.
the class FindUsagesTest method doTest.
protected void doTest() {
PsiReference reference = null;
PsiElement targetElement = null;
for (TestFile testFile : testFiles) {
int refIndex = testFile.getRefIndex();
if (refIndex != -1) {
PsiElement element = testFile.psiFile.findElementAt(refIndex);
UsageTarget[] targets = UsageTargetUtil.findUsageTargets(element);
if (targets != null) {
for (UsageTarget target : targets) {
if (target instanceof PsiElementUsageTarget) {
targetElement = ((PsiElementUsageTarget) target).getElement();
break;
}
}
}
if (targetElement == null) {
reference = testFile.psiFile.findReferenceAt(refIndex);
if (reference != null) {
targetElement = reference.resolve();
} else {
targetElement = TargetElementUtilBase.getInstance().getNamedElement(testFile.psiFile.findElementAt(refIndex), 0);
}
}
break;
}
}
Assert.assertNotNull(targetElement);
Collection<UsageInfo> usages = findUsages(targetElement);
for (TestFile testFile : testFiles) {
assertUsages(testFile, usages);
}
}
use of com.intellij.usages.PsiElementUsageTarget in project android by JetBrains.
the class AndroidFindUsagesTest method findUsages.
private static Collection<UsageInfo> findUsages(String fileName, final JavaCodeInsightTestFixture fixture, String newFilePath) throws Throwable {
VirtualFile file = fixture.copyFileToProject(BASE_PATH + fileName, newFilePath);
fixture.configureFromExistingVirtualFile(file);
final UsageTarget[] targets = UsageTargetUtil.findUsageTargets(new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
return ((EditorEx) fixture.getEditor()).getDataContext().getData(dataId);
}
});
assert targets != null && targets.length > 0 && targets[0] instanceof PsiElementUsageTarget;
return fixture.findUsages(((PsiElementUsageTarget) targets[0]).getElement());
}
use of com.intellij.usages.PsiElementUsageTarget in project intellij-community by JetBrains.
the class FindUsagesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return;
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
UsageTarget[] usageTargets = e.getData(UsageView.USAGE_TARGETS_KEY);
if (usageTargets == null) {
final Editor editor = e.getData(CommonDataKeys.EDITOR);
chooseAmbiguousTargetAndPerform(project, editor, element -> {
startFindUsages(element);
return false;
});
} else {
UsageTarget target = usageTargets[0];
if (target instanceof PsiElementUsageTarget) {
PsiElement element = ((PsiElementUsageTarget) target).getElement();
if (element != null) {
startFindUsages(element);
}
} else {
target.findUsages();
}
}
}
Aggregations