Search in sources :

Example 1 with TodoIndexEntry

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;
}
Also used : FileContent(com.intellij.util.indexing.FileContent) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) SubstitutedFileType(com.intellij.util.indexing.SubstitutedFileType) Language(com.intellij.lang.Language) TokenSet(com.intellij.psi.tree.TokenSet) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TodoIndexEntry

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" });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with TodoIndexEntry

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];
}
Also used : TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)

Example 4 with TodoIndexEntry

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) IndexPattern(com.intellij.psi.search.IndexPattern) PsiFile(com.intellij.psi.PsiFile) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with TodoIndexEntry

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;
}
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

TodoIndexEntry (com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IndexPattern (com.intellij.psi.search.IndexPattern)2 Language (com.intellij.lang.Language)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 Lexer (com.intellij.lexer.Lexer)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)1 Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 PsiFile (com.intellij.psi.PsiFile)1 LexerBasedIdIndexer (com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer)1 TokenSet (com.intellij.psi.tree.TokenSet)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 FileContent (com.intellij.util.indexing.FileContent)1 IdDataConsumer (com.intellij.util.indexing.IdDataConsumer)1 SubstitutedFileType (com.intellij.util.indexing.SubstitutedFileType)1 THashMap (gnu.trove.THashMap)1 File (java.io.File)1 HashSet (java.util.HashSet)1