Search in sources :

Example 1 with Conditions

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

the class SearchScope method iterateContent.

public void iterateContent(@NotNull final Project project, final Processor<VirtualFile> processor) {
    switch(getScopeType()) {
        case PROJECT:
            //noinspection unchecked
            ProjectRootManager.getInstance(project).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
            break;
        case MODULE:
            final Module module = ModuleManager.getInstance(project).findModuleByName(getModuleName());
            assert module != null;
            ModuleRootManager.getInstance(module).getFileIndex().iterateContent(new MyFileIterator(processor, Conditions.<VirtualFile>alwaysTrue()));
            break;
        case DIRECTORY:
            final String dirName = getPath();
            assert dirName != null;
            final VirtualFile virtualFile = findFile(dirName);
            if (virtualFile != null) {
                iterateRecursively(virtualFile, processor, isRecursive());
            }
            break;
        case CUSTOM:
            assert myCustomScope != null;
            final ContentIterator iterator;
            if (myCustomScope instanceof GlobalSearchScope) {
                final GlobalSearchScope searchScope = (GlobalSearchScope) myCustomScope;
                iterator = new MyFileIterator(processor, virtualFile13 -> searchScope.contains(virtualFile13));
                if (searchScope.isSearchInLibraries()) {
                    final OrderEnumerator enumerator = OrderEnumerator.orderEntries(project).withoutModuleSourceEntries().withoutDepModules();
                    final Collection<VirtualFile> libraryFiles = new THashSet<>();
                    Collections.addAll(libraryFiles, enumerator.getClassesRoots());
                    Collections.addAll(libraryFiles, enumerator.getSourceRoots());
                    final Processor<VirtualFile> adapter = virtualFile1 -> iterator.processFile(virtualFile1);
                    for (final VirtualFile file : libraryFiles) {
                        iterateRecursively(file, adapter, true);
                    }
                }
            } else {
                final PsiManager manager = PsiManager.getInstance(project);
                iterator = new MyFileIterator(processor, virtualFile12 -> {
                    final PsiFile element = manager.findFile(virtualFile12);
                    return element != null && PsiSearchScopeUtil.isInScope(myCustomScope, element);
                });
            }
            ProjectRootManager.getInstance(project).getFileIndex().iterateContent(iterator);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) Tag(com.intellij.util.xmlb.annotations.Tag) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashSet(gnu.trove.THashSet) PsiManager(com.intellij.psi.PsiManager) Comparing(com.intellij.openapi.util.Comparing) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Conditions(com.intellij.openapi.util.Conditions) Module(com.intellij.openapi.module.Module) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) ContentIterator(com.intellij.openapi.roots.ContentIterator) Collection(java.util.Collection) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Nullable(org.jetbrains.annotations.Nullable) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) PsiSearchScopeUtil(com.intellij.psi.search.PsiSearchScopeUtil) Processor(com.intellij.util.Processor) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) Attribute(com.intellij.util.xmlb.annotations.Attribute) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) ContentIterator(com.intellij.openapi.roots.ContentIterator) PsiManager(com.intellij.psi.PsiManager) THashSet(gnu.trove.THashSet) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Aggregations

Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Project (com.intellij.openapi.project.Project)1 ContentIterator (com.intellij.openapi.roots.ContentIterator)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 OrderEnumerator (com.intellij.openapi.roots.OrderEnumerator)1 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)1 Comparing (com.intellij.openapi.util.Comparing)1 Condition (com.intellij.openapi.util.Condition)1 Conditions (com.intellij.openapi.util.Conditions)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PsiSearchScopeUtil (com.intellij.psi.search.PsiSearchScopeUtil)1 Processor (com.intellij.util.Processor)1 Attribute (com.intellij.util.xmlb.annotations.Attribute)1