当前位置: 首页>>代码示例>>Java>>正文


Java ProjectRootManager.getInstance方法代码示例

本文整理汇总了Java中com.intellij.openapi.roots.ProjectRootManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ProjectRootManager.getInstance方法的具体用法?Java ProjectRootManager.getInstance怎么用?Java ProjectRootManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.roots.ProjectRootManager的用法示例。


在下文中一共展示了ProjectRootManager.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAvailable

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@CheckReturnValue
@VisibleForTesting
@SuppressWarnings("WeakerAccess")
static boolean isAvailable(@Nonnull AnActionEvent event) {
    final Project project = event.getProject();
    if (project == null) {
        return false;
    }

    final IdeView view = event.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        return false;
    }

    final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    final ProjectFileIndex fileIndex = rootManager.getFileIndex();
    final Optional<PsiDirectory> sourceDirectory = Stream.of(view.getDirectories())
            .filter(directory -> {
                final VirtualFile virtualFile = directory.getVirtualFile();
                return fileIndex.isUnderSourceRootOfType(virtualFile, JavaModuleSourceRootTypes.SOURCES);
            })
            .findFirst();
    return sourceDirectory.isPresent();
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:25,代码来源:NewClassAction.java

示例2: selectSdk

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
private void selectSdk(@NotNull final Project project) {
    Validate.notNull(project);

    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);

    final Sdk projectSdk = projectRootManager.getProjectSdk();

    if (null == projectSdk) {
        return;
    }

    if (StringUtils.isNotBlank(projectSdk.getVersionString())) {
        final JavaSdkVersion sdkVersion = JdkVersionUtil.getVersion(projectSdk.getVersionString());
        final LanguageLevelProjectExtension languageLevelExt = LanguageLevelProjectExtension.getInstance(project);

        if (sdkVersion.getMaxLanguageLevel() != languageLevelExt.getLanguageLevel()) {
            languageLevelExt.setLanguageLevel(sdkVersion.getMaxLanguageLevel());
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:21,代码来源:ImportProjectProgressModalWindow.java

示例3: testAddExcludeRoot

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public void testAddExcludeRoot() throws Exception{
  PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to initialize caches

  ProjectRootManagerEx rootManager = (ProjectRootManagerEx)ProjectRootManager.getInstance(myProject);
  final VirtualFile root = rootManager.getContentRoots()[0];

  final VirtualFile dir = root.findChild("aDir");

  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      VirtualFile newFile = dir.createChildData(null, "New.java");
      VfsUtil.saveText(newFile, "class A{ Exception e;} //todo");
    }
  }.execute().throwException();

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  PsiTestUtil.addExcludedRoot(myModule, dir);

  PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception",GlobalSearchScope.allScope(getProject()));
  assertNotNull(exceptionClass);
  checkUsages(exceptionClass, new String[]{"1.java"});
  checkTodos(new String[]{});
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:UpdateCacheTest.java

示例4: testSCR6066

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public void testSCR6066() throws Exception{
  ProjectRootManagerEx rootManager = (ProjectRootManagerEx)ProjectRootManager.getInstance(myProject);
  final VirtualFile root = rootManager.getContentRoots()[0];

  PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to initialize caches

  new WriteCommandAction.Simple(getProject()) {
    @Override
    protected void run() throws Throwable {
      VirtualFile newFile = root.createChildData(null, "New.java");
      VfsUtil.saveText(newFile, "class A{ Exception e;} //todo");
    }
  }.execute().throwException();

  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  PsiTodoSearchHelper.SERVICE.getInstance(myProject).findFilesWithTodoItems(); // to update caches

  PsiTestUtil.addExcludedRoot(myModule, root);

  PsiClass exceptionClass = myJavaFacade.findClass("java.lang.Exception", GlobalSearchScope.allScope(getProject()));
  assertNotNull(exceptionClass);
  checkUsages(exceptionClass, new String[]{});
  checkTodos(new String[]{});
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:UpdateCacheTest.java

示例5: getPathRelativeToModule

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@Nullable
private static String getPathRelativeToModule(VirtualFile file, Project project) {
  final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
  final Application application = ApplicationManager.getApplication();
  final VirtualFile[] contentRoots = application.runReadAction(
    new Computable<VirtualFile[]>() {
      @Override
      public VirtualFile[] compute() {
        return rootManager.getContentRootsFromAllModules();
      }
    });
  for (VirtualFile otherRoot : contentRoots) {
    if (VfsUtilCore.isAncestor(otherRoot, file, false)) {
      return VfsUtilCore.getRelativePath(file, otherRoot, '/');
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:EmptyDirectoryInspection.java

示例6: findSdkForNonModuleFile

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
  Project project = psiFile.getProject();
  Sdk sdk = null;
  final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
  if (vfile != null) { // reality
    final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
    sdk = projectRootManager.getProjectSdk();
    if (sdk == null) {
      final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
      for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof JdkOrderEntry) {
          sdk = ((JdkOrderEntry)orderEntry).getJdk();
        }
        else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
          sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
        }
      }
    }
  }
  return sdk;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:PyBuiltinCache.java

示例7: findFiles

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
private Set<VirtualFile> findFiles(VirtualFile file) {
    Set<VirtualFile> files = new HashSet<VirtualFile>(0);
    Project project = thumbnailView.getProject();
    if (!project.isDisposed()) {
        ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
        boolean projectIgnored = rootManager.getFileIndex().isExcluded(file);

        if (!projectIgnored && !FileTypeManager.getInstance().isFileIgnored(file)) {
            ImageFileTypeManager typeManager = ImageFileTypeManager.getInstance();
            if (file.isDirectory()) {
                if (thumbnailView.isRecursive()) {
                    files.addAll(findFiles(file.getChildren()));
                } else if (isImagesInDirectory(file)) {
                    files.add(file);
                }
            } else if (typeManager.isImage(file)) {
                files.add(file);
            }
        }
    }
    return files;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ThumbnailViewUI.java

示例8: isUnderTestSources

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
private static boolean isUnderTestSources(PsiElement e) {
  final ProjectRootManager rootManager =
    ProjectRootManager.getInstance(e.getProject());
  final VirtualFile file = e.getContainingFile().getVirtualFile();
  return file != null &&
         rootManager.getFileIndex().isInTestSourceContent(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:ElementOnlyUsedFromTestCodeInspection.java

示例9: buildAllScope

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@NotNull
@Override
public GlobalSearchScope buildAllScope() {
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
  if (projectRootManager == null) return new EverythingGlobalScope(myProject);

  boolean searchOutsideRootModel = false;
  for (SearchScopeEnlarger each : Extensions.getExtensions(SearchScopeEnlarger.EXTENSION)) {
    searchOutsideRootModel = each.allScopeSearchesOutsideRootModel(myProject);
    if (searchOutsideRootModel) break;
  }

  return new ProjectAndLibrariesScope(myProject, searchOutsideRootModel);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ProjectScopeBuilderImpl.java

示例10: buildProjectScope

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@NotNull
@Override
public GlobalSearchScope buildProjectScope() {
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);
  if (projectRootManager == null) {
    return new EverythingGlobalScope(myProject) {
      @Override
      public boolean isSearchInLibraries() {
        return false;
      }
    };
  }
  return new ProjectScopeImpl(myProject, FileIndexFacade.getInstance(myProject));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:ProjectScopeBuilderImpl.java

示例11: getPackage

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public static String getPackage(@NotNull PsiDirectory directory) {
  final VirtualFile virtualFile = directory.getVirtualFile();
  final Project project = directory.getProject();
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
  final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
  return fileIndex.getPackageNameByDirectory(virtualFile);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:PackageDotHtmlMayBePackageInfoInspectionBase.java

示例12: currentProjectFolder

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
private String currentProjectFolder() {
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(myProject);

  final VirtualFile[] roots = projectRootManager.getContentRoots();
  if (roots.length == 1) {
    roots[0].getCanonicalPath();
  }
  final VirtualFile baseDir = myProject.getBaseDir();
  return baseDir == null ? null : baseDir.getCanonicalPath();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:LocalTerminalDirectRunner.java

示例13: getTopLevelRoots

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public List<VirtualFile> getTopLevelRoots() {
  List<VirtualFile> topLevelContentRoots = new ArrayList<VirtualFile>();
  ProjectRootManager prm = ProjectRootManager.getInstance(myProject);
  ProjectFileIndex index = prm.getFileIndex();

  for (VirtualFile root : prm.getContentRoots()) {
    VirtualFile parent = root.getParent();
    if (parent == null || !index.isInContent(parent)) {
      topLevelContentRoots.add(root);
    }
  }
  return topLevelContentRoots;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:ProjectViewDirectoryHelper.java

示例14: getImportPriority

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
@NotNull
public static ImportPriority getImportPriority(@NotNull PsiElement importLocation, @NotNull PsiFileSystemItem toImport) {
  final VirtualFile vFile = toImport.getVirtualFile();
  if (vFile == null) {
    return ImportPriority.THIRD_PARTY;
  }
  final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(toImport.getProject());
  if (projectRootManager.getFileIndex().isInContent(vFile)) {
    return ImportPriority.PROJECT;
  }
  final Module module = ModuleUtilCore.findModuleForPsiElement(importLocation);
  final Sdk pythonSdk = module != null ? PythonSdkType.findPythonSdk(module) : projectRootManager.getProjectSdk();

  return PythonSdkType.isStdLib(vFile, pythonSdk) ? ImportPriority.BUILTIN : ImportPriority.THIRD_PARTY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:AddImportHelper.java

示例15: ConsoleErrorInputFilter

import com.intellij.openapi.roots.ProjectRootManager; //导入方法依赖的package包/类
public ConsoleErrorInputFilter(final Project project) {
    this.project = project;
    projectRootManager = ProjectRootManager.getInstance(project);
    errorStack = "";
    createFileCache();
}
 
开发者ID:chakki-works,项目名称:watchMe,代码行数:7,代码来源:ConsoleErrorInputFilter.java


注:本文中的com.intellij.openapi.roots.ProjectRootManager.getInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。