com.intellij.openapi.roots.ProjectRootManager Java Examples

The following examples show how to use com.intellij.openapi.roots.ProjectRootManager. 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: ProjectViewPane.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean canBeSelectedInProjectView(@Nonnull Project project, @Nonnull VirtualFile file) {
  final VirtualFile archiveFile;

  if (file.getFileSystem() instanceof ArchiveFileSystem) {
    archiveFile = ArchiveVfsUtil.getVirtualFileForArchive(file);
  }
  else {
    archiveFile = null;
  }

  ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  return (archiveFile != null && index.getContentRootForFile(archiveFile, false) != null) ||
         index.getContentRootForFile(file, false) != null ||
         index.isInLibrary(file) ||
         Comparing.equal(file.getParent(), project.getBaseDir()) ||
         ScratchUtil.isScratch(file);
}
 
Example #2
Source File: ForwardDependenciesBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void analyze() {
  final PsiManager psiManager = PsiManager.getInstance(getProject());
  psiManager.startBatchFilesProcessingMode();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(getProject()).getFileIndex();
  try {
    getScope().accept(new PsiRecursiveElementVisitor() {
      @Override public void visitFile(final PsiFile file) {
        visit(file, fileIndex, psiManager, 0);
      }
    });
  }
  finally {
    psiManager.finishBatchFilesProcessingMode();
  }
}
 
Example #3
Source File: GenerateAction.java    From RIBs with Apache License 2.0 6 votes vote down vote up
/**
 * Checked whether or not this action can be enabled.
 * <p>
 * <p>Requirements to be enabled: * User must be in a Java source folder.
 *
 * @param dataContext to figure out where the user is.
 * @return {@code true} when the action is available, {@code false} when the action is not
 * available.
 */
private boolean isAvailable(DataContext dataContext) {
  final Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return false;
  }

  final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
  if (view == null || view.getDirectories().length == 0) {
    return false;
  }

  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  for (PsiDirectory dir : view.getDirectories()) {
    if (projectFileIndex.isUnderSourceRootOfType(
        dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES)
        && checkPackageExists(dir)) {
      return true;
    }
  }

  return false;
}
 
Example #4
Source File: ORProjectRootListener.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
private ORProjectRootListener(@NotNull Project project) {
    project.getMessageBus().
            connect(project).
            subscribe(PROJECT_ROOTS, new ModuleRootListener() {
                @Override
                public void rootsChanged(@NotNull ModuleRootEvent event) {
                    DumbService.getInstance(project).queueTask(new DumbModeTask() {
                        @Override
                        public void performInDumbMode(@NotNull ProgressIndicator indicator) {
                            if (!project.isDisposed()) {
                                indicator.setText("Updating resource repository roots");
                                // should be done per module
                                //ModuleManager moduleManager = ModuleManager.getInstance(project);
                                //for (Module module : moduleManager.getModules()) {
                                //    moduleRootsOrDependenciesChanged(module);
                                //}
                                Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
                                if (projectSdk != null && projectSdk.getSdkType() instanceof OCamlSdkType) {
                                    OCamlSdkType.reindexSourceRoots(projectSdk);
                                }
                            }
                        }
                    });
                }
            });
}
 
