本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
}
示例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();
}
示例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));
}
示例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;
}
示例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();
}
示例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());
}
示例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);
}