com.intellij.psi.search.GlobalSearchScopes#com.intellij.openapi.roots.ProjectRootManager源码实例Demo

下面列出了com.intellij.psi.search.GlobalSearchScopes#com.intellij.openapi.roots.ProjectRootManager 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: consulo   文件: ProjectLocatorImpl.java
@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;
}
 
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);
                                }
                            }
                        }
                    });
                }
            });
}
 
源代码3 项目: consulo   文件: ForwardDependenciesBuilder.java
@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();
  }
}
 
源代码4 项目: consulo   文件: ModuleVcsPathPresenter.java
@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();
    }
  });
}
 
源代码5 项目: RIBs   文件: GenerateAction.java
/**
 * 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;
}
 
源代码6 项目: consulo   文件: TodoDirNode.java
@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);
}
 
源代码7 项目: consulo   文件: CopyReferenceAction.java
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();
}
 
源代码8 项目: consulo   文件: ProjectViewPane.java
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);
}
 
@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));
}
 
源代码10 项目: flutter-intellij   文件: Workspace.java
/**
 * 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);
}
 
源代码11 项目: consulo   文件: ProjectScopeBuilderImpl.java
@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));
    }
  };
}
 
源代码12 项目: consulo   文件: TodoTreeBuilder.java
/**
 * @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();
}
 
源代码13 项目: consulo   文件: ResourceFileUtil.java
@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;
}
 
源代码14 项目: consulo   文件: HighlightLevelUtil.java
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;
}
 
@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));
}
 
源代码16 项目: consulo   文件: CompileContextImpl.java
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();
}
 
源代码17 项目: consulo   文件: SimpleCoverageAnnotator.java
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));
}
 
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());
}
 
@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());
  }
}
 
源代码20 项目: consulo   文件: HighlightingSettingsPerFile.java
@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;
}
 
源代码21 项目: markdown-doclet   文件: DocCommentProcessor.java
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();
        }
    }
}
 
源代码22 项目: consulo   文件: VcsRootDetectorImpl.java
@Inject
public VcsRootDetectorImpl(@Nonnull Project project,
                           @Nonnull ProjectRootManager projectRootManager,
                           @Nonnull ProjectLevelVcsManager projectLevelVcsManager) {
  myProject = project;
  myProjectManager = projectRootManager;
  myVcsManager = projectLevelVcsManager;
  myCheckers = VcsRootChecker.EXTENSION_POINT_NAME.getExtensionList();
}
 
源代码23 项目: NutzCodeInsight   文件: SqlsXmlUtil.java
public static GlobalSearchScope getSearchScope(Project project, @NotNull PsiElement element) {
    GlobalSearchScope searchScope = GlobalSearchScope.projectScope(project);
    Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(element.getContainingFile().getVirtualFile());
    if (module != null) {
        searchScope = GlobalSearchScope.moduleScope(module);
    }
    return searchScope;
}
 
源代码24 项目: consulo   文件: FileTreeModelBuilder.java
public FileTreeModelBuilder(Project project, Marker marker, DependenciesPanel.DependencyPanelSettings settings) {
  myProject = project;
  myBaseDir = myProject.getBaseDir();
  myContentRoots = ProjectRootManager.getInstance(myProject).getContentRoots();
  final boolean multiModuleProject = ModuleManager.getInstance(myProject).getModules().length > 1;
  myShowModules = settings.UI_SHOW_MODULES && multiModuleProject;
  myFlattenPackages = settings.UI_FLATTEN_PACKAGES;
  myCompactEmptyMiddlePackages = settings.UI_COMPACT_EMPTY_MIDDLE_PACKAGES;
  myShowFiles = settings.UI_SHOW_FILES;
  myShowModuleGroups = settings.UI_SHOW_MODULE_GROUPS && multiModuleProject;
  myMarker = marker;
  myAddUnmarkedFiles = !settings.UI_FILTER_LEGALS;
  myRoot = new RootNode(myProject);
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
}
 
@Override
    public void actionPerformed(AnActionEvent anActionEvent)
    {
        final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(anActionEvent.getDataContext());
        final Project project = anActionEvent.getProject();
        final VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(file);
        String appPath = moduleContentRoot.getPath() + File.separator + MuleConfigUtils.CONFIG_RELATIVE_PATH;

        logger.debug("*** APP PATH IS " + appPath);

        final File appDir = new File(appPath);

        logger.debug("*** APP DIR IS DIRECTORY = " + appDir.isDirectory());

        final List<File> ramlFiles = new ArrayList<File>();
        final File ramlFile = new File(file.getPath());
        ramlFiles.add(ramlFile);

//TODO - list all RAML files in the project and add them too?
//        Collection<VirtualFile> ramlFilesInProject = FilenameIndex.getAllFilesByExt(project, "raml", GlobalSearchScope.projectScope(project));
//        for (VirtualFile vFile : ramlFilesInProject) {
//            ramlFiles.add(new File(vFile.getPath()));
//        }

        //TODO - go through the list of modules and see if any one of them is a Mule domain
//                if (MuleConfigUtils.isMuleDomainModule(module))

        try
        {
            //TODO Mule version should be derived from Maven project?
            new IdeaScaffolderAPI().execute(ramlFiles, appDir, null, "3.8");
        } catch (RuntimeException e) {
            logger.error("FINALLY CAUGHT RAML ERROR! ", e);
        }
        finally
        {
            file.getParent().getParent().refresh(false, true);
        }
    }
 
源代码26 项目: consulo   文件: DuplicatesInspectionBase.java
DuplicatedCodeProcessor(VirtualFile file, Project project, boolean skipGeneratedCode) {
  virtualFile = file;
  this.project = project;
  myFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
  mySkipGeneratedCode = skipGeneratedCode;
  myFileWithinGeneratedCode = skipGeneratedCode && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project);
}
 
源代码27 项目: mule-intellij-plugins   文件: MuleSchemaProvider.java
@Nullable
@Override
public CachedValueProvider.Result<Map<String, String>> compute(Module module) {
    try {
        ArrayList<Object> dependencies = new ArrayList<Object>();
        dependencies.add(ProjectRootManager.getInstance(module.getProject()));
        Map<String, String> schemas = getSchemasFromSpringSchemas(module);
        return CachedValueProvider.Result.create(schemas, dependencies);
    } catch (Exception e) {
        return null;
    }
}
 
源代码28 项目: consulo   文件: DirectoryChooserUtil.java
@Nullable
public static PsiDirectory selectDirectory(Project project,
                                           PsiDirectory[] packageDirectories,
                                           PsiDirectory defaultDirectory,
                                           String postfixToShow) {
  ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();

  ArrayList<PsiDirectory> possibleDirs = new ArrayList<PsiDirectory>();
  for (PsiDirectory dir : packageDirectories) {
    if (!dir.isValid()) continue;
    if (!dir.isWritable()) continue;
    if (possibleDirs.contains(dir)) continue;
    if (!projectFileIndex.isInContent(dir.getVirtualFile())) continue;
    possibleDirs.add(dir);
  }

  if (possibleDirs.isEmpty()) return null;
  if (possibleDirs.size() == 1) return possibleDirs.get(0);

  if (ApplicationManager.getApplication().isUnitTestMode()) return possibleDirs.get(0);

  DirectoryChooser chooser = new DirectoryChooser(project);
  chooser.setTitle(IdeBundle.message("title.choose.destination.directory"));
  chooser.fillList(possibleDirs.toArray(new PsiDirectory[possibleDirs.size()]), defaultDirectory, project, postfixToShow);
  chooser.show();
  return chooser.isOK() ? chooser.getSelectedDirectory() : null;
}
 
源代码29 项目: flutter-intellij   文件: FlutterInitializer.java
/**
 * Automatically set Android SDK based on ANDROID_HOME.
 */
