Package com.intellij.openapi.roots

Examples of com.intellij.openapi.roots.ProjectFileIndex


    final VirtualFile vFile = psiFile.getOriginalFile().getVirtualFile();
    return vFile != null && isInDartSdkOrDartPackagesFolder(psiFile.getProject(), vFile);
  }

  public static boolean isInDartSdkOrDartPackagesFolder(final @NotNull Project project, final @NotNull VirtualFile file) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();

    if (fileIndex.isInLibraryClasses(file)) {
      return true; // file in SDK or in custom package root
    }

    if (fileIndex.isExcluded(file) || (fileIndex.isInContent(file) && isInDartPackagesFolder(fileIndex, file))) {
      return true; // symlinked child of 'packages' folder. Real location is in user cache folder for Dart packages, not in project
    }

    return false;
  }
View Full Code Here


    return VfsUtilCore.getRelativePath(file, root, '/');
  }

  @Nullable
  private static VirtualFile getRootForFile(final VirtualFile file, final ConvertContext context) {
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(context.getPsiManager().getProject()).getFileIndex();
    VirtualFile root = projectFileIndex.getSourceRootForFile(file);

    if (root == null) {
      root = projectFileIndex.getContentRootForFile(file);
    }

    return root;
  }
View Full Code Here

            for (Object key : data.getClasses().keySet()) {
              if (key instanceof String) {
                String path = (String) key;
                VirtualFile file = VfsUtil.findFileByIoFile(new File(path), false);
                if (file != null && file.isValid()) {
                  ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
                  VirtualFile contentRoot = projectFileIndex.getContentRootForFile(file);
                  if (contentRoot != null && contentRoot.isDirectory() && contentRoot.isValid()) {
                    return contentRoot;
                  }
                }
              }
View Full Code Here

  private static final Key<Pair<Long, Map<String, Object>>> MOD_STAMP_TO_PUBSPEC_NAME = Key.create("MOD_STAMP_TO_PUBSPEC_NAME");

  @Nullable
  public static VirtualFile findPubspecYamlFile(@NotNull final Project project, @NotNull final VirtualFile contextFile) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    VirtualFile parent = contextFile;
    while ((parent = parent.getParent()) != null && fileIndex.isInContent(parent)) {
      final VirtualFile file = parent.findChild(PUBSPEC_YAML);
      if (file != null && !file.isDirectory()) return file;
    }

    return null;
View Full Code Here

  public Icon getIcon(@NotNull final PsiElement element, @Iconable.IconFlags final int flags) {
    if (element instanceof PsiDirectory) {
      final VirtualFile folder = ((PsiDirectory)element).getVirtualFile();

      if (isFolderNearPubspecYaml(folder, "build")) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
        return fileIndex.isExcluded(folder) ? AllIcons.Modules.ExcludedGeneratedRoot
                                            : AllIcons.Modules.GeneratedFolder;
      }
      if (isFolderNearPubspecYaml(folder, "web")) return AllIcons.Nodes.WebFolder;
      if (isFolderNearPubspecYaml(folder, "test")) return AllIcons.Modules.TestSourceFolder;
      if (isFolderNearPubspecYaml(folder, "packages")) return DartIcons.Package_root;
      if (isFolderNearPubspecYaml(folder.getParent(), "packages")) {
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
        return fileIndex.isExcluded(folder) ? EXCLUDED_FOLDER_SYMLINK_ICON
                                            : FOLDER_SYMLINK_ICON;
      }
    }

    return null;
View Full Code Here

    }
  }

  private static THashSet<String> collectFoldersToExclude(final Module module, final VirtualFile pubspecYamlFile) {
    final THashSet<String> newExcludedPackagesUrls = new THashSet<String>();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final VirtualFile root = pubspecYamlFile.getParent();

    // java.io.File is used here because exclusion is done before FS refresh (in order not to trigger indexing of files that are going to be excluded)
    final File pubFolder = new File(root.getPath() + "/.pub");
    if (pubFolder.isDirectory() || ApplicationManager.getApplication().isUnitTestMode() && root.findChild(".pub") != null) {
      newExcludedPackagesUrls.add(root.getUrl() + "/.pub");
    }

    final File buildFolder = new File(root.getPath() + "/build");
    if (buildFolder.isDirectory() || ApplicationManager.getApplication().isUnitTestMode() && root.findChild("build") != null) {
      newExcludedPackagesUrls.add(root.getUrl() + "/build");
    }

    final VirtualFile binFolder = root.findChild("bin");
    if (binFolder != null && binFolder.isDirectory() && fileIndex.isInContent(binFolder)) {
      newExcludedPackagesUrls.add(binFolder.getUrl() + "/packages");
    }

    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("benchmark"), fileIndex);
    appendPackagesFolders(newExcludedPackagesUrls, root.findChild("example"), fileIndex);
View Full Code Here

    private final Module myModule;

    private JarFileScope(@NotNull VirtualFile file) {
      super();
      myVirtualFile = file;
      ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
      myModule = myVirtualFile != null ? fileIndex.getModuleForFile(myVirtualFile) : null;
    }
View Full Code Here

    PsiFile featureFile = step.getContainingFile();
    if (featureFile != null) {
      PsiDirectory psiDirectory = featureFile.getContainingDirectory();
      final Project project = step.getProject();
      if (psiDirectory != null) {
        ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        VirtualFile directory = psiDirectory.getVirtualFile();
        if (projectFileIndex.isInContent(directory)) {
          VirtualFile sourceRoot = projectFileIndex.getSourceRootForFile(directory);
          //noinspection ConstantConditions
          final Module module = projectFileIndex.getModuleForFile(featureFile.getVirtualFile());
          if (module != null) {
            final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
            if (sourceRoot != null && sourceRoot.getName().equals("resources")) {
              final VirtualFile resourceParent = sourceRoot.getParent();
              for (VirtualFile vFile : sourceRoots) {
View Full Code Here

      @Nullable
      public VirtualFile compute() {
        Project project = psiFileRequestor.getProject();
        VirtualFile virtualFile = psiFileRequestor.getVirtualFile();
        if (virtualFile != null) {
          ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
          VirtualFile contentRoot = fileIndex.getContentRootForFile(virtualFile);
          if (contentRoot != null) {
            return contentRoot;
          }
        }
        return project.getBaseDir();
View Full Code Here

      }
    };
  }

  private static boolean isVirtualFileUnderSourceRoot(VirtualFile virtualFile, Project project) {
    ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex();
    if (virtualFile == null || index.getContentRootForFile(virtualFile) == null) {
      return false;
    }
    return true;
  }
View Full Code Here

TOP

Related Classes of com.intellij.openapi.roots.ProjectFileIndex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.