use of com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry in project intellij-community by JetBrains.
the class PlatformIdTableBuilding method getTodoIndexer.
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, 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(), 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;
}
use of com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry in project intellij-community by JetBrains.
the class UpdateCacheTest method testExternalFileModificationWhileProjectClosed.
public void testExternalFileModificationWhileProjectClosed() throws Exception {
VirtualFile root = ProjectRootManager.getInstance(myProject).getContentRoots()[0];
PsiClass objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
assertNotNull(objectClass);
checkUsages(objectClass, new String[] {});
FileBasedIndex.getInstance().getContainingFiles(TodoIndex.NAME, new TodoIndexEntry("todo", true), GlobalSearchScope.allScope(getProject()));
final String projectLocation = myProject.getPresentableUrl();
assert projectLocation != null : myProject;
PlatformTestUtil.saveProject(myProject);
final VirtualFile content = ModuleRootManager.getInstance(getModule()).getContentRoots()[0];
Project project = myProject;
ProjectUtil.closeAndDispose(project);
InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);
assertTrue("Project was not disposed", myProject.isDisposed());
myModule = null;
final File file = new File(root.getPath(), "1.java");
assertTrue(file.exists());
FileUtil.writeToFile(file, "class A{ Object o;}".getBytes(CharsetToolkit.UTF8_CHARSET));
root.refresh(false, true);
LocalFileSystem.getInstance().refresh(false);
myProject = ProjectManager.getInstance().loadAndOpenProject(projectLocation);
InjectedLanguageManagerImpl.pushInjectors(getProject());
setUpModule();
setUpJdk();
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
// startup activities
UIUtil.dispatchAllInvocationEvents();
runStartupActivities();
PsiTestUtil.addSourceContentToRoots(getModule(), content);
assertNotNull(myProject);
myPsiManager = (PsiManagerImpl) PsiManager.getInstance(myProject);
myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);
objectClass = myJavaFacade.findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
assertNotNull(objectClass);
checkUsages(objectClass, new String[] { "1.java" });
}
use of com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry in project intellij-community by JetBrains.
the class IndexTodoCacheManagerImpl method fetchCount.
private int fetchCount(@NotNull FileBasedIndex fileBasedIndex, @NotNull VirtualFile file, @NotNull 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];
}
use of com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry 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.impl.cache.impl.todo.TodoIndexEntry 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;
}
Aggregations