Search in sources :

Example 1 with TodoCacheManager

use of com.intellij.psi.impl.cache.TodoCacheManager in project intellij-community by JetBrains.

the class IndexPatternSearcher method execute.

@Override
public boolean execute(@NotNull final IndexPatternSearch.SearchParameters queryParameters, @NotNull final Processor<IndexPatternOccurrence> consumer) {
    final PsiFile file = queryParameters.getFile();
    VirtualFile virtualFile = file.getVirtualFile();
    if (file instanceof PsiBinaryFile || file instanceof PsiCompiledElement || virtualFile == null) {
        return true;
    }
    final TodoCacheManager cacheManager = TodoCacheManager.SERVICE.getInstance(file.getProject());
    final IndexPatternProvider patternProvider = queryParameters.getPatternProvider();
    int count = patternProvider != null ? cacheManager.getTodoCount(virtualFile, patternProvider) : cacheManager.getTodoCount(virtualFile, queryParameters.getPattern());
    return count == 0 || executeImpl(queryParameters, consumer);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) IndexPatternProvider(com.intellij.psi.search.IndexPatternProvider)

Example 2 with TodoCacheManager

use of com.intellij.psi.impl.cache.TodoCacheManager in project intellij-community by JetBrains.

the class IdCacheTest method testFileDeletion.

public void testFileDeletion() throws Exception {
    final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
    final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
    checkCache(cache, todocache);
    VirtualFile child = myRootDir.findChild("1.java");
    delete(child);
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
    checkResult(new String[] {}, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] {}, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java" }, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache.getFilesWithWord("c", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache.getFilesWithWord("d", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(cache.getFilesWithWord("e", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(todocache.getFilesWithTodoItems()));
    assertEquals(0, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
    assertEquals(2, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) CacheManager(com.intellij.psi.impl.cache.CacheManager)

Example 3 with TodoCacheManager

use of com.intellij.psi.impl.cache.TodoCacheManager in project intellij-community by JetBrains.

the class IdCacheTest method testUpdateCache2.

public void testUpdateCache2() throws Exception {
    VirtualFile child = myRootDir.findChild("1.java");
    setFileText(child, "xxx");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
    final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
    final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
    checkResult(new String[] { "1.java" }, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] {}, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java" }, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache.getFilesWithWord("c", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache.getFilesWithWord("d", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(cache.getFilesWithWord("e", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(todocache.getFilesWithTodoItems()));
    assertEquals(0, todocache.getTodoCount(myRootDir.findChild("1.java"), TodoIndexPatternProvider.getInstance()));
    assertEquals(0, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
    assertEquals(2, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) CacheManager(com.intellij.psi.impl.cache.CacheManager)

Example 4 with TodoCacheManager

use of com.intellij.psi.impl.cache.TodoCacheManager in project intellij-community by JetBrains.

the class IdCacheTest method testUpdateOnTodoChange.

public void testUpdateOnTodoChange() throws Exception {
    TodoPattern pattern = new TodoPattern("newtodo", TodoAttributesUtil.createDefault(), true);
    TodoPattern[] oldPatterns = TodoConfiguration.getInstance().getTodoPatterns();
    TodoConfiguration.getInstance().setTodoPatterns(new TodoPattern[] { pattern });
    try {
        final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
        checkResult(new String[] { "2.java" }, convert(todocache.getFilesWithTodoItems()));
        assertEquals(0, todocache.getTodoCount(myRootDir.findChild("1.java"), TodoIndexPatternProvider.getInstance()));
        assertEquals(1, todocache.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
        assertEquals(0, todocache.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
    } finally {
        TodoConfiguration.getInstance().setTodoPatterns(oldPatterns);
    }
}
Also used : TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) TodoPattern(com.intellij.psi.search.TodoPattern)

Example 5 with TodoCacheManager

use of com.intellij.psi.impl.cache.TodoCacheManager in project intellij-community by JetBrains.

the class IdCacheTest method testUpdateCache3.

public void testUpdateCache3() throws Exception {
    VirtualFile child = myRootDir.findChild("1.java");
    delete(child);
    final CacheManager cache2 = CacheManager.SERVICE.getInstance(myProject);
    final TodoCacheManager todocache2 = TodoCacheManager.SERVICE.getInstance(myProject);
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
    checkResult(ArrayUtil.EMPTY_STRING_ARRAY, convert(cache2.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
    checkResult(ArrayUtil.EMPTY_STRING_ARRAY, convert(cache2.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java" }, convert(cache2.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache2.getFilesWithWord("c", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "2.java", "3.java" }, convert(cache2.getFilesWithWord("d", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(cache2.getFilesWithWord("e", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "3.java" }, convert(todocache2.getFilesWithTodoItems()));
    assertEquals(0, todocache2.getTodoCount(myRootDir.findChild("2.java"), TodoIndexPatternProvider.getInstance()));
    assertEquals(2, todocache2.getTodoCount(myRootDir.findChild("3.java"), TodoIndexPatternProvider.getInstance()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) CacheManager(com.intellij.psi.impl.cache.CacheManager)

Aggregations

TodoCacheManager (com.intellij.psi.impl.cache.TodoCacheManager)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 CacheManager (com.intellij.psi.impl.cache.CacheManager)5 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)5 IndexPatternProvider (com.intellij.psi.search.IndexPatternProvider)1 TodoPattern (com.intellij.psi.search.TodoPattern)1