Example #5
Source File: HighlightingSettingsPerFile.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean shouldInspect(@Nonnull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  if (!shouldHighlight(psiRoot)) return false;
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;

  final FileHighlightingSetting settingForRoot = getHighlightingSettingForRoot(psiRoot);
  return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
 
Example #6
Source File: DocCommentProcessor.java    From markdown-doclet with GNU General Public License v3.0 6 votes vote down vote up
public DocCommentProcessor(PsiFile file) {
    this.file = file;
    if ( file == null ) {
        project = null;
        markdownOptions = null;
        psiElementFactory = null;
    }
    else {
        project = file.getProject();
        psiElementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
        ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        Module module = fileIndex.getModuleForFile(file.getVirtualFile());
        if ( module == null ) {
            markdownOptions = null;
        }
        else if ( !fileIndex.isInSourceContent(file.getVirtualFile()) ) {
            markdownOptions = null;
        }
        else if ( !Plugin.moduleConfiguration(module).isMarkdownEnabled() ) {
            markdownOptions = null;
        }
        else {
            markdownOptions = Plugin.moduleConfiguration(module).getRenderingOptions();
        }
    }
}
 
Example #7
Source File: ModuleVcsPathPresenter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String getPresentableRelativePathFor(final VirtualFile file) {
  if (file == null) return "";
  return ApplicationManager.getApplication().runReadAction(new Computable<String>() {
    @Override
    public String compute() {
      ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
      Module module = fileIndex.getModuleForFile(file, false);
      VirtualFile contentRoot = fileIndex.getContentRootForFile(file, false);
      if (module == null || contentRoot == null) return file.getPresentableUrl();
      StringBuilder result = new StringBuilder();
      result.append("[");
      result.append(module.getName());
      result.append("] ");
      result.append(contentRoot.getName());
      String relativePath = VfsUtilCore.getRelativePath(file, contentRoot, File.separatorChar);
      if (!relativePath.isEmpty()) {
        result.append(File.separatorChar);
        result.append(relativePath);
      }
      return result.toString();
    }
  });
}
 
Example #8
Source File: ProjectLocatorImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public Collection<Project> getProjectsForFile(VirtualFile file) {
  if (file == null) {
    return Collections.emptyList();
  }

  Project[] openProjects = myProjectManager.getOpenProjects();
  if (openProjects.length == 0) {
    return Collections.emptyList();
  }

  List<Project> result = new ArrayList<>(openProjects.length);
  for (Project openProject : openProjects) {
    if (openProject.isInitialized() && !openProject.isDisposed() && ProjectRootManager.getInstance(openProject).getFileIndex().isInContent(file)) {
      result.add(openProject);
    }
  }

  return result;
}
 
Example #9
Source File: TodoDirNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void updateImpl(@Nonnull PresentationData data) {
  super.updateImpl(data);
  int fileCount = getFileCount(getValue());
  if (getValue() == null || !getValue().isValid() || fileCount == 0) {
    setValue(null);
    return;
  }

  VirtualFile directory = getValue().getVirtualFile();
  boolean isProjectRoot = !ProjectRootManager.getInstance(getProject()).getFileIndex().isInContent(directory);
  String newName = isProjectRoot || getStructure().getIsFlattenPackages() ? getValue().getVirtualFile().getPresentableUrl() : getValue().getName();

  int todoItemCount = getTodoItemCount(getValue());
  data.setLocationString(IdeBundle.message("node.todo.group", todoItemCount));
  data.setPresentableText(newName);
}
 
Example #10
Source File: CopyReferenceAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static String getVirtualFileFqn(@Nonnull VirtualFile virtualFile, @Nonnull Project project) {
  final LogicalRoot logicalRoot = LogicalRootsManager.getLogicalRootsManager(project).findLogicalRoot(virtualFile);
  VirtualFile logicalRootFile = logicalRoot != null ? logicalRoot.getVirtualFile() : null;
  if (logicalRootFile != null && !virtualFile.equals(logicalRootFile)) {
    return ObjectUtil.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, logicalRootFile, '/'));
  }

  VirtualFile outerMostRoot = null;
  VirtualFile each = virtualFile;
  ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
  while (each != null && (each = index.getContentRootForFile(each, false)) != null) {
    outerMostRoot = each;
    each = each.getParent();
  }

  if (outerMostRoot != null && !outerMostRoot.equals(virtualFile)) {
    return ObjectUtil.assertNotNull(VfsUtilCore.getRelativePath(virtualFile, outerMostRoot, '/'));
  }

  return virtualFile.getPath();
}
 
Example #11
Source File: FileDirRelativeToSourcepathMacro.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String expand(final DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return null;
  }
  VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE);
  if (file == null) {
    return null;
  }
  if (!file.isDirectory()) {
    file = file.getParent();
    if (file == null) {
      return null;
    }
  }
  final VirtualFile sourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(file);
  if (sourceRoot == null) return null;
  return FileUtil.getRelativePath(getIOFile(sourceRoot), getIOFile(file));
}
 
