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;
}
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;
}
Aggregations