use of com.intellij.find.findUsages.FindUsagesOptions in project intellij-community by JetBrains.
the class PyTestCase method findUsage.
/**
* Finds all usages of element. Works much like method in {@link com.intellij.testFramework.fixtures.CodeInsightTestFixture#findUsages(com.intellij.psi.PsiElement)},
* but supports {@link com.intellij.find.findUsages.CustomUsageSearcher} and {@link com.intellij.psi.search.searches.ReferencesSearch} as well
*
* @param element what to find
* @return usages
*/
@NotNull
protected Collection<PsiElement> findUsage(@NotNull final PsiElement element) {
final Collection<PsiElement> result = new ArrayList<>();
final CollectProcessor<Usage> usageCollector = new CollectProcessor<>();
for (final CustomUsageSearcher searcher : CustomUsageSearcher.EP_NAME.getExtensions()) {
searcher.processElementUsages(element, usageCollector, new FindUsagesOptions(myFixture.getProject()));
}
for (final Usage usage : usageCollector.getResults()) {
if (usage instanceof PsiElementUsage) {
result.add(((PsiElementUsage) usage).getElement());
}
}
for (final PsiReference reference : ReferencesSearch.search(element).findAll()) {
result.add(reference.getElement());
}
for (final UsageInfo info : myFixture.findUsages(element)) {
result.add(info.getElement());
}
return result;
}
use of com.intellij.find.findUsages.FindUsagesOptions in project intellij-community by JetBrains.
the class CodeInsightTestFixtureImpl method findUsages.
@NotNull
public Collection<UsageInfo> findUsages(@NotNull final PsiElement targetElement, @Nullable SearchScope scope) {
final Project project = getProject();
final FindUsagesHandler handler = ((FindManagerImpl) FindManager.getInstance(project)).getFindUsagesManager().getFindUsagesHandler(targetElement, false);
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
assertNotNull("Cannot find handler for: " + targetElement, handler);
final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
final FindUsagesOptions options = handler.getFindUsagesOptions(null);
if (scope != null)
options.searchScope = scope;
for (PsiElement psiElement : psiElements) {
handler.processElementUsages(psiElement, processor, options);
}
return processor.getResults();
}
use of com.intellij.find.findUsages.FindUsagesOptions in project intellij-plugins by JetBrains.
the class DartCallerTreeStructure method getCallers.
private static void getCallers(@NotNull PsiElement element, @NotNull List<PsiElement> results, @NotNull GlobalSearchScope scope) {
FindUsagesHandler finder = createFindUsageHandler(element);
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
FindUsagesOptions options = new FindUsagesOptions(scope);
options.isUsages = true;
options.isSearchForTextOccurrences = false;
finder.processElementUsages(element, processor, options);
for (UsageInfo each : processor.getResults()) {
PsiElement eachElement = each.getElement();
collectDeclarations(eachElement, results);
}
}
use of com.intellij.find.findUsages.FindUsagesOptions in project smali by JesusFreke.
the class FindUsagesTest method findUsages.
private Collection<UsageInfo> findUsages(@NotNull PsiElement element) {
FindUsagesManager findUsagesManager = ((FindManagerImpl) FindManager.getInstance(getProject())).getFindUsagesManager();
FindUsagesHandler findUsagesHandler = findUsagesManager.getFindUsagesHandler(element, false);
Assert.assertNotNull(findUsagesHandler);
final FindUsagesOptions options = findUsagesHandler.getFindUsagesOptions();
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<UsageInfo>();
for (PsiElement primaryElement : findUsagesHandler.getPrimaryElements()) {
findUsagesHandler.processElementUsages(primaryElement, processor, options);
}
for (PsiElement secondaryElement : findUsagesHandler.getSecondaryElements()) {
findUsagesHandler.processElementUsages(secondaryElement, processor, options);
}
return processor.getResults();
}
use of com.intellij.find.findUsages.FindUsagesOptions in project intellij-community by JetBrains.
the class PyStaticCallHierarchyUtil method findUsages.
private static Collection<UsageInfo> findUsages(@NotNull final PsiElement element) {
final FindUsagesHandler handler = createFindUsageHandler(element);
if (handler == null) {
return Lists.newArrayList();
}
final CommonProcessors.CollectProcessor<UsageInfo> processor = new CommonProcessors.CollectProcessor<>();
final PsiElement[] psiElements = ArrayUtil.mergeArrays(handler.getPrimaryElements(), handler.getSecondaryElements());
final FindUsagesOptions options = handler.getFindUsagesOptions(null);
for (PsiElement psiElement : psiElements) {
handler.processElementUsages(psiElement, processor, options);
}
return processor.getResults();
}
Aggregations