use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ModuleElementPresentation method render.
public void render(@NotNull PresentationData presentationData, SimpleTextAttributes mainAttributes, SimpleTextAttributes commentAttributes) {
final Module module = findModule();
if (myTestOutput) {
presentationData.setIcon(PlatformIcons.TEST_SOURCE_FOLDER);
} else if (module != null) {
presentationData.setIcon(ModuleType.get(module).getIcon());
}
String moduleName;
if (module != null) {
moduleName = module.getName();
final ModifiableModuleModel moduleModel = myContext.getModifiableModuleModel();
if (moduleModel != null) {
final String newName = moduleModel.getNewName(module);
if (newName != null) {
moduleName = newName;
}
}
} else if (myModulePointer != null) {
moduleName = myModulePointer.getModuleName();
} else {
moduleName = "<unknown>";
}
String text = myTestOutput ? CompilerBundle.message("node.text.0.test.compile.output", moduleName) : CompilerBundle.message("node.text.0.compile.output", moduleName);
presentationData.addText(text, module != null ? mainAttributes : SimpleTextAttributes.ERROR_ATTRIBUTES);
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class ResolveClassTest method configureDependency.
@SuppressWarnings({ "ConstantConditions" })
private void configureDependency() {
ApplicationManager.getApplication().runWriteAction(() -> {
ModifiableModuleModel modifiableModel = ModuleManager.getInstance(getProject()).getModifiableModel();
Module module = modifiableModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
modifiableModel.commit();
VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByPath(getTestDataPath() + "/class/dependentModule");
assert root != null;
PsiTestUtil.addContentRoot(module, root);
PsiTestUtil.addSourceRoot(module, root.findChild("src"));
PsiTestUtil.addSourceRoot(module, root.findChild("test"), true);
ModuleRootModificationUtil.addDependency(getModule(), module);
});
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class MultiModuleEditingTest method testRootsEditing.
public void testRootsEditing() {
final MessageBusConnection connection = myProject.getMessageBus().connect();
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
final MyModuleListener moduleListener = new MyModuleListener();
connection.subscribe(ProjectTopics.MODULES, moduleListener);
final Module moduleA;
final Module moduleB;
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelB.addModuleOrderEntry(moduleA);
final ContentEntry contentEntryA = rootModelA.addContentEntry(getVirtualFileInTestData("a"));
contentEntryA.addSourceFolder(getVirtualFileInTestData("a/src"), false);
final ContentEntry contentEntryB = rootModelB.addContentEntry(getVirtualFileInTestData("b"));
contentEntryB.addSourceFolder(getVirtualFileInTestData("b/src"), false);
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB, rootModelA }, moduleModel));
}
final JavaPsiFacade psiManager = getJavaFacade();
assertNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleA)));
assertNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleB)));
assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleA)));
assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleScope(moduleB)));
assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleB)));
moduleManager.disposeModule(moduleB);
moduleManager.disposeModule(moduleA);
moduleListener.assertCorrectEvents(new String[][] { { "+b", "+a" }, { "-b" }, { "-a" } });
connection.disconnect();
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class MultiModuleEditingTest method testRenaming.
public void testRenaming() throws Exception {
final ModuleManager moduleManager = ModuleManager.getInstance(myProject);
final Module moduleA;
final Module moduleB;
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleA = moduleModel.newModule("a.iml", StdModuleTypes.JAVA.getId());
moduleB = moduleModel.newModule("b.iml", StdModuleTypes.JAVA.getId());
final Module moduleC = moduleModel.newModule("c.iml", StdModuleTypes.JAVA.getId());
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelB.addModuleOrderEntry(moduleC);
moduleModel.disposeModule(moduleC);
ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[] { rootModelB }, moduleModel));
}
final ModuleRootManager rootManagerB = ModuleRootManager.getInstance(moduleB);
assertEquals(0, rootManagerB.getDependencies().length);
final String[] dependencyModuleNames = rootManagerB.getDependencyModuleNames();
assertEquals(1, dependencyModuleNames.length);
assertEquals("c", dependencyModuleNames[0]);
{
final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel();
moduleModel.renameModule(moduleA, "c");
assertSame(moduleA, moduleModel.findModuleByName("a"));
assertSame(moduleA, moduleManager.findModuleByName("a"));
assertEquals("c", moduleModel.getNewName(moduleA));
assertSame(moduleA, moduleModel.getModuleToBeRenamed("c"));
ApplicationManager.getApplication().runWriteAction(() -> moduleModel.commit());
}
assertEquals(1, rootManagerB.getDependencies().length);
assertEquals(moduleA, rootManagerB.getDependencies()[0]);
assertSame(moduleA, moduleManager.findModuleByName("c"));
assertNull(moduleManager.findModuleByName("a"));
assertEquals("c", moduleA.getName());
moduleManager.disposeModule(moduleA);
moduleManager.disposeModule(moduleB);
}
use of com.intellij.openapi.module.ModifiableModuleModel in project intellij-community by JetBrains.
the class AbstractModuleDataService method importData.
@Override
public void importData(@NotNull final Collection<DataNode<E>> toImport, @Nullable ProjectData projectData, @NotNull final Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
if (toImport.isEmpty()) {
return;
}
final Collection<DataNode<E>> toCreate = filterExistingModules(toImport, modelsProvider, project);
if (!toCreate.isEmpty()) {
createModules(toCreate, modelsProvider, project);
}
for (DataNode<E> node : toImport) {
Module module = node.getUserData(MODULE_KEY);
if (module != null) {
String productionModuleId = node.getData().getProductionModuleId();
modelsProvider.setTestModuleProperties(module, productionModuleId);
setModuleOptions(module, node);
ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
syncPaths(module, modifiableRootModel, node.getData());
setLanguageLevel(modifiableRootModel, node.getData());
}
}
for (DataNode<E> node : toImport) {
Module module = node.getUserData(MODULE_KEY);
if (module != null) {
final String[] groupPath;
groupPath = node.getData().getIdeModuleGroup();
final ModifiableModuleModel modifiableModel = modelsProvider.getModifiableModuleModel();
modifiableModel.setModuleGroupPath(module, groupPath);
}
}
}
Aggregations