Search in sources :

Example 1 with FindUsagesOptions

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;
}
Also used : PsiElementUsage(com.intellij.usages.rules.PsiElementUsage) Usage(com.intellij.usages.Usage) CustomUsageSearcher(com.intellij.find.findUsages.CustomUsageSearcher) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) UsageInfo(com.intellij.usageView.UsageInfo) CollectProcessor(com.intellij.util.CommonProcessors.CollectProcessor) PsiElementUsage(com.intellij.usages.rules.PsiElementUsage) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FindUsagesOptions

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();
}
Also used : Project(com.intellij.openapi.project.Project) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) UsageInfo(com.intellij.usageView.UsageInfo) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FindUsagesOptions

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);
    }
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 4 with FindUsagesOptions

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();
}
Also used : FindManagerImpl(com.intellij.find.impl.FindManagerImpl) FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) FindUsagesManager(com.intellij.find.findUsages.FindUsagesManager) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Example 5 with FindUsagesOptions

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();
}
Also used : FindUsagesHandler(com.intellij.find.findUsages.FindUsagesHandler) PyFunctionFindUsagesHandler(com.jetbrains.python.findUsages.PyFunctionFindUsagesHandler) PyClassFindUsagesHandler(com.jetbrains.python.findUsages.PyClassFindUsagesHandler) FindUsagesOptions(com.intellij.find.findUsages.FindUsagesOptions) CommonProcessors(com.intellij.util.CommonProcessors) UsageInfo(com.intellij.usageView.UsageInfo) PsiElement(com.intellij.psi.PsiElement)

Aggregations

FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)6 UsageInfo (com.intellij.usageView.UsageInfo)6 FindUsagesHandler (com.intellij.find.findUsages.FindUsagesHandler)5 PsiElement (com.intellij.psi.PsiElement)4 CommonProcessors (com.intellij.util.CommonProcessors)4 NotNull (org.jetbrains.annotations.NotNull)3 FindUsagesManager (com.intellij.find.findUsages.FindUsagesManager)2 FindManagerImpl (com.intellij.find.impl.FindManagerImpl)2 CustomUsageSearcher (com.intellij.find.findUsages.CustomUsageSearcher)1 Project (com.intellij.openapi.project.Project)1 Usage (com.intellij.usages.Usage)1 PsiElementUsage (com.intellij.usages.rules.PsiElementUsage)1 CollectProcessor (com.intellij.util.CommonProcessors.CollectProcessor)1 DartServerFindUsagesHandler (com.jetbrains.lang.dart.ide.findUsages.DartServerFindUsagesHandler)1 PyClassFindUsagesHandler (com.jetbrains.python.findUsages.PyClassFindUsagesHandler)1 PyFunctionFindUsagesHandler (com.jetbrains.python.findUsages.PyFunctionFindUsagesHandler)1