本文整理汇总了Java中com.intellij.openapi.roots.ModuleRootManager.getSourceRoots方法的典型用法代码示例。如果您正苦于以下问题:Java ModuleRootManager.getSourceRoots方法的具体用法?Java ModuleRootManager.getSourceRoots怎么用?Java ModuleRootManager.getSourceRoots使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.roots.ModuleRootManager
的用法示例。
在下文中一共展示了ModuleRootManager.getSourceRoots方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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;
}
示例4: hasChanges
import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
/**
* Allows to answer if any file that belongs to the given module has changes in comparison with VCS.
*
* @param module target module to check
* @return <code>true</code> if any file that belongs to the given module has changes in comparison with VCS
* <code>false</code> otherwise
*/
public static boolean hasChanges(@NotNull Module module) {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
for (VirtualFile root : rootManager.getSourceRoots()) {
if (hasChanges(root, module.getProject())) {
return true;
}
}
return false;
}
示例5: actionPerformed
import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
Module module = myContext.getModule();
final VirtualFile[] contentRoots = ModuleRootManager.getInstance(module).getContentRoots();
if (contentRoots.length == 0) {
return;
}
VirtualFile initialFile = null;
String path = myTextField.getText().trim();
if (path.length() == 0) {
path = myDefaultPath;
}
if (path != null) {
initialFile = LocalFileSystem.getInstance().findFileByPath(path);
}
if (initialFile == null) {
ModuleRootManager manager = ModuleRootManager.getInstance(module);
VirtualFile[] sourceRoots = manager.getSourceRoots();
if (sourceRoots.length > 0) {
initialFile = sourceRoots[0];
}
else {
initialFile = module.getModuleFile();
if (initialFile == null) {
String p = AndroidRootUtil.getModuleDirPath(myContext.getModule());
if (p != null) {
initialFile = LocalFileSystem.getInstance().findFileByPath(p);
}
}
}
}
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
descriptor.setRoots(contentRoots);
VirtualFile file = FileChooser.chooseFile(descriptor, myContentPanel, myContext.getProject(), initialFile);
if (file != null) {
myTextField.setText(FileUtil.toSystemDependentName(file.getPath()));
}
}
示例6: hasCustomCompile
import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public boolean hasCustomCompile(ModuleChunk chunk) {
for (Module m : chunk.getModules()) {
if (LibrariesUtil.hasGroovySdk(m)) {
final Set<String> scriptExtensions = GroovyFileTypeLoader.getCustomGroovyScriptExtensions();
final ContentIterator groovyFileSearcher = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
ProgressManager.checkCanceled();
if (isCompilableGroovyFile(fileOrDir, scriptExtensions)) {
return false;
}
return true;
}
};
final ModuleRootManager rootManager = ModuleRootManager.getInstance(m);
final ModuleFileIndex fileIndex = rootManager.getFileIndex();
for (VirtualFile file : rootManager.getSourceRoots(JavaModuleSourceRootTypes.SOURCES)) {
if (!fileIndex.iterateContentUnderDirectory(file, groovyFileSearcher)) {
return true;
}
}
}
}
return false;
}
示例7: createTheme
import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private void createTheme(@NotNull Project project, Module module) {
String[] commands = {"echo", "0", "|", "php", "bin/plugin", "devtools", "new-theme",
"--name", themeData.getName(),
"--description", themeData.getDescription(),
"--developer", themeData.getDeveloper(),
"--email", themeData.getEmail()};
GravProjectSettings settings = GravProjectSettings.getInstance(project);
ModuleRootManager root = ModuleRootManager.getInstance(module);
VirtualFile srcFile = null;
for (VirtualFile file : root.getSourceRoots()) {
if (file.isDirectory() && file.getName().contentEquals("src")) {
srcFile = file;
break;
}
}
if (srcFile == null) {
if (settings != null && settings.withSrcDirectory) {
NotificationHelper.showBaloon("No source root found in module '" + module.getName() + "'",
MessageType.ERROR, project);
return;
} else {
srcFile = FileCreateUtil.getParentDirectory(module.getModuleFile(), module.getName());
}
}
VirtualFile finalSrcFile = srcFile;
ProcessUtils processUtils = new ProcessUtils(commands, new File(finalSrcFile.getPath()));
Task.Backgroundable t = new Task.Backgroundable(project, "Create New Grav Theme in Module '" + module.getName() + "'") {
@Override
public boolean shouldStartInBackground() {
return true;
}
@Override
public void onSuccess() {
super.onSuccess();
String output = processUtils.getOutputAsString();
if (processUtils.getErrorOutput() != null) {
NotificationHelper.showBaloon(processUtils.getErrorOutput(), MessageType.ERROR, project);
} else {
NotificationHelper.showBaloon("Theme '" + themeData.getName() + "' was created", MessageType.INFO, project);
}
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
processUtils.execute();
}
};
ProgressManager.getInstance().run(t);
}
示例8: getTestSourceRootCount
import com.intellij.openapi.roots.ModuleRootManager; //导入方法依赖的package包/类
private static int getTestSourceRootCount(@NotNull Module module) {
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
return manager.getSourceRoots(true).length - manager.getSourceRoots(false).length;
}