Search in sources :

Example 1 with IdDataConsumer

use of com.intellij.util.indexing.IdDataConsumer in project intellij-community by JetBrains.

the class PlainTextIndexer method map.

@Override
@NotNull
public Map<IdIndexEntry, Integer> map(@NotNull final FileContent inputData) {
    final IdDataConsumer consumer = new IdDataConsumer();
    final CharSequence chars = inputData.getContentAsText();
    IdTableBuilding.scanWords(new IdTableBuilding.ScanWordProcessor() {

        @Override
        public void run(final CharSequence chars11, @Nullable char[] charsArray, final int start, final int end) {
            if (charsArray != null) {
                consumer.addOccurrence(charsArray, start, end, (int) UsageSearchContext.IN_PLAIN_TEXT);
            } else {
                consumer.addOccurrence(chars11, start, end, (int) UsageSearchContext.IN_PLAIN_TEXT);
            }
        }
    }, chars, 0, chars.length());
    return consumer.getResult();
}
Also used : IdDataConsumer(com.intellij.util.indexing.IdDataConsumer) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IdDataConsumer

use of com.intellij.util.indexing.IdDataConsumer in project intellij-community by JetBrains.

the class BaseFilterLexerUtil method scanContent.

public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) {
    ScanContent data = content.getUserData(scanContentKey);
    if (data != null) {
        content.putUserData(scanContentKey, null);
        return data;
    }
    // same as TodoIndex.getFilter().isAcceptable
    final boolean needTodo = content.getFile().isInLocalFileSystem();
    final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer;
    final IdDataConsumer consumer = needIdIndex ? new IdDataConsumer() : null;
    final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo);
    final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer);
    filterLexer.start(content.getContentAsText());
    while (filterLexer.getTokenType() != null) filterLexer.advance();
    Map<TodoIndexEntry, Integer> todoMap = null;
    if (needTodo) {
        for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) {
            final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern);
            if (count > 0) {
                if (todoMap == null)
                    todoMap = new THashMap<>();
                todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count);
            }
        }
    }
    data = new ScanContent(consumer != null ? consumer.getResult() : Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap : Collections.<TodoIndexEntry, Integer>emptyMap());
    if (needIdIndex && needTodo)
        content.putUserData(scanContentKey, data);
    return data;
}
Also used : Lexer(com.intellij.lexer.Lexer) THashMap(gnu.trove.THashMap) IndexPattern(com.intellij.psi.search.IndexPattern) IdDataConsumer(com.intellij.util.indexing.IdDataConsumer) LexerBasedIdIndexer(com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)

Aggregations

IdDataConsumer (com.intellij.util.indexing.IdDataConsumer)2 Lexer (com.intellij.lexer.Lexer)1 LexerBasedIdIndexer (com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer)1 TodoIndexEntry (com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)1 IndexPattern (com.intellij.psi.search.IndexPattern)1 THashMap (gnu.trove.THashMap)1 NotNull (org.jetbrains.annotations.NotNull)1