Example #12
Source File: Workspace.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns the Bazel WORKSPACE file for a Project, or null if not using Bazel.
 * <p>
 * At least one content root must be within the workspace, and the project cannot have
 * content roots in more than one workspace.
 */
@Nullable
private static VirtualFile findWorkspaceFile(@NotNull Project p) {
  final Computable<VirtualFile> readAction = () -> {
    final Map<String, VirtualFile> candidates = new HashMap<>();
    for (VirtualFile contentRoot : ProjectRootManager.getInstance(p).getContentRoots()) {
      final VirtualFile wf = findContainingWorkspaceFile(contentRoot);
      if (wf != null) {
        candidates.put(wf.getPath(), wf);
      }
    }

    if (candidates.size() == 1) {
      return candidates.values().iterator().next();
    }

    // not found
    return null;
  };
  return ApplicationManager.getApplication().runReadAction(readAction);
}
 
Example #13
Source File: ProjectScopeBuilderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public GlobalSearchScope buildAllScope() {
  ProjectRootManager projectRootManager = myProject.isDefault() ? null : ProjectRootManager.getInstance(myProject);
  if (projectRootManager == null) {
    return new EverythingGlobalScope(myProject);
  }

  return new ProjectAndLibrariesScope(myProject) {
    @Override
    public boolean contains(@Nonnull VirtualFile file) {
      DirectoryInfo info = ((ProjectFileIndexImpl)myProjectFileIndex).getInfoForFileOrDirectory(file);
      return info.isInProject(file) && (info.getModule() != null || info.hasLibraryClassRoot() || info.isInLibrarySource(file));
    }
  };
}
 
Example #14
Source File: ProjectFileIndexSampleAction.java    From intellij-sdk-docs with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
  Project project = event.getProject();
  final Editor editor = event.getData(CommonDataKeys.EDITOR);
  if (project == null || editor == null) return;
  Document document = editor.getDocument();
  FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
  VirtualFile virtualFile = fileDocumentManager.getFile(document);
  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (virtualFile != null) {
    Module module = projectFileIndex.getModuleForFile(virtualFile);
    String moduleName;
    moduleName = module != null ? module.getName() : "No module defined for file";

    VirtualFile moduleContentRoot = projectFileIndex.getContentRootForFile(virtualFile);
    boolean isLibraryFile = projectFileIndex.isLibraryClassFile(virtualFile);
    boolean isInLibraryClasses = projectFileIndex.isInLibraryClasses(virtualFile);
    boolean isInLibrarySource = projectFileIndex.isInLibrarySource(virtualFile);
    Messages.showInfoMessage("Module: " + moduleName + "\n" +
                             "Module content root: " + moduleContentRoot + "\n" +
                             "Is library file: " + isLibraryFile + "\n" +
                             "Is in library classes: " + isInLibraryClasses +
                             ", Is in library source: " + isInLibrarySource,
                             "Main File Info for" + virtualFile.getName());
  }
}
 
Example #15
Source File: TodoTreeBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return read-only iterator of all valid PSI files that can have T.O.D.O items
 * and which in specified {@code module}.
 * @see FileTree#getFiles(VirtualFile)
 */
public Iterator<PsiFile> getFiles(Module module) {
  if (module.isDisposed()) return Collections.emptyIterator();
  ArrayList<PsiFile> psiFileList = new ArrayList<>();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
  for (VirtualFile virtualFile : contentRoots) {
    List<VirtualFile> files = myFileTree.getFiles(virtualFile);
    PsiManager psiManager = PsiManager.getInstance(myProject);
    for (VirtualFile file : files) {
      if (fileIndex.getModuleForFile(file) != module) continue;
      if (file.isValid()) {
        PsiFile psiFile = psiManager.findFile(file);
        if (psiFile != null) {
          psiFileList.add(psiFile);
        }
      }
    }
  }
  return psiFileList.iterator();
}
 
