Search in sources :

Example 6 with IndexPattern

use of com.intellij.psi.search.IndexPattern in project intellij-community by JetBrains.

the class IndexTodoCacheManagerImpl method getFilesWithTodoItems.

@Override
@NotNull
public PsiFile[] getFilesWithTodoItems() {
    if (myProject.isDefault()) {
        return PsiFile.EMPTY_ARRAY;
    }
    final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
    final Set<PsiFile> allFiles = new HashSet<>();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) {
        final Collection<VirtualFile> files = fileBasedIndex.getContainingFiles(TodoIndex.NAME, new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), GlobalSearchScope.allScope(myProject));
        ApplicationManager.getApplication().runReadAction(() -> {
            for (VirtualFile file : files) {
                if (projectFileIndex.isInContent(file)) {
                    final PsiFile psiFile = myPsiManager.findFile(file);
                    if (psiFile != null) {
                        allFiles.add(psiFile);
                    }
                }
            }
        });
    }
    return allFiles.isEmpty() ? PsiFile.EMPTY_ARRAY : PsiUtilCore.toPsiFileArray(allFiles);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IndexPattern(com.intellij.psi.search.IndexPattern) PsiFile(com.intellij.psi.PsiFile) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with IndexPattern

use of com.intellij.psi.search.IndexPattern in project intellij-community by JetBrains.

the class IndexPatternSearcher method executeImpl.

protected static boolean executeImpl(IndexPatternSearch.SearchParameters queryParameters, Processor<IndexPatternOccurrence> consumer) {
    final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
    final PsiFile file = queryParameters.getFile();
    TIntArrayList commentStarts = new TIntArrayList();
    TIntArrayList commentEnds = new TIntArrayList();
    final CharSequence chars = file.getViewProvider().getContents();
    findCommentTokenRanges(file, chars, queryParameters.getRange(), commentStarts, commentEnds);
    TIntArrayList occurrences = new TIntArrayList(1);
    IndexPattern[] patterns = patternProvider != null ? patternProvider.getIndexPatterns() : null;
    for (int i = 0; i < commentStarts.size(); i++) {
        int commentStart = commentStarts.get(i);
        int commentEnd = commentEnds.get(i);
        occurrences.resetQuick();
        if (patternProvider != null) {
            for (int j = patterns.length - 1; j >= 0; --j) {
                if (!collectPatternMatches(patterns[j], chars, commentStart, commentEnd, file, queryParameters.getRange(), consumer, occurrences)) {
                    return false;
                }
            }
        } else {
            if (!collectPatternMatches(queryParameters.getPattern(), chars, commentStart, commentEnd, file, queryParameters.getRange(), consumer, occurrences)) {
                return false;
            }
        }
    }
    return true;
}
Also used : IndexPatternProvider(com.intellij.psi.search.IndexPatternProvider) IndexPattern(com.intellij.psi.search.IndexPattern) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

IndexPattern (com.intellij.psi.search.IndexPattern)7 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 NotNull (org.jetbrains.annotations.NotNull)3 TodoIndexEntry (com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)2 IndexPatternProvider (com.intellij.psi.search.IndexPatternProvider)2 Lexer (com.intellij.lexer.Lexer)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 OccurrenceConsumer (com.intellij.psi.impl.cache.impl.OccurrenceConsumer)1 LexerBasedIdIndexer (com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 IdDataConsumer (com.intellij.util.indexing.IdDataConsumer)1 CharSequenceSubSequence (com.intellij.util.text.CharSequenceSubSequence)1 THashMap (gnu.trove.THashMap)1 TIntArrayList (gnu.trove.TIntArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1