Java 类com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry 实例源码

项目:intellij-ce-playground    文件:PlatformIdTableBuilding.java   
@NotNull
@Override
public Map<TodoIndexEntry, Integer> map(@NotNull FileContent inputData) {
  Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap();
  for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) {
    for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) {
      TodoIndexEntry key = entry.getKey();
      if (result.containsKey(key)) {
        result.put(key, result.get(key) + entry.getValue());
      } else {
        result.put(key, entry.getValue());
      }
    }
  }
  return result;
}
项目:tools-idea    文件:PlatformIdTableBuilding.java   
@NotNull
@Override
public Map<TodoIndexEntry, Integer> map(FileContent inputData) {
  Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap();
  for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) {
    for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) {
      TodoIndexEntry key = entry.getKey();
      if (result.containsKey(key)) {
        result.put(key, result.get(key) + entry.getValue());
      } else {
        result.put(key, entry.getValue());
      }
    }
  }
  return result;
}
项目:consulo    文件:PlatformIdTableBuilding.java   
@Nonnull
@Override
public Map<TodoIndexEntry, Integer> map(FileContent inputData) {
  Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap();
  for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) {
    for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) {
      TodoIndexEntry key = entry.getKey();
      if (result.containsKey(key)) {
        result.put(key, result.get(key) + entry.getValue());
      }
      else {
        result.put(key, entry.getValue());
      }
    }
  }
  return result;
}
项目:consulo    文件:IndexTodoCacheManagerImpl.java   
@Override
@Nonnull
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);
}
项目:intellij-ce-playground    文件:PlatformIdTableBuilding.java   
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
  }

  return null;
}
项目:intellij-ce-playground    文件:IndexTodoCacheManagerImpl.java   
@Override
@NotNull
public PsiFile[] getFilesWithTodoItems() {
  if (myProject.isDefault()) {
    return PsiFile.EMPTY_ARRAY;
  }
  final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
  final Set<PsiFile> allFiles = new HashSet<PsiFile>();
  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(new Runnable() {
      @Override
      public void run() {
        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);
}
项目:intellij-ce-playground    文件:BaseFilterLexerUtil.java   
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) {
  ScanContent data = content.getUserData(scanContentKey);
  if (data != null) {
    content.putUserData(scanContentKey, null);
    return data;
  }

  final boolean needTodo = content.getFile().isInLocalFileSystem(); // same as TodoIndex.getFilter().isAcceptable
  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<TodoIndexEntry, Integer>();
          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;
}
项目:tools-idea    文件:BaseFilterLexerUtil.java   
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) {
  ScanContent data = content.getUserData(scanContentKey);
  if (data != null) {
    content.putUserData(scanContentKey, null);
    return data;
  }

  final boolean needTodo = content.getFile().getFileSystem().getProtocol().equals(StandardFileSystems.FILE_PROTOCOL);
  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<TodoIndexEntry, Integer>();
          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;
}
项目:tools-idea    文件:PlatformIdTableBuilding.java   
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = ourTodoIndexers.get(fileType);

  if (indexer != null) {
    return indexer;
  }

  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer =
      new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, virtualFile);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
  }

  return null;
}
项目:tools-idea    文件:IndexTodoCacheManagerImpl.java   
@Override
@NotNull
public PsiFile[] getFilesWithTodoItems() {
  if (myProject.isDefault()) {
    return PsiFile.EMPTY_ARRAY;
  }
  final FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
  final Set<PsiFile> allFiles = new HashSet<PsiFile>();
  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(new Runnable() {
      @Override
      public void run() {
        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);
}
项目:consulo    文件:PlatformIdTableBuilding.java   
@javax.annotation.Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, Project project, final VirtualFile virtualFile) {
  final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
  if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType)fileType).isSameFileType()) {
    SubstitutedFileType sft = (SubstitutedFileType)fileType;
    extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), project, virtualFile), getTodoIndexer(sft.getFileType(), project, virtualFile));
  }
  else {
    extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
  }
  if (extIndexer != null) {
    return extIndexer;
  }

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    LanguageVersion languageVersion = LanguageVersionUtil.findLanguageVersion(lang, project, virtualFile);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens(languageVersion) : null;
    if (commentTokens != null) {
      return new TokenSetTodoIndexer(commentTokens, languageVersion, virtualFile, project);
    }
  }

  if (fileType instanceof CustomSyntaxTableFileType) {
    return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, null, virtualFile, project);
  }

  return null;
}
项目:consulo    文件:BaseFilterLexerUtil.java   
public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) {
  ScanContent data = content.getUserData(scanContentKey);
  if (data != null) {
    content.putUserData(scanContentKey, null);
    return data;
  }

  final boolean needTodo = content.getFile().getFileSystem() instanceof LocalFileSystem;
  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<TodoIndexEntry, Integer>();
          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;
}
项目:consulo    文件:IndexTodoCacheManagerImpl.java   
private int fetchCount(@Nonnull FileBasedIndex fileBasedIndex, @Nonnull VirtualFile file, @Nonnull IndexPattern indexPattern) {
  final int[] count = {0};
  fileBasedIndex.processValues(
          TodoIndex.NAME, new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), file,
          (file1, value) -> {
            count[0] += value.intValue();
            return true;
          }, GlobalSearchScope.fileScope(myProject, file));
  return count[0];
}
项目:intellij-ce-playground    文件:PlatformIdTableBuilding.java   
@Deprecated
public static void registerTodoIndexer(@NotNull FileType fileType, DataIndexer<TodoIndexEntry, Integer, FileContent> indexer) {
  ourTodoIndexers.put(fileType, indexer);
}
项目:intellij-ce-playground    文件:PlatformIdTableBuilding.java   
public CompositeTodoIndexer(@NotNull DataIndexer<TodoIndexEntry, Integer, FileContent>... indexers) {
  this.indexers = indexers;
}
项目:intellij-ce-playground    文件:BaseFilterLexerUtil.java   
public ScanContent(Map<IdIndexEntry, Integer> _idMap, Map<TodoIndexEntry, Integer> _todoMap) {
  idMap = _idMap;
  todoMap = _todoMap;
}
项目:tools-idea    文件:BaseFilterLexerUtil.java   
public ScanContent(Map<IdIndexEntry, Integer> _idMap, Map<TodoIndexEntry, Integer> _todoMap) {
  idMap = _idMap;
  todoMap = _todoMap;
}
项目:tools-idea    文件:PlatformIdTableBuilding.java   
@Deprecated
public static void registerTodoIndexer(FileType fileType, DataIndexer<TodoIndexEntry, Integer, FileContent> indexer) {
  ourTodoIndexers.put(fileType, indexer);
}
项目:tools-idea    文件:PlatformIdTableBuilding.java   
public CompositeTodoIndexer(DataIndexer<TodoIndexEntry, Integer, FileContent>... indexers) {
  this.indexers = indexers;
}
项目:consulo    文件:PlatformIdTableBuilding.java   
@SafeVarargs
public CompositeTodoIndexer(@Nonnull DataIndexer<TodoIndexEntry, Integer, FileContent>... indexers) {
  this.indexers = indexers;
}
项目:consulo    文件:BaseFilterLexerUtil.java   
public ScanContent(Map<IdIndexEntry, Integer> _idMap, Map<TodoIndexEntry, Integer> _todoMap) {
  idMap = _idMap;
  todoMap = _todoMap;
}