use of com.intellij.util.indexing.FileBasedIndexImpl in project intellij-community by JetBrains.
the class PlatformTestCase method cleanupApplicationCaches.
public static void cleanupApplicationCaches(Project project) {
if (project != null && !project.isDisposed()) {
UndoManagerImpl globalInstance = (UndoManagerImpl) UndoManager.getGlobalInstance();
if (globalInstance != null) {
globalInstance.dropHistoryInTests();
}
((UndoManagerImpl) UndoManager.getInstance(project)).dropHistoryInTests();
((DocumentReferenceManagerImpl) DocumentReferenceManager.getInstance()).cleanupForNextTest();
((PsiManagerImpl) PsiManager.getInstance(project)).cleanupForNextTest();
}
final ProjectManager projectManager = ProjectManager.getInstance();
assert projectManager != null : "The ProjectManager is not initialized yet";
ProjectManagerImpl projectManagerImpl = (ProjectManagerImpl) projectManager;
if (projectManagerImpl.isDefaultProjectInitialized()) {
Project defaultProject = projectManager.getDefaultProject();
((PsiManagerImpl) PsiManager.getInstance(defaultProject)).cleanupForNextTest();
}
AsyncHighlighterUpdater.completeAsyncTasks();
((FileBasedIndexImpl) FileBasedIndex.getInstance()).cleanupForNextTest();
LocalFileSystemImpl localFileSystem = (LocalFileSystemImpl) LocalFileSystem.getInstance();
if (localFileSystem != null) {
localFileSystem.cleanupForNextTest();
}
}
use of com.intellij.util.indexing.FileBasedIndexImpl in project intellij-community by JetBrains.
the class PersistenceStressTest method testReadWrite.
public void testReadWrite() throws Exception {
List<Future<Boolean>> futures = new ArrayList<>();
for (PersistentHashMap<String, Record> map : myMaps) {
Future<Boolean> submit = submit(map);
futures.add(submit);
}
Future<?> waitFuture = myThreadPool.submit(() -> {
try {
while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
Thread.sleep(100);
myMaps.forEach(PersistentHashMap::dropMemoryCaches);
}
} catch (InterruptedException ignore) {
}
});
List<VirtualFile> files = new ArrayList<>();
for (int i = 0; i < 100; i++) {
File file = FileUtil.createTempFile("", ".txt");
VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
assertNotNull(virtualFile);
PlatformTestCase.setFileText(virtualFile, "foo bar");
files.add(virtualFile);
}
FileBasedIndexImpl index = (FileBasedIndexImpl) FileBasedIndex.getInstance();
while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
Thread.sleep(100);
CacheUpdateRunner.processFiles(new EmptyProgressIndicator(), true, files, getProject(), content -> index.indexFileContent(getProject(), content));
}
for (Future<Boolean> future : futures) {
assertTrue(future.get());
}
waitFuture.get();
}
use of com.intellij.util.indexing.FileBasedIndexImpl in project intellij-community by JetBrains.
the class FindInProjectTask method collectFilesInScope.
// must return non-binary files
@NotNull
private Collection<VirtualFile> collectFilesInScope(@NotNull final Set<VirtualFile> alreadySearched, final boolean skipIndexed) {
SearchScope customScope = myFindModel.isCustomScope() ? myFindModel.getCustomScope() : null;
final GlobalSearchScope globalCustomScope = customScope == null ? null : GlobalSearchScopeUtil.toGlobalSearchScope(customScope, myProject);
final ProjectFileIndex fileIndex = ProjectFileIndex.SERVICE.getInstance(myProject);
final boolean hasTrigrams = hasTrigrams(myStringToFindInIndices);
class EnumContentIterator implements ContentIterator {
private final Set<VirtualFile> myFiles = new LinkedHashSet<>();
@Override
public boolean processFile(@NotNull final VirtualFile virtualFile) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
ProgressManager.checkCanceled();
if (virtualFile.isDirectory() || !virtualFile.isValid() || !myFileMask.value(virtualFile) || globalCustomScope != null && !globalCustomScope.contains(virtualFile)) {
return;
}
if (skipIndexed && isCoveredByIndex(virtualFile) && (fileIndex.isInContent(virtualFile) || fileIndex.isInLibraryClasses(virtualFile) || fileIndex.isInLibrarySource(virtualFile))) {
return;
}
Pair.NonNull<PsiFile, VirtualFile> pair = findFile(virtualFile);
if (pair == null)
return;
VirtualFile sourceVirtualFile = pair.second;
if (sourceVirtualFile != null && !alreadySearched.contains(sourceVirtualFile)) {
myFiles.add(sourceVirtualFile);
}
}
private final FileBasedIndexImpl fileBasedIndex = (FileBasedIndexImpl) FileBasedIndex.getInstance();
private boolean isCoveredByIndex(VirtualFile file) {
FileType fileType = file.getFileType();
if (hasTrigrams) {
return TrigramIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, TrigramIndex.INDEX_ID);
}
return IdIndex.isIndexable(fileType) && fileBasedIndex.isIndexingCandidate(file, IdIndex.NAME);
}
});
return true;
}
@NotNull
private Collection<VirtualFile> getFiles() {
return myFiles;
}
}
final EnumContentIterator iterator = new EnumContentIterator();
if (customScope instanceof LocalSearchScope) {
for (VirtualFile file : GlobalSearchScopeUtil.getLocalScopeFiles((LocalSearchScope) customScope)) {
iterator.processFile(file);
}
} else if (customScope instanceof Iterable) {
//noinspection unchecked
for (VirtualFile file : (Iterable<VirtualFile>) customScope) {
iterator.processFile(file);
}
} else if (myDirectory != null) {
final boolean checkExcluded = !ProjectFileIndex.SERVICE.getInstance(myProject).isExcluded(myDirectory);
VirtualFileVisitor.Option limit = VirtualFileVisitor.limit(myFindModel.isWithSubdirectories() ? -1 : 1);
VfsUtilCore.visitChildrenRecursively(myDirectory, new VirtualFileVisitor(limit) {
@Override
public boolean visitFile(@NotNull VirtualFile file) {
if (checkExcluded && myProjectFileIndex.isExcluded(file))
return false;
iterator.processFile(file);
return true;
}
});
} else {
boolean success = myFileIndex.iterateContent(iterator);
if (success && globalCustomScope != null && globalCustomScope.isSearchInLibraries()) {
final VirtualFile[] librarySources = ReadAction.compute(() -> {
OrderEnumerator enumerator = myModule == null ? OrderEnumerator.orderEntries(myProject) : OrderEnumerator.orderEntries(myModule);
return enumerator.withoutModuleSourceEntries().withoutDepModules().getSourceRoots();
});
iterateAll(librarySources, globalCustomScope, iterator);
}
}
return iterator.getFiles();
}
use of com.intellij.util.indexing.FileBasedIndexImpl in project Perl5-IDEA by Camelcade.
the class Mason2Util method reindexProjectRoots.
public static void reindexProjectRoots(Project project, List<String> rootsToReindex) {
if (rootsToReindex.isEmpty()) {
return;
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
VirtualFile projectRoot = project.getBaseDir();
if (projectRoot != null) {
final FileBasedIndex index = FileBasedIndex.getInstance();
for (String root : rootsToReindex) {
VirtualFile componentRoot = VfsUtil.findRelativeFile(root, projectRoot);
if (componentRoot != null) {
for (VirtualFile file : VfsUtil.collectChildrenRecursively(componentRoot)) {
if (file.getFileType() instanceof MasonPurePerlComponentFileType) {
index.requestReindex(file);
}
}
}
}
if (index instanceof FileBasedIndexImpl) {
DumbModeTask changedFilesIndexingTask = FileBasedIndexProjectHandler.createChangedFilesIndexingTask(project);
if (changedFilesIndexingTask != null) {
DumbServiceImpl.getInstance(project).queueTask(changedFilesIndexingTask);
}
}
}
}
Aggregations