Search in sources :

Example 1 with TextOccurenceProcessor

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);
}
Also used : PatternClassBean(com.intellij.patterns.compiler.PatternClassBean) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) NotNull(org.jetbrains.annotations.NotNull) TextOccurenceProcessor(com.intellij.psi.search.TextOccurenceProcessor) XmlTag(com.intellij.psi.xml.XmlTag) StringSearcher(com.intellij.util.text.StringSearcher)

Aggregations

EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 PatternClassBean (com.intellij.patterns.compiler.PatternClassBean)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 TextOccurenceProcessor (com.intellij.psi.search.TextOccurenceProcessor)1 XmlTag (com.intellij.psi.xml.XmlTag)1 StringSearcher (com.intellij.util.text.StringSearcher)1 NotNull (org.jetbrains.annotations.NotNull)1