Search in sources :

Example 1 with CacheManager

use of com.intellij.psi.impl.cache.CacheManager 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 2 with CacheManager

use of com.intellij.psi.impl.cache.CacheManager 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 3 with CacheManager

use of com.intellij.psi.impl.cache.CacheManager in project android by JetBrains.

the class AndroidFindStyleApplicationsProcessor method collectFilesToProcess.

public Collection<PsiFile> collectFilesToProcess() {
    final Project project = myModule.getProject();
    final List<VirtualFile> resDirs = new ArrayList<VirtualFile>();
    if (mySearchOnlyInCurrentModule) {
        collectResDir(myModule, myStyleNameAttrValue, myStyleName, resDirs);
    } else {
        for (Module m : getAllModulesToScan(myModule)) {
            collectResDir(m, myStyleNameAttrValue, myStyleName, resDirs);
        }
    }
    final List<VirtualFile> subdirs = AndroidResourceUtil.getResourceSubdirs(ResourceFolderType.LAYOUT, resDirs.toArray(new VirtualFile[resDirs.size()]));
    List<VirtualFile> filesToProcess = new ArrayList<VirtualFile>();
    for (VirtualFile subdir : subdirs) {
        for (VirtualFile child : subdir.getChildren()) {
            if (child.getFileType() == XmlFileType.INSTANCE && (myFileToScan == null || myFileToScan.equals(child))) {
                filesToProcess.add(child);
            }
        }
    }
    if (filesToProcess.size() == 0) {
        return Collections.emptyList();
    }
    final Set<PsiFile> psiFilesToProcess = new HashSet<PsiFile>();
    for (VirtualFile file : filesToProcess) {
        final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
        if (psiFile != null) {
            psiFilesToProcess.add(psiFile);
        }
    }
    final CacheManager cacheManager = CacheManager.SERVICE.getInstance(project);
    final GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
    for (Map.Entry<AndroidAttributeInfo, String> entry : myAttrMap.entrySet()) {
        filterFilesToScan(cacheManager, entry.getKey().getName(), psiFilesToProcess, projectScope);
        filterFilesToScan(cacheManager, entry.getValue(), psiFilesToProcess, projectScope);
    }
    return psiFilesToProcess;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) CacheManager(com.intellij.psi.impl.cache.CacheManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) HashMap(com.intellij.util.containers.HashMap) HashSet(com.intellij.util.containers.HashSet)

Example 4 with CacheManager

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

the class FindInProjectTask method getFilesForFastWordSearch.

@NotNull
private Set<VirtualFile> getFilesForFastWordSearch() {
    String stringToFind = myStringToFindInIndices;
    if (stringToFind.isEmpty() || DumbService.getInstance(myProject).isDumb()) {
        return Collections.emptySet();
    }
    final Set<VirtualFile> resultFiles = new LinkedHashSet<>();
    for (VirtualFile file : myFilesToScanInitially) {
        if (myFileMask.value(file)) {
            resultFiles.add(file);
        }
    }
    final GlobalSearchScope scope = GlobalSearchScopeUtil.toGlobalSearchScope(FindInProjectUtil.getScopeFromModel(myProject, myFindModel), myProject);
    if (TrigramIndex.ENABLED) {
        final Set<Integer> keys = ContainerUtil.newTroveSet();
        TrigramBuilder.processTrigrams(stringToFind, new TrigramBuilder.TrigramProcessor() {

            @Override
            public boolean execute(int value) {
                keys.add(value);
                return true;
            }
        });
        if (!keys.isEmpty()) {
            final List<VirtualFile> hits = new ArrayList<>();
            ApplicationManager.getApplication().runReadAction(() -> {
                FileBasedIndex.getInstance().getFilesWithKey(TrigramIndex.INDEX_ID, keys, Processors.cancelableCollectProcessor(hits), scope);
            });
            for (VirtualFile hit : hits) {
                if (myFileMask.value(hit)) {
                    resultFiles.add(hit);
                }
            }
            return resultFiles;
        }
    }
    PsiSearchHelperImpl helper = (PsiSearchHelperImpl) PsiSearchHelper.SERVICE.getInstance(myProject);
    helper.processFilesWithText(scope, UsageSearchContext.ANY, myFindModel.isCaseSensitive(), stringToFind, file -> {
        if (myFileMask.value(file)) {
            ContainerUtil.addIfNotNull(resultFiles, file);
        }
        return true;
    });
    // in case our word splitting is incorrect
    CacheManager cacheManager = CacheManager.SERVICE.getInstance(myProject);
    VirtualFile[] filesWithWord = cacheManager.getVirtualFilesWithWord(stringToFind, UsageSearchContext.ANY, scope, myFindModel.isCaseSensitive());
    for (VirtualFile file : filesWithWord) {
        if (myFileMask.value(file)) {
            resultFiles.add(file);
        }
    }
    return resultFiles;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TrigramBuilder(com.intellij.openapi.util.text.TrigramBuilder) PsiSearchHelperImpl(com.intellij.psi.impl.search.PsiSearchHelperImpl) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(com.intellij.psi.impl.cache.CacheManager) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CacheManager

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

the class IdCacheTest method testLoadCacheNoTodo.

public void testLoadCacheNoTodo() throws Exception {
    final CacheManager cache = CacheManager.SERVICE.getInstance(myProject);
    checkResult(new String[] { "1.java", "2.java" }, convert(cache.getFilesWithWord("b", UsageSearchContext.ANY, GlobalSearchScope.projectScope(myProject), false)));
}
Also used : TodoCacheManager(com.intellij.psi.impl.cache.TodoCacheManager) CacheManager(com.intellij.psi.impl.cache.CacheManager)

Aggregations

CacheManager (com.intellij.psi.impl.cache.CacheManager)10 TodoCacheManager (com.intellij.psi.impl.cache.TodoCacheManager)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)7 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 TrigramBuilder (com.intellij.openapi.util.text.TrigramBuilder)1 PsiFile (com.intellij.psi.PsiFile)1 PsiSearchHelperImpl (com.intellij.psi.impl.search.PsiSearchHelperImpl)1 HashMap (com.intellij.util.containers.HashMap)1 HashSet (com.intellij.util.containers.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 NotNull (org.jetbrains.annotations.NotNull)1