Example #16
Source File: OSSPantsJavaExamplesIntegrationTest.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
public void testCompileWithProjectJdk() throws Throwable {
  doImport("examples/src/java/org/pantsbuild/example/hello/greet");

  assertFirstSourcePartyModules(
    "examples_src_java_org_pantsbuild_example_hello_greet_greet"
  );

  PantsSettings settings = PantsSettings.getInstance(myProject);
  settings.setUseIdeaProjectJdk(true);
  PantsExecuteTaskResult result = pantsCompileProject();
  assertPantsCompileExecutesAndSucceeds(result);
  assertContainsSubstring(result.output.get(), PantsConstants.PANTS_CLI_OPTION_JVM_DISTRIBUTIONS_PATHS);
  assertContainsSubstring(result.output.get(), PantsUtil.getJdkPathFromIntelliJCore());

  settings.setUseIdeaProjectJdk(false);
  PantsExecuteTaskResult resultB = pantsCompileProject();
  assertPantsCompileExecutesAndSucceeds(result);
  assertContainsSubstring(resultB.output.get(), PantsConstants.PANTS_CLI_OPTION_JVM_DISTRIBUTIONS_PATHS);
  assertContainsSubstring(resultB.output.get(), ProjectRootManager.getInstance(myProject).getProjectSdk().getHomePath());
}
 
Example #17
Source File: SimpleCoverageAnnotator.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void annotate(@Nonnull final VirtualFile contentRoot,
                     @Nonnull final CoverageSuitesBundle suite,
                     final @Nonnull CoverageDataManager dataManager, @Nonnull final ProjectData data,
                     final Project project,
                     final Annotator annotator)
{
  if (!contentRoot.isValid()) {
    return;
  }

  // TODO: check name filter!!!!!

  final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();

  @SuppressWarnings("unchecked") final Set<String> files = data.getClasses().keySet();
  final Map<String, String> normalizedFiles2Files = ContainerUtil.newHashMap();
  for (final String file : files) {
    normalizedFiles2Files.put(normalizeFilePath(file), file);
  }
  collectFolderCoverage(contentRoot, dataManager, annotator, data,
                        suite.isTrackTestFolders(),
                        index,
                        suite.getCoverageEngine(),
                        ContainerUtil.<VirtualFile>newHashSet(),
                        Collections.unmodifiableMap(normalizedFiles2Files));
}
 
Example #18
Source File: ResourceFileUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static VirtualFile findResourceFile(final String name, final Module inModule) {
  final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(inModule).getContentFolderFiles(ContentFolderScopes.productionAndTest());
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(inModule.getProject()).getFileIndex();
  for (final VirtualFile sourceRoot : sourceRoots) {
    final String packagePrefix = fileIndex.getPackageNameByDirectory(sourceRoot);
    final String prefix = packagePrefix == null || packagePrefix.isEmpty() ? null : packagePrefix.replace('.', '/') + "/";
    final String relPath = prefix != null && name.startsWith(prefix) && name.length() > prefix.length() ? name.substring(prefix.length()) : name;
    final String fullPath = sourceRoot.getPath() + "/" + relPath;
    final VirtualFile fileByPath = LocalFileSystem.getInstance().findFileByPath(fullPath);
    if (fileByPath != null) {
      return fileByPath;
    }
  }
  return null;
}
 
Example #19
Source File: CompileContextImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CompileContextImpl(final Project project,
                          final CompilerTask compilerSession,
                          CompileScope compileScope,
                          CompositeDependencyCache dependencyCache,
                          boolean isMake,
                          boolean isRebuild) {
  myProject = project;
  myTask = compilerSession;
  myCompileScope = compileScope;
  myDependencyCache = dependencyCache;
  myMake = isMake;
  myIsRebuild = isRebuild;
  myStartCompilationStamp = System.currentTimeMillis();
  myProjectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();

  recalculateOutputDirs();
}
 
