Java Code Examples for com.intellij.openapi.vfs.VfsUtil#toVirtualFileArray()

The following examples show how to use com.intellij.openapi.vfs.VfsUtil#toVirtualFileArray() . 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: ModuleChunk.java    From consulo with Apache License 2.0 6 votes vote down vote up
private VirtualFile[] filterRoots(VirtualFile[] roots, Project project, final int sourcesFilter) {
  final List<VirtualFile> filteredRoots = new ArrayList<VirtualFile>(roots.length);
  for (final VirtualFile root : roots) {
    if (sourcesFilter != ALL_SOURCES) {
      if (myContext.isInTestSourceContent(root)) {
        if ((sourcesFilter & TEST_SOURCES) == 0) {
          continue;
        }
      }
      else {
        if ((sourcesFilter & SOURCES) == 0) {
          continue;
        }
      }
    }
    if (CompilerManager.getInstance(project).isExcludedFromCompilation(root)) {
      continue;
    }
    filteredRoots.add(root);
  }
  return VfsUtil.toVirtualFileArray(filteredRoots);
}
 
Example 2
Source File: PathEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private VirtualFile[] doAdd() {
  VirtualFile baseDir = myAddBaseDir;
  Project project = DataManager.getInstance().getDataContext(myComponent).getData(CommonDataKeys.PROJECT);
  if (baseDir == null && project != null) {
    baseDir = project.getBaseDir();
  }
  VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myComponent, project, baseDir);
  files = adjustAddedFileSet(myComponent, files);
  List<VirtualFile> added = new ArrayList<VirtualFile>(files.length);
  for (VirtualFile vFile : files) {
    if (addElement(vFile)) {
      added.add(vFile);
    }
  }
  return VfsUtil.toVirtualFileArray(added);
}
 
Example 3
Source File: OCamlSourcesOrderRootTypeUIFactory.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
protected VirtualFile[] adjustAddedFileSet(final Component component, final VirtualFile[] files) {
    java.util.List<OrderRoot> orderRoots = RootDetectionUtil
            .detectRoots(Arrays.asList(files), component, null, new OCamlRootsDetector(), new OrderRootType[]{OCamlSourcesOrderRootType.getInstance()});

    List<VirtualFile> result = new ArrayList<>();
    for (OrderRoot root : orderRoots) {
        result.add(root.getFile());
    }

    return VfsUtil.toVirtualFileArray(result);
}
 
Example 4
Source File: ModuleRootCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public VirtualFile[] getFiles(final FileType fileType, final boolean inSourceOnly) {
  final List<VirtualFile> files = new ArrayList<VirtualFile>();
  final FileIndex[] fileIndices = getFileIndices();
  for (final FileIndex fileIndex : fileIndices) {
    fileIndex.iterateContent(new ModuleRootCompilerContentIterator(fileType, files));
  }
  return VfsUtil.toVirtualFileArray(files);
}
 
Example 5
Source File: CompileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile[] getCompilableFiles(Project project, VirtualFile[] files) {
  if (files == null || files.length == 0) {
    return VirtualFile.EMPTY_ARRAY;
  }
  final PsiManager psiManager = PsiManager.getInstance(project);
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final CompilerManager compilerManager = CompilerManager.getInstance(project);
  final List<VirtualFile> filesToCompile = new ArrayList<VirtualFile>();
  for (final VirtualFile file : files) {
    if (!fileIndex.isInSourceContent(file)) {
      continue;
    }
    if (!file.isInLocalFileSystem()) {
      continue;
    }
    if (file.isDirectory()) {
      final PsiDirectory directory = psiManager.findDirectory(file);
      if (directory == null || PsiPackageManager.getInstance(project).findAnyPackage(directory) == null) {
        continue;
      }
    }
    else {
      FileType fileType = file.getFileType();
      if (!(compilerManager.isCompilableFileType(fileType) || isCompilableResourceFile(project, file))) {
        continue;
      }
    }
    filesToCompile.add(file);
  }
  return VfsUtil.toVirtualFileArray(filesToCompile);
}
 
Example 6
Source File: CompositeScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public VirtualFile[] getFiles(FileType fileType, boolean inSourceOnly) {
  Set<VirtualFile> allFiles = new THashSet<VirtualFile>();
  for (CompileScope scope : myScopes) {
    final VirtualFile[] files = scope.getFiles(fileType, inSourceOnly);
    if (files.length > 0) {
      ContainerUtil.addAll(allFiles, files);
    }
  }
  return VfsUtil.toVirtualFileArray(allFiles);
}
 
Example 7
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
private VirtualFile[] getAllSourceRoots() {
  final Set<Module> modules = getNodes();
  Set<VirtualFile> roots = new HashSet<VirtualFile>();
  for (final Module module : modules) {
    ContainerUtil.addAll(roots, myContext.getSourceRoots(module));
  }
  return VfsUtil.toVirtualFileArray(roots);
}
 
