Search in sources :

Example 1 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class GroovyAntCustomCompilerProvider method hasCustomCompile.

/**
   * {@inheritDoc}
   */
@Override
public boolean hasCustomCompile(ModuleChunk chunk) {
    for (Module m : chunk.getModules()) {
        if (LibrariesUtil.hasGroovySdk(m)) {
            final Set<String> scriptExtensions = GroovyFileTypeLoader.getCustomGroovyScriptExtensions();
            final ContentIterator groovyFileSearcher = new ContentIterator() {

                @Override
                public boolean processFile(VirtualFile fileOrDir) {
                    ProgressManager.checkCanceled();
                    if (isCompilableGroovyFile(fileOrDir, scriptExtensions)) {
                        return false;
                    }
                    return true;
                }
            };
            final ModuleRootManager rootManager = ModuleRootManager.getInstance(m);
            final ModuleFileIndex fileIndex = rootManager.getFileIndex();
            for (VirtualFile file : rootManager.getSourceRoots(JavaModuleSourceRootTypes.SOURCES)) {
                if (!fileIndex.iterateContentUnderDirectory(file, groovyFileSearcher)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleFileIndex(com.intellij.openapi.roots.ModuleFileIndex) Module(com.intellij.openapi.module.Module)

Example 2 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class PyIntegratedToolsConfigurable method reparseFiles.

public void reparseFiles(final List<String> extensions) {
    final List<VirtualFile> filesToReparse = Lists.newArrayList();
    ProjectRootManager.getInstance(myProject).getFileIndex().iterateContent(new ContentIterator() {

        @Override
        public boolean processFile(VirtualFile fileOrDir) {
            if (!fileOrDir.isDirectory() && extensions.contains(fileOrDir.getExtension())) {
                filesToReparse.add(fileOrDir);
            }
            return true;
        }
    });
    FileContentUtilCore.reparseFiles(filesToReparse);
    PyUtil.rehighlightOpenEditors(myProject);
    DaemonCodeAnalyzer.getInstance(myProject).restart();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator)

Example 3 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator 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)

Example 4 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class OneProjectItemCompileScope method getFiles.

@NotNull
public VirtualFile[] getFiles(final FileType fileType, final boolean inSourceOnly) {
    final List<VirtualFile> files = new ArrayList<>(1);
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    final ContentIterator iterator = new CompilerContentIterator(fileType, projectFileIndex, inSourceOnly, files);
    if (myFile.isDirectory()) {
        projectFileIndex.iterateContentUnderDirectory(myFile, iterator);
    } else {
        iterator.processFile(myFile);
    }
    return VfsUtil.toVirtualFileArray(files);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ContentIterator

use of com.intellij.openapi.roots.ContentIterator in project intellij-community by JetBrains.

the class IndexedFilesListener method buildIndicesForFileRecursively.

protected void buildIndicesForFileRecursively(@NotNull final VirtualFile file, final boolean contentChange) {
    if (file.isDirectory()) {
        final ContentIterator iterator = fileOrDir -> {
            buildIndicesForFile(fileOrDir, contentChange);
            return true;
        };
        iterateIndexableFiles(file, iterator);
    } else {
        buildIndicesForFile(file, contentChange);
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) PathManager(com.intellij.openapi.application.PathManager) ContentIterator(com.intellij.openapi.roots.ContentIterator) BulkVirtualFileListenerAdapter(com.intellij.openapi.vfs.impl.BulkVirtualFileListenerAdapter) IOException(java.io.IOException) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) com.intellij.openapi.vfs(com.intellij.openapi.vfs) FileUtil(com.intellij.openapi.util.io.FileUtil) NotNull(org.jetbrains.annotations.NotNull) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) ContentIterator(com.intellij.openapi.roots.ContentIterator)

Aggregations

ContentIterator (com.intellij.openapi.roots.ContentIterator)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 NotNull (org.jetbrains.annotations.NotNull)8 Project (com.intellij.openapi.project.Project)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)4 IOException (java.io.IOException)4 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 ProjectRootManager (com.intellij.openapi.roots.ProjectRootManager)3 File (java.io.File)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)2 ModuleFileIndex (com.intellij.openapi.roots.ModuleFileIndex)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2 Condition (com.intellij.openapi.util.Condition)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)2 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)2 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 PsiDirectory (com.intellij.psi.PsiDirectory)2