Search in sources :

Example 1 with Processors

use of com.intellij.util.Processors in project intellij-community by JetBrains.

the class PsiSearchHelperImpl method collectFiles.

private void collectFiles(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles, @NotNull ProgressIndicator progress, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
    for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
        final Set<IdIndexEntry> keys = entry.getKey();
        if (keys.isEmpty()) {
            continue;
        }
        final Collection<RequestWithProcessor> processors = entry.getValue();
        final GlobalSearchScope commonScope = uniteScopes(processors);
        final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);
        List<VirtualFile> result = new ArrayList<>();
        Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
        processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
        for (final VirtualFile file : result) {
            progress.checkCanceled();
            for (final IdIndexEntry indexEntry : keys) {
                DumbService.getInstance(myManager.getProject()).runReadActionInSmartMode(() -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
                    int mask = value.intValue();
                    for (RequestWithProcessor single : processors) {
                        final PsiSearchRequest request = single.request;
                        if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
                            MultiMap<VirtualFile, RequestWithProcessor> result1 = intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
                            result1.putValue(file1, single);
                        }
                    }
                    return true;
                }, commonScope));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) CommentUtilCore(com.intellij.util.codeInsight.CommentUtilCore) JobLauncher(com.intellij.concurrency.JobLauncher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) ReadAction(com.intellij.openapi.application.ReadAction) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) StringSearcher(com.intellij.util.text.StringSearcher) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DumbService(com.intellij.openapi.project.DumbService) StringUtil(com.intellij.openapi.util.text.StringUtil) Processors(com.intellij.util.Processors) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) ProgressIndicatorProvider(com.intellij.openapi.progress.ProgressIndicatorProvider) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) AsyncFuture(com.intellij.concurrency.AsyncFuture) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) com.intellij.psi.search(com.intellij.psi.search) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdIndex(com.intellij.psi.impl.cache.impl.id.IdIndex) com.intellij.psi(com.intellij.psi) UsageInfoFactory(com.intellij.usageView.UsageInfoFactory) AsyncUtil(com.intellij.concurrency.AsyncUtil) NotNull(org.jetbrains.annotations.NotNull) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Aggregations

AsyncFuture (com.intellij.concurrency.AsyncFuture)1 AsyncUtil (com.intellij.concurrency.AsyncUtil)1 JobLauncher (com.intellij.concurrency.JobLauncher)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 ReadAction (com.intellij.openapi.application.ReadAction)1 ReadActionProcessor (com.intellij.openapi.application.ReadActionProcessor)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 ApplicationUtil (com.intellij.openapi.application.ex.ApplicationUtil)1 Logger (com.intellij.openapi.diagnostic.Logger)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1 FileDocumentManager (com.intellij.openapi.fileEditor.FileDocumentManager)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProgressIndicatorProvider (com.intellij.openapi.progress.ProgressIndicatorProvider)1 TooManyUsagesStatus (com.intellij.openapi.progress.util.TooManyUsagesStatus)1 DumbService (com.intellij.openapi.project.DumbService)1 Project (com.intellij.openapi.project.Project)1 FileIndexFacade (com.intellij.openapi.roots.FileIndexFacade)1 com.intellij.openapi.util (com.intellij.openapi.util)1