Example #20
Source File: HighlightLevelUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static boolean shouldInspect(@Nonnull PsiElement psiRoot) {
  if (ApplicationManager.getApplication().isUnitTestMode()) return true;

  if (!shouldHighlight(psiRoot)) return false;
  final Project project = psiRoot.getProject();
  final VirtualFile virtualFile = psiRoot.getContainingFile().getVirtualFile();
  if (virtualFile == null || !virtualFile.isValid()) return false;

  if (ProjectCoreUtil.isProjectOrWorkspaceFile(virtualFile)) return false;

  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  if (ProjectScope.getLibrariesScope(project).contains(virtualFile) && !fileIndex.isInContent(virtualFile)) return false;

  if (SingleRootFileViewProvider.isTooLargeForIntelligence(virtualFile)) return false;

  final HighlightingSettingsPerFile component = HighlightingSettingsPerFile.getInstance(project);
  if (component == null) return true;

  final FileHighlightingSetting settingForRoot = component.getHighlightingSettingForRoot(psiRoot);
  return settingForRoot != FileHighlightingSetting.SKIP_INSPECTION;
}
 
Example #21
Source File: FilePathRelativeToProjectRootMacro.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public String expand(final DataContext dataContext) {
  final Project project = dataContext.getData(CommonDataKeys.PROJECT);
  if (project == null) {
    return null;
  }
  VirtualFile file = dataContext.getData(PlatformDataKeys.VIRTUAL_FILE);
  if (file == null) {
    return null;
  }
  final VirtualFile contentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(file);
  if (contentRoot == null) {
    return null;
  }
  return FileUtil.getRelativePath(getIOFile(contentRoot), getIOFile(file));
}
 
Example #22
Source File: PackagesPaneSelectInTarget.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean canSelect(final VirtualFile vFile) {
  if (vFile != null && vFile.isValid()) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    return fileIndex.isInSourceContent(vFile) || isInLibraryContentOnly(vFile);
  }
  else {
    return false;
  }
}
 
Example #23
Source File: OSSSdkRefreshActionTest.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public void testRefreshSdkWhenNotSet() {
  doImport("examples/src/java/org/pantsbuild/example/hello");

  ApplicationManager.getApplication().runWriteAction(() -> {
    ProjectRootManager.getInstance(myProject).setProjectSdk(null);
  });

  refreshProjectSdk();
  Sdk sdk = ProjectRootManager.getInstance(myProject).getProjectSdk();
  assertNotEmpty(runtimeOf(sdk));
}
 
Example #24
Source File: DocumentationComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private String getLocationText() {
  PsiElement element = getElement();
  if (element != null) {
    PsiFile file = element.getContainingFile();
    VirtualFile vfile = file == null ? null : file.getVirtualFile();

    if (vfile == null) return null;

    ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
    Module module = fileIndex.getModuleForFile(vfile);

    if (module != null) {
      if (ModuleManager.getInstance(element.getProject()).getModules().length == 1) return null;
      return "<icon src='/actions/module.png'>&nbsp;" + module.getName().replace("<", "&lt;");
    }
    else {
      List<OrderEntry> entries = fileIndex.getOrderEntriesForFile(vfile);
      for (OrderEntry order : entries) {
        if (order instanceof OrderEntryWithTracking) {
          return "<icon src='AllIcons.Nodes.PpLibFolder" + "'>&nbsp;" + order.getPresentableName().replace("<", "&lt;");
        }
      }
    }
  }

  return null;
}
 
Example #25
Source File: AwesomeLinkFilter.java    From intellij-awesome-console with MIT License 5 votes vote down vote up
public AwesomeLinkFilter(final Project project) {
	this.project = project;
	this.fileCache = new HashMap<>();
	this.fileBaseCache = new HashMap<>();
	projectRootManager = ProjectRootManager.getInstance(project);
	srcRoots = getSourceRoots();
	config = AwesomeConsoleConfig.getInstance();
	fileMatcher = FILE_PATTERN.matcher("");
	urlMatcher = URL_PATTERN.matcher("");

	createFileCache();
}
 
