Search in sources :

Example 6 with TodoCacheManager

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

the class IdCacheTest method testFileCreation.

public void testFileCreation() throws Exception {
    final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
    final TodoCacheManager todocache = TodoCacheManager.SERVICE.getInstance(myProject);
    checkCache(cache, todocache);
    VirtualFile child = createChildData(myRootDir, "4.java");
    setFileText(child, "xxx //todo");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    final GlobalSearchScope scope = GlobalSearchScope.projectScope(myProject);
    checkResult(new String[] { "4.java" }, convert(cache.getFilesWithWord("xxx", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "1.java" }, convert(cache.getFilesWithWord("a", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "1.java", "2.java" }, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, scope, false)));
    checkResult(new String[] { "1.java", "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[] { "1.java", "3.java", "4.java" }, convert(todocache.getFilesWithTodoItems()));
    assertEquals(1, 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()));
    assertEquals(1, todocache.getTodoCount(myRootDir.findChild("4.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 7 with TodoCacheManager

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

the class IdCacheTest method testFileModification.

public void testFileModification() 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");
    checkCache(cache, todocache);
    setFileText(child, "xxx");
    setFileText(child, "xxx");
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    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)

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