use of com.intellij.psi.search.IndexPattern in project intellij-community by JetBrains.
the class BaseFilterLexer method advanceTodoItemsCount.
public static TodoScanningState advanceTodoItemsCount(final CharSequence input, final OccurrenceConsumer consumer, TodoScanningState todoScanningState) {
if (todoScanningState == null) {
IndexPattern[] patterns = IndexPatternUtil.getIndexPatterns();
Matcher[] matchers = new Matcher[patterns.length];
todoScanningState = new TodoScanningState(patterns, matchers);
for (int i = 0; i < patterns.length; ++i) {
Pattern pattern = patterns[i].getOptimizedIndexingPattern();
if (pattern != null) {
matchers[i] = pattern.matcher("");
}
}
} else {
todoScanningState.myOccurences.resetQuick();
}
for (int i = todoScanningState.myMatchers.length - 1; i >= 0; --i) {
Matcher matcher = todoScanningState.myMatchers[i];
if (matcher == null)
continue;
matcher.reset(input);
while (matcher.find()) {
int start = matcher.start();
if (start != matcher.end() && todoScanningState.myOccurences.indexOf(start) == -1) {
consumer.incTodoOccurrence(todoScanningState.myPatterns[i]);
todoScanningState.myOccurences.add(start);
}
}
}
return todoScanningState;
}
use of com.intellij.psi.search.IndexPattern in project intellij-community by JetBrains.
the class PlainTextTodoIndexer method map.
@Override
@NotNull
public Map<TodoIndexEntry, Integer> map(@NotNull final FileContent inputData) {
// matching strings is faster than HeapCharBuffer
String chars = inputData.getContentAsText().toString();
final IndexPattern[] indexPatterns = IndexPatternUtil.getIndexPatterns();
if (indexPatterns.length <= 0) {
return Collections.emptyMap();
}
OccurrenceConsumer occurrenceConsumer = new OccurrenceConsumer(null, true);
for (IndexPattern indexPattern : indexPatterns) {
Pattern pattern = indexPattern.getOptimizedIndexingPattern();
if (pattern != null) {
Matcher matcher = pattern.matcher(chars);
while (matcher.find()) {
if (matcher.start() != matcher.end()) {
occurrenceConsumer.incTodoOccurrence(indexPattern);
}
}
}
}
Map<TodoIndexEntry, Integer> map = new HashMap<>();
for (IndexPattern indexPattern : indexPatterns) {
final int count = occurrenceConsumer.getOccurrenceCount(indexPattern);
if (count > 0) {
map.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count);
}
}
return map;
}
use of com.intellij.psi.search.IndexPattern in project intellij-community by JetBrains.
the class IndexPatternSearcher method collectPatternMatches.
private static boolean collectPatternMatches(IndexPattern indexPattern, CharSequence chars, int commentStart, int commentEnd, PsiFile file, TextRange range, Processor<IndexPatternOccurrence> consumer, TIntArrayList matches) {
Pattern pattern = indexPattern.getPattern();
if (pattern != null) {
ProgressManager.checkCanceled();
CharSequence input = new CharSequenceSubSequence(chars, commentStart, commentEnd);
Matcher matcher = pattern.matcher(input);
while (true) {
//long time1 = System.currentTimeMillis();
boolean found = matcher.find();
if (!found)
break;
int start = matcher.start() + commentStart;
int end = matcher.end() + commentStart;
if (start != end) {
if ((range == null || range.getStartOffset() <= start && end <= range.getEndOffset()) && matches.indexOf(start) == -1) {
matches.add(start);
if (!consumer.process(new IndexPatternOccurrenceImpl(file, start, end, indexPattern))) {
return false;
}
}
}
ProgressManager.checkCanceled();
}
}
return true;
}
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);
}
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;
}
Aggregations