private void ensureAndroidSdk(@NotNull Project project) {
  if (ProjectRootManager.getInstance(project).getProjectSdk() != null) {
    return; // Don't override user's settings.
  }

  final IntelliJAndroidSdk wanted = IntelliJAndroidSdk.fromEnvironment();
  if (wanted == null) {
    return; // ANDROID_HOME not set or Android SDK not created in IDEA; not clear what to do.
  }

  ApplicationManager.getApplication().runWriteAction(() -> wanted.setCurrent(project));
}
 
源代码30 项目: consulo   文件: DumpDirectoryInfoAction.java
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  final DirectoryIndex index = DirectoryIndex.getInstance(project);
  if (project != null) {
    final VirtualFile root = e.getData(PlatformDataKeys.VIRTUAL_FILE);
    ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
      @Override
      public void run() {
        final ContentIterator contentIterator = new ContentIterator() {
          @Override
          public boolean processFile(VirtualFile fileOrDir) {
            LOG.info(fileOrDir.getPath());

            final DirectoryInfo directoryInfo = index.getInfoForDirectory(fileOrDir);
            if (directoryInfo != null) {
              LOG.info(directoryInfo.toString());
            }
            return true;
          }
        };
        if (root != null) {
          ProjectRootManager.getInstance(project).getFileIndex().iterateContentUnderDirectory(root, contentIterator);
        } else {
          ProjectRootManager.getInstance(project).getFileIndex().iterateContent(contentIterator);
        }
      }
    }, "Dumping directory index", true, project);
  }
}