Search in sources :

Example 1 with OccurrenceConsumer

use of com.intellij.psi.impl.cache.impl.OccurrenceConsumer 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;
}
Also used : OccurrenceConsumer(com.intellij.psi.impl.cache.impl.OccurrenceConsumer) IndexPattern(com.intellij.psi.search.IndexPattern) Pattern(java.util.regex.Pattern) IndexPattern(com.intellij.psi.search.IndexPattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

OccurrenceConsumer (com.intellij.psi.impl.cache.impl.OccurrenceConsumer)1 IndexPattern (com.intellij.psi.search.IndexPattern)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NotNull (org.jetbrains.annotations.NotNull)1