Example 8
Source File: CompileContextImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void recalculateOutputDirs() {
  final Module[] allModules = ModuleManager.getInstance(myProject).getModules();

  final Set<VirtualFile> allDirs = new OrderedSet<VirtualFile>();
  final Set<VirtualFile> testOutputDirs = new java.util.HashSet<VirtualFile>();
  final Set<VirtualFile> productionOutputDirs = new java.util.HashSet<VirtualFile>();

  for (Module module : allModules) {
    ModuleCompilerPathsManager moduleCompilerPathsManager = ModuleCompilerPathsManager.getInstance(module);

    final VirtualFile output = moduleCompilerPathsManager.getCompilerOutput(ProductionContentFolderTypeProvider.getInstance());
    if (output != null && output.isValid()) {
      allDirs.add(output);
      productionOutputDirs.add(output);
    }

    final VirtualFile testsOutput = moduleCompilerPathsManager.getCompilerOutput(TestContentFolderTypeProvider.getInstance());
    if (testsOutput != null && testsOutput.isValid()) {
      allDirs.add(testsOutput);
      testOutputDirs.add(testsOutput);
    }
  }
  myOutputDirectories = VfsUtil.toVirtualFileArray(allDirs);
  // need this to ensure that the sent contains only _dedicated_ test output dirs
  // Directories that are configured for both test and production classes must not be added in the resulting set
  testOutputDirs.removeAll(productionOutputDirs);
  myTestOutputDirectories = Collections.unmodifiableSet(testOutputDirs);
}
 
Example 9
Source File: OneProjectItemCompileScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public VirtualFile[] getFiles(final FileType fileType, final boolean inSourceOnly) {
  final List<VirtualFile> files = new ArrayList<VirtualFile>(1);
  final FileIndex 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);
}
 
Example 10
Source File: ToggleReadOnlyAttributeAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
static VirtualFile[] getFiles(DataContext dataContext){
  ArrayList<VirtualFile> filesList = new ArrayList<VirtualFile>();
  VirtualFile[] files = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
  for(int i=0;files!=null&&i<files.length;i++){
    VirtualFile file=files[i];
    if(file.isInLocalFileSystem()){
      filesList.add(file);
    }
  }
  return VfsUtil.toVirtualFileArray(filesList);
}
 
Example 11
Source File: UpdateInfoTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
private VirtualFile[] getVirtualFileArray() {
  ArrayList<VirtualFile> result = new ArrayList<>();
  TreePath[] selectionPaths = myTree.getSelectionPaths();
  if (selectionPaths != null) {
    for (TreePath selectionPath : selectionPaths) {
      AbstractTreeNode treeNode = (AbstractTreeNode)selectionPath.getLastPathComponent();
      result.addAll(treeNode.getVirtualFiles());
    }
  }
  return VfsUtil.toVirtualFileArray(result);
}
 
Example 12
Source File: VirtualFileArrayRule.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static VirtualFile[] getFilesFromModules(Module[] selectedModules) {
  ArrayList<VirtualFile> result = new ArrayList<>();
  for (Module selectedModule : selectedModules) {
    ContainerUtil.addAll(result, ModuleRootManager.getInstance(selectedModule).getContentRoots());
  }
  return VfsUtil.toVirtualFileArray(result);
}
 
Example 13
Source File: TestVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public VirtualFile[] getChildren() {
  return VfsUtil.toVirtualFileArray(myChildren);
}
 
Example 14
Source File: UndoRedo.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean execute(boolean drop, boolean isInsideStartFinishGroup) {
  if (!myUndoableGroup.isUndoable()) {
    reportCannotUndo(CommonBundle.message("cannot.undo.error.contains.nonundoable.changes.message"),
                     myUndoableGroup.getAffectedDocuments());
    return false;
  }

  Set<DocumentReference> clashing = getStackHolder().collectClashingActions(myUndoableGroup);
  if (!clashing.isEmpty()) {
    reportCannotUndo(CommonBundle.message("cannot.undo.error.other.affected.files.changed.message"), clashing);
    return false;
  }


  if (!isInsideStartFinishGroup && myUndoableGroup.shouldAskConfirmation(isRedo())) {
    if (!askUser()) return false;
  }
  else {
    if (restore(getBeforeState(), true)) {
      setBeforeState(new EditorAndState(myEditor, myEditor.getState(FileEditorStateLevel.UNDO)));
      return true;
    }
  }

  Collection<VirtualFile> readOnlyFiles = collectReadOnlyAffectedFiles();
  if (!readOnlyFiles.isEmpty()) {
    final Project project = myManager.getProject();
    final VirtualFile[] files = VfsUtil.toVirtualFileArray(readOnlyFiles);

    if (project == null) {
      return false;
    }

    final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
    if (operationStatus.hasReadonlyFiles()) {
      return false;
    }
  }

  Collection<Document> readOnlyDocuments = collectReadOnlyDocuments();
  if (!readOnlyDocuments.isEmpty()) {
    for (Document document : readOnlyDocuments) {
      document.fireReadOnlyModificationAttempt();
    }
    return false;
  }

  getStackHolder().removeFromStacks(myUndoableGroup);
  if (!drop) {
    getReverseStackHolder().addToStacks(myUndoableGroup);
  }

  performAction();

  restore(getAfterState(), false);

  return true;
}