Search in sources :

Example 1 with FileBasedIndexImpl

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();
    }
}
Also used : UndoManagerImpl(com.intellij.openapi.command.impl.UndoManagerImpl) Project(com.intellij.openapi.project.Project) DocumentReferenceManagerImpl(com.intellij.openapi.command.impl.DocumentReferenceManagerImpl) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) LocalFileSystemImpl(com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl) ProjectManager(com.intellij.openapi.project.ProjectManager) ProjectManagerImpl(com.intellij.openapi.project.impl.ProjectManagerImpl)

Example 2 with FileBasedIndexImpl

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with FileBasedIndexImpl

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) FileType(com.intellij.openapi.fileTypes.FileType) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FileBasedIndexImpl

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);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MasonPurePerlComponentFileType(com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType) DumbModeTask(com.intellij.openapi.project.DumbModeTask) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Aggregations

FileBasedIndexImpl (com.intellij.util.indexing.FileBasedIndexImpl)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DocumentReferenceManagerImpl (com.intellij.openapi.command.impl.DocumentReferenceManagerImpl)1 UndoManagerImpl (com.intellij.openapi.command.impl.UndoManagerImpl)1 FileType (com.intellij.openapi.fileTypes.FileType)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 DumbModeTask (com.intellij.openapi.project.DumbModeTask)1 Project (com.intellij.openapi.project.Project)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 ProjectManagerImpl (com.intellij.openapi.project.impl.ProjectManagerImpl)1 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)1 LocalFileSystemImpl (com.intellij.openapi.vfs.impl.local.LocalFileSystemImpl)1 PsiManagerImpl (com.intellij.psi.impl.PsiManagerImpl)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 MasonPurePerlComponentFileType (com.perl5.lang.mason2.filetypes.MasonPurePerlComponentFileType)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Future (java.util.concurrent.Future)1 NotNull (org.jetbrains.annotations.NotNull)1