Java Code Examples for com.intellij.openapi.vfs.VfsUtilCore#visitChildrenRecursively()

The following examples show how to use com.intellij.openapi.vfs.VfsUtilCore#visitChildrenRecursively() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OCamlSourcesOrderRootTypeUIFactory.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
@NotNull
List<VirtualFile> suggestOCamlRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) {
    if (!dir.isDirectory()) {
        return ContainerUtil.emptyList();
    }

    final FileTypeManager typeManager = FileTypeManager.getInstance();
    final ArrayList<VirtualFile> foundDirectories = new ArrayList<>();
    try {
        VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {
            @NotNull
            @Override
            public Result visitFileEx(@NotNull VirtualFile file) {
                progressIndicator.checkCanceled();

                if (!file.isDirectory()) {
                    FileType type = typeManager.getFileTypeByFileName(file.getName());

                    if (type.getDefaultExtension().equals("ml")) {
                        VirtualFile root = file.getParent();
                        if (root != null) {
                            foundDirectories.add(root);
                            return skipTo(root);
                        }
                    }
                }

                return CONTINUE;
            }
        });
    } catch (ProcessCanceledException ignore) {
    }

    return foundDirectories;
}
 
Example 2
Source File: RemoveBomAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void getFilesWithBom(@Nonnull VirtualFile root, @Nonnull final List<VirtualFile> result, final boolean all) {
  VfsUtilCore.visitChildrenRecursively(root, new VirtualFileVisitor() {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      if (file.isDirectory()) {
        if (!all && !result.isEmpty()) {
          return false;
        }
      }
      else if (file.getBOM() != null) {
        result.add(file);
      }
      return true;
    }
  });
}
 
Example 3
Source File: NewLibraryEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void collectJarFiles(@Nonnull VirtualFile dir, @Nonnull List<? super VirtualFile> container, final boolean recursively) {
  VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor(VirtualFileVisitor.SKIP_ROOT, recursively ? null : VirtualFileVisitor.ONE_LEVEL_DEEP) {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      FileType type;
      if (!file.isDirectory() && (type = FileTypeRegistry.getInstance().getFileTypeByFileName(file.getNameSequence())) instanceof ArchiveFileType) {
        VirtualFile jarRoot = ((ArchiveFileType)type).getFileSystem().findFileByPath(file.getPath() + URLUtil.JAR_SEPARATOR);
        if (jarRoot != null) {
          container.add(jarRoot);
          return false;
        }
      }
      return true;
    }
  });
}
 
Example 4
Source File: HaxeLibRootDetector.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private static boolean containsHaxeFiles(final VirtualFile dir) {
  final VirtualFileVisitor.Result result = VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {
    @NotNull
    @Override
    public Result visitFileEx(@NotNull VirtualFile file) {
      return !file.isDirectory() && HaxeFileType.DEFAULT_EXTENSION.equalsIgnoreCase(file.getExtension()) ? skipTo(dir) : CONTINUE;
    }
  });
  return result.skipToParent != null;
}
 
Example 5
Source File: AbstractDelombokAction.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processDirectory(@NotNull final Project project, @NotNull VirtualFile vFile) {
  VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
    @Override
    public boolean visitFile(@NotNull VirtualFile file) {
      if (!file.isDirectory()) {
        processFile(project, file);
      }
      return true;
    }
  });
}
 
Example 6
Source File: AnalysisScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void initFilesSet() {
  if (myType == FILE) {
    myFilesSet = new HashSet<VirtualFile>(1);
    myFilesSet.add(((PsiFileSystemItem)myElement).getVirtualFile());
  }
  else if (myType == DIRECTORY || myType == PROJECT || myType == MODULES || myType == MODULE || myType == CUSTOM) {
    myFilesSet = new HashSet<VirtualFile>();
    accept(createFileSearcher(), false);
  }
  else if (myType == VIRTUAL_FILES) {
    myFilesSet = new HashSet<VirtualFile>();
    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() {
        @Nonnull
        @Override
        public Result visitFileEx(@Nonnull VirtualFile file) {
          boolean ignored = fileIndex.isExcluded(file);
          if (!ignored && !file.isDirectory()) {
            myFilesSet.add(file);
          }
          return ignored ? SKIP_CHILDREN : CONTINUE;
        }
      });

      if (vFile.isDirectory()) {
        iterator.remove();
      }
    }
  }
}
 
Example 7
Source File: SymlinkTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void refresh(boolean recursive) {
  final VirtualFile tempDir = myFileSystem.findFileByIoFile(myTempDir);
  assertNotNull(myTempDir.getPath(), tempDir);
  tempDir.getChildren();
  tempDir.refresh(false, true);
  if (recursive) {
    VfsUtilCore.visitChildrenRecursively(tempDir, new VirtualFileVisitor() { });
  }
}
 
Example 8
Source File: FileSetCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addRecursively(final Collection<VirtualFile> container, VirtualFile fromDirectory, final FileType fileType) {
  VfsUtilCore.visitChildrenRecursively(fromDirectory, new VirtualFileVisitor(VirtualFileVisitor.SKIP_ROOT) {
    @Override
    public boolean visitFile(@Nonnull VirtualFile child) {
      if (!child.isDirectory() && (fileType == null || fileType.equals(child.getFileType()))) {
        container.add(child);
      }
      return true;
    }
  });
}
 
Example 9
Source File: FixLineSeparatorsAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void fixSeparators(VirtualFile vFile) {
  VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor() {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      if (!file.isDirectory() && !file.getFileType().isBinary()) {
        final Document document = FileDocumentManager.getInstance().getDocument(file);
        if (areSeparatorsBroken(document)) {
          fixSeparators(document);
        }
      }
      return true;
    }
  });
}
 
Example 10
Source File: CommonRefactoringUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void collectReadOnlyFiles(@Nonnull VirtualFile vFile, @Nonnull final Collection<VirtualFile> list) {
  final FileTypeManager fileTypeManager = FileTypeManager.getInstance();

  VfsUtilCore.visitChildrenRecursively(vFile, new VirtualFileVisitor(VirtualFileVisitor.NO_FOLLOW_SYMLINKS) {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      final boolean ignored = fileTypeManager.isFileIgnored(file);
      if (!file.isWritable() && !ignored) {
        list.add(file);
      }
      return !ignored;
    }
  });
}
 
Example 11
Source File: PatchProjectUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void iterate(VirtualFile contentRoot, final ContentIterator iterator, final ProjectFileIndex idx) {
  VfsUtilCore.visitChildrenRecursively(contentRoot, new VirtualFileVisitor() {
    @Override
    public boolean visitFile(@Nonnull VirtualFile file) {
      if (!iterator.processFile(file)) return false;
      if (idx.getModuleForFile(file) == null) return false;  // already excluded
      return true;
    }
  });
}
 
Example 12
Source File: Util.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public static void resetModificationStamp(VirtualFile fileOrFolder, boolean recursive) {
    VfsUtilCore.visitChildrenRecursively(
        fileOrFolder,
        new ResetFileVisitor(recursive)
    );
}