use of com.intellij.openapi.roots.ModuleRootManager in project android by JetBrains.
the class ConflictSetTest method setUpModuleDependencies.
private void setUpModuleDependencies() {
// Make module depend on myLibModule.
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(myModule);
ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
try {
rootModel.addModuleOrderEntry(myLibModule);
} finally {
rootModel.commit();
}
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.
the class CodeContext method createCodeContextFromLibraries.
private static CodeContext createCodeContextFromLibraries(final String namespace, final Module module, final FlexBuildConfiguration bc) {
final Map<String, CodeContext> contextsOfModule = new THashMap<>();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
// If fixed - then method usage at getStdCodeContext() must be changed to make sure that all namespaces handled at that point.
for (DependencyEntry entry : bc.getDependencies().getEntries()) {
if (entry.getDependencyType().getLinkageType() == LinkageType.LoadInRuntime)
continue;
if (entry instanceof BuildConfigurationEntry) {
final FlexBuildConfiguration bcDependency = ((BuildConfigurationEntry) entry).findBuildConfiguration();
if (bcDependency != null && bcDependency.getOutputType() == OutputType.Library) {
addComponentsFromManifests(module, contextsOfModule, bcDependency, true);
}
} else if (entry instanceof ModuleLibraryEntry) {
final LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, rootManager);
if (orderEntry != null) {
for (VirtualFile file : orderEntry.getRootFiles(OrderRootType.CLASSES)) {
handleFileDependency(module, contextsOfModule, file);
}
}
} else if (entry instanceof SharedLibraryEntry) {
final Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
if (library != null) {
for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
handleFileDependency(module, contextsOfModule, file);
}
}
}
}
addComponentsFromManifests(module, contextsOfModule, bc, false);
final CodeContextHolder contextHolder = CodeContextHolder.getInstance(module.getProject());
for (Map.Entry<String, CodeContext> entry : contextsOfModule.entrySet()) {
contextHolder.putCodeContext(entry.getKey(), module, entry.getValue());
}
CodeContext codeContext = contextsOfModule.get(namespace);
if (codeContext == null) {
codeContext = CodeContextHolder.EMPTY;
}
return codeContext;
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-plugins by JetBrains.
the class FlexFileReferenceHelper method registerFixes.
@NotNull
public List<? extends LocalQuickFix> registerFixes(final FileReference reference) {
final PsiElement element = reference.getElement();
if (!(reference instanceof JSFlexFileReference) || !(element instanceof JSAttributeNameValuePair))
return Collections.emptyList();
final PsiElement parent = element.getParent();
if (!(parent instanceof JSAttribute) || !FlexAnnotationNames.EMBED.equals(((JSAttribute) parent).getName())) {
return Collections.emptyList();
}
final String value = ((JSAttributeNameValuePair) element).getSimpleValue();
if (value.startsWith("/"))
return Collections.emptyList();
final Module module = ModuleUtil.findModuleForPsiElement(element);
if (module == null)
return Collections.emptyList();
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final VirtualFile virtualFile = element.getContainingFile().getVirtualFile();
final boolean testSourceRoot = virtualFile != null && rootManager.getFileIndex().isInTestSourceContent(virtualFile);
for (VirtualFile sourceRoot : rootManager.getSourceRoots(testSourceRoot)) {
if (sourceRoot.findFileByRelativePath(value) != null) {
return Collections.singletonList(new AddLeadingSlashFix((JSAttributeNameValuePair) element));
}
}
return Collections.emptyList();
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-community by JetBrains.
the class IdeFrameFixture method getSourceFolderRelativePaths.
@NotNull
public Collection<String> getSourceFolderRelativePaths(@NotNull String moduleName, @NotNull final JpsModuleSourceRootType<?> sourceType) {
final Set<String> paths = new HashSet<>();
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;
}
use of com.intellij.openapi.roots.ModuleRootManager in project intellij-community by JetBrains.
the class PlatformProjectConfigurator method configureProject.
@Override
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, final Ref<Module> moduleRef) {
final ModuleManager moduleManager = ModuleManager.getInstance(project);
final Module[] modules = moduleManager.getModules();
if (modules.length == 0) {
ApplicationManager.getApplication().runWriteAction(() -> {
// correct module name when opening root of drive as project (RUBY-5181)
String moduleName = baseDir.getName().replace(":", "");
String imlName = baseDir.getPath() + "/.idea/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION;
ModuleTypeManager instance = ModuleTypeManager.getInstance();
String id = instance == null ? "unknown" : instance.getDefaultModuleType().getId();
final Module module = moduleManager.newModule(imlName, id);
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = rootManager.getModifiableModel();
if (rootModel.getContentRoots().length == 0) {
rootModel.addContentEntry(baseDir);
}
rootModel.inheritSdk();
rootModel.commit();
moduleRef.set(module);
});
}
}
Aggregations