Example #26
Source File: SdkOrLibraryWeigher.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isSdkElement(PsiElement element, @Nonnull final Project project) {
  final VirtualFile file = PsiUtilCore.getVirtualFile(element);
  if (file != null) {
    List<OrderEntry> orderEntries = ProjectRootManager.getInstance(project).getFileIndex().getOrderEntriesForFile(file);
    if (!orderEntries.isEmpty() && orderEntries.get(0) instanceof ModuleExtensionWithSdkOrderEntry) {
      return true;
    }
  }
  return false;
}
 
Example #27
Source File: AbstractFileTreeTable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void appendChildrenTo(@Nonnull final Collection<ConvenientNode> children) {
  VirtualFile[] childrenf = getObject().getChildren();
  ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
  for (VirtualFile child : childrenf) {
    if (myFilter.accept(child) && fileIndex.isInContent(child)) {
      children.add(new FileNode(child, myProject, myFilter));
    }
  }
}
 
Example #28
Source File: BaseProjectViewDirectoryHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public static Collection<AbstractTreeNode> doGetDirectoryChildren(final PsiDirectory psiDirectory, final ViewSettings settings, final boolean withSubDirectories) {
  final List<AbstractTreeNode> children = new ArrayList<>();
  final Project project = psiDirectory.getProject();
  final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  final Module module = fileIndex.getModuleForFile(psiDirectory.getVirtualFile());
  final ModuleFileIndex moduleFileIndex = module == null ? null : ModuleRootManager.getInstance(module).getFileIndex();
  if (!settings.isFlattenPackages() || skipDirectory(psiDirectory)) {
    processPsiDirectoryChildren(psiDirectory, directoryChildrenInProject(psiDirectory, settings), children, fileIndex, null, settings, withSubDirectories);
  }
  else { // source directory in "flatten packages" mode
    final PsiDirectory parentDir = psiDirectory.getParentDirectory();
    if (parentDir == null || skipDirectory(parentDir) /*|| !rootDirectoryFound(parentDir)*/ && withSubDirectories) {
      addAllSubpackages(children, psiDirectory, moduleFileIndex, settings);
    }
    PsiDirectory[] subdirs = psiDirectory.getSubdirectories();
    for (PsiDirectory subdir : subdirs) {
      if (!skipDirectory(subdir)) {
        continue;
      }
      VirtualFile directoryFile = subdir.getVirtualFile();
      if (FileTypeRegistry.getInstance().isFileIgnored(directoryFile)) continue;

      if (withSubDirectories) {
        children.add(new PsiDirectoryNode(project, subdir, settings));
      }
    }
    processPsiDirectoryChildren(psiDirectory, psiDirectory.getFiles(), children, fileIndex, moduleFileIndex, settings, withSubDirectories);
  }
  return children;
}
 
Example #29
Source File: ExtractInterfaceDialog.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
private PsiDirectory getDirUnderSameSourceRoot(final PsiDirectory[] directories) {
  final VirtualFile sourceFile = mySourceClass.getContainingFile().getVirtualFile();
  if (sourceFile != null) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(sourceFile);
    if (sourceRoot != null) {
      for (PsiDirectory dir : directories) {
        if (Comparing.equal(fileIndex.getSourceRootForFile(dir.getVirtualFile()), sourceRoot)) {
          return dir;
        }
      }
    }
  }
  return directories[0];
}
 
Example #30
Source File: PantsProjectPaneSelectInTarget.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private boolean canSelect(final VirtualFile vFile) {
  if (vFile != null && vFile.isValid()) {
    ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
    if (projectFileIndex.isInLibraryClasses(vFile) || projectFileIndex.isInLibrarySource(vFile)) {
      return true;
    }
    final Optional<VirtualFile> buildRoot = PantsUtil.findBuildRoot(myProject.getBaseDir());

    return buildRoot.isPresent() && VfsUtil.isAncestor(buildRoot.get(), vFile, false);
  }

  return false;
}