Search in sources :

Example 1 with CollectProcessor

use of com.intellij.util.CommonProcessors.CollectProcessor 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 CollectProcessor

use of com.intellij.util.CommonProcessors.CollectProcessor in project intellij-plugins by JetBrains.

the class AbstractStepDefinition method findSteps.

/**
   * Finds all steps points to this definition in some scope
   *
   * @param searchScope scope to find steps
   * @return steps
   */
@NotNull
public Collection<GherkinStep> findSteps(@NotNull final SearchScope searchScope) {
    final String regex = getCucumberRegex();
    final PsiElement element = getElement();
    if ((regex == null) || (element == null)) {
        return Collections.emptyList();
    }
    final CollectProcessor<PsiReference> consumer = new CollectProcessor<>();
    CucumberUtil.findGherkinReferencesToElement(element, regex, consumer, searchScope);
    // We use hash to get rid of duplicates
    final Collection<GherkinStep> results = new HashSet<>(consumer.getResults().size());
    for (final PsiReference reference : consumer.getResults()) {
        final PsiElement step = reference.getElement();
        if (step instanceof GherkinStep) {
            results.add((GherkinStep) step);
        }
    }
    return results;
}
Also used : GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) CollectProcessor(com.intellij.util.CommonProcessors.CollectProcessor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

CollectProcessor (com.intellij.util.CommonProcessors.CollectProcessor)2 NotNull (org.jetbrains.annotations.NotNull)2 CustomUsageSearcher (com.intellij.find.findUsages.CustomUsageSearcher)1 FindUsagesOptions (com.intellij.find.findUsages.FindUsagesOptions)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 UsageInfo (com.intellij.usageView.UsageInfo)1 Usage (com.intellij.usages.Usage)1 PsiElementUsage (com.intellij.usages.rules.PsiElementUsage)1 HashSet (java.util.HashSet)1 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)1