use of com.intellij.usages.UsageTarget 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.usages.UsageTarget 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.UsageTarget in project intellij-community by JetBrains.
the class UsageViewTreeModelBuilder method addTargetNodes.
private void addTargetNodes() {
ApplicationManager.getApplication().assertIsDispatchThread();
if (myTargets.length == 0)
return;
myTargetNodes = new UsageTargetNode[myTargets.length];
myTargetsNode.removeAllChildren();
for (int i = 0; i < myTargets.length; i++) {
UsageTarget target = myTargets[i];
UsageTargetNode targetNode = new UsageTargetNode(target);
myTargetsNode.add(targetNode);
myTargetNodes[i] = targetNode;
}
myRootNode.addTargetsNode(myTargetsNode, this);
reload(myTargetsNode);
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class JavaUsageTypeProviderTest method assertUsageType.
private void assertUsageType(UsageType expected, PsiClass target) {
UsageTarget[] targets = { new PsiElement2UsageTargetAdapter(target) };
PsiElement element = myFixture.getReferenceAtCaretPositionWithAssertion().getElement();
UsageType usageType = new JavaUsageTypeProvider().getUsageType(element, targets);
assertEquals(expected, usageType);
}
use of com.intellij.usages.UsageTarget in project intellij-community by JetBrains.
the class UsageViewManagerTest method testScopeCreatedForFindInDirectory.
public void testScopeCreatedForFindInDirectory() {
VirtualFile dir = getProject().getBaseDir();
FindModel findModel = new FindModel();
findModel.setDirectoryName(dir.getPath());
findModel.setWithSubdirectories(true);
findModel.setProjectScope(false);
UsageTarget target = new FindInProjectUtil.StringUsageTarget(getProject(), findModel);
UsageViewManagerImpl manager = (UsageViewManagerImpl) UsageViewManager.getInstance(getProject());
SearchScope scope = manager.getMaxSearchScopeToWarnOfFallingOutOf(new UsageTarget[] { target });
assertEquals(scope, GlobalSearchScopesCore.directoryScope(getProject(), dir, true));
}
Aggregations