use of com.intellij.psi.search.TextOccurenceProcessor in project intellij-community by JetBrains.
the class PatternEditorContextMembersProvider method calcDevPatternClassNames.
private static Set<String> calcDevPatternClassNames(@NotNull final Project project) {
final List<String> roots = ContainerUtil.createLockFreeCopyOnWriteList();
JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
PsiClass beanClass = psiFacade.findClass(PatternClassBean.class.getName(), GlobalSearchScope.allScope(project));
if (beanClass != null) {
GlobalSearchScope scope = GlobalSearchScope.getScopeRestrictedByFileTypes(GlobalSearchScope.allScope(project), StdFileTypes.XML);
final TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
@Override
public boolean execute(@NotNull PsiElement element, int offsetInElement) {
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
String className = tag == null ? null : tag.getAttributeValue("className");
if (StringUtil.isNotEmpty(className) && tag.getLocalName().endsWith("patternClass")) {
roots.add(className);
}
return true;
}
};
final StringSearcher searcher = new StringSearcher("patternClass", true, true);
CacheManager.SERVICE.getInstance(beanClass.getProject()).processFilesWithWord(psiFile -> {
LowLevelSearchUtil.processElementsContainingWordInElement(occurenceProcessor, psiFile, searcher, true, new EmptyProgressIndicator());
return true;
}, searcher.getPattern(), UsageSearchContext.IN_FOREIGN_LANGUAGES, scope, searcher.isCaseSensitive());
}
return ContainerUtil.newHashSet(roots);
}
Aggregations