@Override protected void setUp() throws Exception { super.setUp(); FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME); FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME); String root = JavaTestUtil.getJavaTestDataPath()+ "/psi/impl/cache/"; PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17()); myRootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete); myCacheFile = FileUtil.createTempFile("cache", ""); myCacheFile.delete(); myFilesToDelete.add(myCacheFile); }
@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); }
@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); }
@Override protected void setUp() throws Exception { super.setUp(); FileBasedIndex.getInstance().requestRebuild(IdIndex.NAME); FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME); }
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]; }
public static void ensureIndexesUpToDate(@NotNull Project project) { if (!DumbService.isDumb(project)) { FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); } }
public static void ensureIndexesUpToDate(Project project) { if (!DumbService.isDumb(project)) { FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null); FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null); } }