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


Java ModuleRootManager.getInstance方法代码示例

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


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

示例1: getDirectClassPaths

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static List<String> getDirectClassPaths( Module ijModule )
{
  final ModuleRootManager rootManager = ModuleRootManager.getInstance( ijModule );
  final List<OrderEntry> orderEntries = Arrays.asList( rootManager.getOrderEntries() );

  List<String> paths = new ArrayList<>();
  for( OrderEntry entry : orderEntries.stream().filter( (LibraryOrderEntry.class)::isInstance ).collect( Collectors.toList() ) )
  {
    final Library lib = ((LibraryOrderEntry)entry).getLibrary();
    if( lib != null )
    {
      for( VirtualFile virtualFile : lib.getFiles( OrderRootType.CLASSES ) )
      {
        final File file = new File( stripExtraCharacters( virtualFile.getPath() ) );
        if( file.exists() )
        {
          paths.add( file.getAbsolutePath() );
        }
      }
    }
  }
  return paths;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:24,代码来源:ManProject.java

示例2: dependencyChainContains

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static boolean dependencyChainContains( Module ijModule, String path, List<Module> visited )
{
  if( !visited.contains( ijModule ) )
  {
    visited.add( ijModule );

    ModuleRootManager rootManager = ModuleRootManager.getInstance( ijModule );
    for( Module dep : rootManager.getDependencies() )
    {
      if( getDirectClassPaths( dep ).contains( path ) || dependencyChainContains( dep, path, visited ) )
      {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:18,代码来源:ManProject.java

示例3: getNonEmptySourceTypes

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static Set<NonAndroidSourceType> getNonEmptySourceTypes(Module module) {
  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  Set<NonAndroidSourceType> sourceTypes = Sets.newHashSetWithExpectedSize(NonAndroidSourceType.values().length);

  ContentEntry[] contentEntries = rootManager.getContentEntries();
  for (ContentEntry entry : contentEntries) {
    for (NonAndroidSourceType type : NonAndroidSourceType.values()) {
      for (SourceFolder sourceFolder : entry.getSourceFolders(type.rootType)) {
        if (sourceFolder.getFile() != null) {
          sourceTypes.add(type);
          break;
        }
      }
    }
  }

  return sourceTypes;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:NonAndroidModuleNode.java

示例4: getSelectedDirectoriesInAmbiguousCase

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
@NotNull
protected PsiDirectory[] getSelectedDirectoriesInAmbiguousCase(@NotNull final DefaultMutableTreeNode node) {
  final Object userObject = node.getUserObject();
  if (userObject instanceof AbstractModuleNode) {
    final Module module = ((AbstractModuleNode)userObject).getValue();
    if (module != null) {
      final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
      final VirtualFile[] sourceRoots = moduleRootManager.getSourceRoots();
      List<PsiDirectory> dirs = new ArrayList<PsiDirectory>(sourceRoots.length);
      final PsiManager psiManager = PsiManager.getInstance(myProject);
      for (final VirtualFile sourceRoot : sourceRoots) {
        final PsiDirectory directory = psiManager.findDirectory(sourceRoot);
        if (directory != null) {
          dirs.add(directory);
        }
      }
      return dirs.toArray(new PsiDirectory[dirs.size()]);
    }
  }
  return PsiDirectory.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:AbstractProjectViewPane.java

示例5: getState

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException {
  final Module module = getModule();
  if (module == null) {
    throw new ExecutionException("Module is not specified");
  }

  if (!isSupport(module)) {
    throw new ExecutionException(getNoSdkMessage());
  }

  final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
  final Sdk sdk = rootManager.getSdk();
  if (sdk == null || !(sdk.getSdkType() instanceof JavaSdkType)) {
    throw CantRunException.noJdkForModule(module);
  }

  return createCommandLineState(environment, module);

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:MvcRunConfiguration.java

示例6: getSourceFolders

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private List<VirtualFile> getSourceFolders() {
  ModuleRootManager rootManager = ModuleRootManager.getInstance(getValue());
  List<VirtualFile> folders = Lists.newArrayList();

  ContentEntry[] contentEntries = rootManager.getContentEntries();
  for (ContentEntry entry : contentEntries) {
    List<SourceFolder> sources = entry.getSourceFolders(mySourceType.rootType);
    for (SourceFolder folder : sources) {
      VirtualFile file = folder.getFile();
      if (file != null) {
        folders.add(file);
      }
    }
  }

  return folders;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:NonAndroidSourceTypeNode.java

示例7: getPotentialRoots

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static List<VirtualFile> getPotentialRoots(Module module, PsiDirectory[] dirs) {
  if (dirs.length != 0) {
    final List<VirtualFile> result = new ArrayList<VirtualFile>();
    for (PsiDirectory dir : dirs) {
      final PsiDirectory parent = dir.getParentDirectory();
      if (parent != null) result.add(parent.getVirtualFile());
    }
    return result;
  }
  else {
    ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    List<VirtualFile> resourceRoots = rootManager.getSourceRoots(JavaResourceRootType.RESOURCE);
    if (!resourceRoots.isEmpty()) {
      return resourceRoots;
    }
    return rootManager.getSourceRoots(JavaModuleSourceRootTypes.SOURCES);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:CreateHtmlDescriptionFix.java

示例8: getSourceRoots

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
public static List<VirtualFile> getSourceRoots( Module ijModule )
{
  final ModuleRootManager moduleManager = ModuleRootManager.getInstance( ijModule );
  final List<VirtualFile> sourcePaths = new ArrayList<>();
  List<VirtualFile> excludeRoots = Arrays.asList( moduleManager.getExcludeRoots() );
  for( VirtualFile sourceRoot : moduleManager.getSourceRoots() )
  {
    if( !excludeRoots.contains( sourceRoot ) )
    {
      sourcePaths.add( sourceRoot );
    }
  }

  return sourcePaths;
}
 
开发者ID:manifold-systems,项目名称:manifold-ij,代码行数:16,代码来源:ManProject.java

示例9: configureJdk

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static void configureJdk(Element cfg, @NotNull Module module) {
  String jdkName = cfg.getChildTextTrim("jdkName");
  if (StringUtil.isEmptyOrSpaces(jdkName)) return;

  ModuleRootManager rootManager = ModuleRootManager.getInstance(module);

  String currentSdkName = null;
  Sdk sdk = rootManager.getSdk();
  if (sdk != null) {
    currentSdkName = sdk.getName();
  }

  if (!jdkName.equals(currentSdkName)) {
    ModifiableRootModel model = rootManager.getModifiableModel();

    if (jdkName.equals(ProjectRootManager.getInstance(model.getProject()).getProjectSdkName())) {
      model.inheritSdk();
    }
    else {
      Sdk jdk = ProjectJdkTable.getInstance().findJdk(jdkName);
      if (jdk != null) {
        model.setSdk(jdk);
      }
      else {
        model.setInvalidSdk(jdkName, JavaSdk.getInstance().getName());
      }
    }

    model.commit();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:MavenIdeaPluginConfigurer.java

示例10: getSdk

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
@Nullable
private Sdk getSdk() {
  if (myModule == null) {
    return ProjectRootManager.getInstance(myProject).getProjectSdk();
  }
  final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
  return rootManager.getSdk();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:PyActiveSdkConfigurable.java

示例11: testTest1

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
public void testTest1() {
  final String rootPath = PathManagerEx.getTestDataPath() + "/moduleRootManager/roots/" + "test1";
  final VirtualFile[] rootFileBox = new VirtualFile[1];
  ApplicationManager.getApplication().runWriteAction(() -> {
    rootFileBox[0] =
    LocalFileSystem.getInstance().refreshAndFindFileByPath(rootPath.replace(File.separatorChar, '/'));
  });
  final VirtualFile rootFile = rootFileBox[0];
  final VirtualFile classesFile = rootFile.findChild("classes");
  assertNotNull(classesFile);
  final VirtualFile childOfContent = rootFile.findChild("x.txt");
  assertNotNull(childOfContent);
  final VirtualFile childOfClasses = classesFile.findChild("y.txt");
  assertNotNull(childOfClasses);

  final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);


  PsiTestUtil.addContentRoot(myModule, rootFile);
  PsiTestUtil.setCompilerOutputPath(myModule, classesFile.getUrl(), false);
  PsiTestUtil.setExcludeCompileOutput(myModule, false);
  assertTrue(rootManager.getFileIndex().isInContent(childOfContent));
  assertTrue(rootManager.getFileIndex().isInContent(childOfClasses));

  PsiTestUtil.setExcludeCompileOutput(myModule, true);
  assertTrue(rootManager.getFileIndex().isInContent(childOfContent));
  assertFalse(rootManager.getFileIndex().isInContent(childOfClasses));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:RootsTest.java

示例12: getSourceFolderRelativePaths

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
  final Set<String> paths = Sets.newHashSet();

  Module module = getModule(moduleName);
  final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);

  execute(new GuiTask() {
    @Override
    protected void executeInEDT() throws Throwable {
      ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
      try {
        for (ContentEntry contentEntry : rootModel.getContentEntries()) {
          for (SourceFolder folder : contentEntry.getSourceFolders()) {
            JpsModuleSourceRootType<?> rootType = folder.getRootType();
            if (rootType.equals(sourceType)) {
              String path = urlToPath(folder.getUrl());
              String relativePath = getRelativePath(myProjectPath, new File(toSystemDependentName(path)));
              paths.add(relativePath);
            }
          }
        }
      }
      finally {
        rootModel.dispose();
      }
    }
  });

  return paths;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:IdeFrameFixture.java

示例13: initModule

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
protected void initModule(Module module) {
    final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
    final ModifiableRootModel rootModel = rootManager.getModifiableModel();

    for (String contentRoot : myContentRoots) {
      final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(contentRoot);
      Assert.assertNotNull("cannot find content root: " + contentRoot, virtualFile);
      final ContentEntry contentEntry = rootModel.addContentEntry(virtualFile);

      for (String sourceRoot: mySourceRoots) {
        String s = contentRoot + "/" + sourceRoot;
        VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByPath(s);
        if (vf == null) {
          final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(sourceRoot);
          if (file != null && VfsUtilCore.isAncestor(virtualFile, file, false)) vf = file;
        }
//        assert vf != null : "cannot find source root: " + sourceRoot;
        if (vf != null) {
          contentEntry.addSourceFolder(vf, false);
        }
        else {
          // files are not created yet
          contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(s), false);
        }
      }
    }
    setupRootModel(rootModel);
    rootModel.commit();
  }
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:ModuleFixtureBuilderImpl.java

示例14: testInheritJdkFromProject

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
public void testInheritJdkFromProject() throws Exception {
  if (!hasMavenInstallation()) return;

  createNewModule(new MavenId("org.foo", "module", "1.0"));
  ModuleRootManager manager = ModuleRootManager.getInstance(getModule("module"));
  assertTrue(manager.isSdkInherited());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:MavenModuleBuilderTest.java

示例15: doGenerate

import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static <T> void doGenerate(@NotNull WebProjectTemplate<T> template, @NotNull Module module) {
  WebProjectGenerator.GeneratorPeer<T> peer = template.getPeer();
  ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
  VirtualFile[] contentRoots = moduleRootManager.getContentRoots();
  VirtualFile dir = module.getProject().getBaseDir();
  if (contentRoots.length > 0 && contentRoots[0] != null) {
    dir = contentRoots[0];
  }
  template.generateProject(module.getProject(), dir, peer.getSettings(), module);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:WebModuleBuilder.java


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