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()));
}
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()));
}
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;
}
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;
}
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)));
}
Aggregations