Search in sources :

Example 6 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.

the class ModuleChunkSourcePath method addExcludePatterns.

private static void addExcludePatterns(Module module, final VirtualFile root, VirtualFile dir, final CompositeGenerator generator, final boolean parentIncluded) {
    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile dir) {
            if (!dir.isDirectory() || fileTypeManager.isFileIgnored(dir)) {
                // ignored files are handled by global 'ignored' pattern set
                return false;
            }
            final boolean isIncluded = moduleRootManager.getFileIndex().isInContent(dir);
            if (isIncluded != parentIncluded) {
                final String relativePath = VfsUtilCore.getRelativePath(dir, root, '/');
                if (isIncluded) {
                    generator.add(new Include(relativePath + "/**"));
                } else {
                    if (!isExcludedByDefault(dir.getName())) {
                        generator.add(new Exclude(relativePath + "/**"));
                    }
                }
            }
            return true;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor)

Example 7 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-elixir by KronicDeth.

the class MixProjectImportBuilder method findMixExs.

@NotNull
private List<VirtualFile> findMixExs(@NotNull final VirtualFile root, @NotNull final ProgressIndicator indicator) {
    // synchronous and recursive
    root.refresh(false, true);
    final List<VirtualFile> foundMixExs = new ArrayList<VirtualFile>();
    VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {

        @Override
        public boolean visitFile(@NotNull VirtualFile file) {
            indicator.checkCanceled();
            if (file.isDirectory()) {
                if (isBuildOrConfigOrDepsOrTestsDirectory(root.getPath(), file.getPath()))
                    return false;
                indicator.setText2(file.getPath());
            } else if (file.getName().equalsIgnoreCase("mix.exs")) {
                foundMixExs.add(file);
            }
            return true;
        }
    });
    return foundMixExs;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.

the class LightProjectDescriptor method registerSourceRoot.

protected void registerSourceRoot(Project project, VirtualFile srcRoot) {
    IndexableFileSet indexableFileSet = new IndexableFileSet() {

        @Override
        public boolean isInSet(@NotNull VirtualFile file) {
            return file.getFileSystem() == srcRoot.getFileSystem() && project.isOpen();
        }

        @Override
        public void iterateIndexableFilesIn(@NotNull VirtualFile file, @NotNull ContentIterator iterator) {
            VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {

                @Override
                public boolean visitFile(@NotNull VirtualFile file) {
                    iterator.processFile(file);
                    return true;
                }
            });
        }
    };
    FileBasedIndex.getInstance().registerIndexableSet(indexableFileSet, null);
    Disposer.register(project, () -> FileBasedIndex.getInstance().removeIndexableSet(indexableFileSet));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentIterator(com.intellij.openapi.roots.ContentIterator) IndexableFileSet(com.intellij.util.indexing.IndexableFileSet) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.

the class BytecodeAnalysisIntegrationTest method setUpExternalUpAnnotations.

private void setUpExternalUpAnnotations() {
    String annotationsPath = PathManagerEx.getTestDataPath() + "/codeInspection/bytecodeAnalysis/annotations";
    VirtualFile annotationsDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(annotationsPath);
    assertNotNull(annotationsDir);
    ModuleRootModificationUtil.updateModel(myModule, new AsynchConsumer<ModifiableRootModel>() {

        @Override
        public void finished() {
        }

        @Override
        public void consume(ModifiableRootModel modifiableRootModel) {
            LibraryTable libraryTable = modifiableRootModel.getModuleLibraryTable();
            Library[] libs = libraryTable.getLibraries();
            for (Library library : libs) {
                Library.ModifiableModel libraryModel = library.getModifiableModel();
                libraryModel.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
                libraryModel.commit();
            }
            Sdk sdk = modifiableRootModel.getSdk();
            if (sdk != null) {
                Sdk clone;
                try {
                    clone = (Sdk) sdk.clone();
                } catch (CloneNotSupportedException e) {
                    throw new RuntimeException(e);
                }
                SdkModificator sdkModificator = clone.getSdkModificator();
                sdkModificator.addRoot(annotationsDir, AnnotationOrderRootType.getInstance());
                sdkModificator.commitChanges();
                modifiableRootModel.setSdk(clone);
            }
        }
    });
    VfsUtilCore.visitChildrenRecursively(annotationsDir, new VirtualFileVisitor() {
    });
    annotationsDir.refresh(false, true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 10 with VirtualFileVisitor

use of com.intellij.openapi.vfs.VirtualFileVisitor in project intellij-community by JetBrains.

the class AnalysisScope method initFilesSet.

protected void initFilesSet() {
    if (myType == FILE) {
        myFilesSet = new HashSet<>(1);
        myFilesSet.add(((PsiFileSystemItem) myElement).getVirtualFile());
    } else if (myType == DIRECTORY || myType == PROJECT || myType == MODULES || myType == MODULE || myType == CUSTOM) {
        myFilesSet = new THashSet<>();
        accept(createFileSearcher(), false);
    } else if (myType == VIRTUAL_FILES) {
        myFilesSet = new THashSet<>();
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
        for (Iterator<VirtualFile> iterator = myVFiles.iterator(); iterator.hasNext(); ) {
            final VirtualFile vFile = iterator.next();
            VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {

                @NotNull
                @Override
                public Result visitFileEx(@NotNull VirtualFile file) {
                    boolean ignored = fileIndex.isExcluded(file);
                    if (!ignored && !file.isDirectory()) {
                        myFilesSet.add(file);
                    }
                    return ignored ? SKIP_CHILDREN : CONTINUE;
                }
            });
            if (vFile.isDirectory()) {
                iterator.remove();
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileVisitor(com.intellij.openapi.vfs.VirtualFileVisitor) NotNull(org.jetbrains.annotations.NotNull) THashSet(gnu.trove.THashSet)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 VirtualFileVisitor (com.intellij.openapi.vfs.VirtualFileVisitor)23 NotNull (org.jetbrains.annotations.NotNull)12 FileTypeManager (com.intellij.openapi.fileTypes.FileTypeManager)4 File (java.io.File)4 FileType (com.intellij.openapi.fileTypes.FileType)3 IOException (java.io.IOException)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 Result (com.intellij.openapi.application.Result)1 PatchApplier (com.intellij.openapi.diff.impl.patch.formove.PatchApplier)1 FileTypeRegistry (com.intellij.openapi.fileTypes.FileTypeRegistry)1 Module (com.intellij.openapi.module.Module)1 ModuleImpl (com.intellij.openapi.module.impl.ModuleImpl)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 ContentIterator (com.intellij.openapi.roots.ContentIterator)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1