From cc7f68e10c30ed500d63e178a53dc204a856ff86 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Thu, 10 May 2012 18:51:49 +0200 Subject: [PATCH] ModuleManager.newModule() also accepts module type ID --- .../completion/ClassNameCompletionTest.java | 18 +++++++++++++++- .../roots/DirectoryIndexImplTest.java | 21 ++++++++++++++++--- .../testFramework/ModuleTestCase.java | 4 ++-- .../openapi/module/ModuleManager.java | 6 +++--- .../module/impl/ModuleManagerImpl.java | 4 ++-- .../platform/PlatformProjectConfigurator.java | 4 ++-- .../testFramework/LightPlatformTestCase.java | 2 +- .../testFramework/PlatformTestCase.java | 2 +- .../impl/ModuleFixtureBuilderImpl.java | 4 ++-- .../CreateNewModuleTask.java | 17 ++++++++++++++- .../idea/eclipse/EclipseClasspathTest.java | 4 ++-- .../idea/eclipse/EclipseEmlTest.java | 4 ++-- .../idea/eclipse/EclipseImlTest.java | 4 ++-- .../importing/GradleModuleImporter.java | 2 +- .../jetbrains/idea/maven/MavenTestCase.java | 4 ++-- 15 files changed, 73 insertions(+), 27 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java index 8c380ca0ee2a..39c4f1b0cda1 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/ClassNameCompletionTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.codeInsight.completion; import com.intellij.JavaTestUtil; @@ -211,7 +226,8 @@ public class ClassNameCompletionTest extends CompletionTestCase { new WriteCommandAction.Simple(getProject()) { @Override protected void run() throws Exception { - final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType()); + final JavaModuleType type = new JavaModuleType(); + final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", type.getId()); createClass(module, "package foo.bar; class AxBxCxDxEx {}"); } }.execute().throwException(); diff --git a/java/java-tests/testSrc/com/intellij/roots/DirectoryIndexImplTest.java b/java/java-tests/testSrc/com/intellij/roots/DirectoryIndexImplTest.java index 6b33b1ab7bc2..ddec4a1b9d57 100644 --- a/java/java-tests/testSrc/com/intellij/roots/DirectoryIndexImplTest.java +++ b/java/java-tests/testSrc/com/intellij/roots/DirectoryIndexImplTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.roots; import com.intellij.openapi.application.ApplicationManager; @@ -121,7 +136,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase { // fill roots of module2 { VirtualFile moduleFile = myModule2Dir.createChildData(null, "module2.iml"); - myModule2 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA); + myModule2 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA.getId()); ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule2).getModifiableModel(); ContentEntry contentEntry = rootModel.addContentEntry(myModule2Dir); @@ -139,7 +154,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase { // fill roots of module3 { VirtualFile moduleFile = myModule3Dir.createChildData(null, "module3.iml"); - myModule3 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA); + myModule3 = moduleManager.newModule(moduleFile.getPath(), StdModuleTypes.JAVA.getId()); ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule3).getModifiableModel(); rootModel.addContentEntry(myModule3Dir); @@ -295,7 +310,7 @@ public class DirectoryIndexImplTest extends IdeaTestCase { VirtualFile newModuleContent = myRootVFile.createChildDirectory(null, "newModule"); newModuleContent.createChildDirectory(null, "subDir"); ModuleManager moduleManager = ModuleManager.getInstance(myProject); - Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA); + Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA.getId()); ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); rootModel.addContentEntry(newModuleContent); rootModel.commit(); diff --git a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java index 684da0dd18f8..ebd9c29430fa 100644 --- a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { new Computable() { @Override public Module compute() { - return ModuleManager.getInstance(myProject).newModule(path, moduleType); + return ModuleManager.getInstance(myProject).newModule(path, moduleType.getId()); } } ); diff --git a/platform/lang-api/src/com/intellij/openapi/module/ModuleManager.java b/platform/lang-api/src/com/intellij/openapi/module/ModuleManager.java index b2e00d438652..c6c9c2147dfa 100644 --- a/platform/lang-api/src/com/intellij/openapi/module/ModuleManager.java +++ b/platform/lang-api/src/com/intellij/openapi/module/ModuleManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,10 +48,10 @@ public abstract class ModuleManager { * to which the module manager is related. * * @param filePath the path at which the module is created. - * @param moduleType the type of the module to create. + * @param moduleTypeId the ID of the module type to create. * @return the module instance. */ - @NotNull public abstract Module newModule(@NotNull @NonNls String filePath, @NotNull ModuleType moduleType); + @NotNull public abstract Module newModule(@NotNull @NonNls String filePath, final String moduleTypeId); /** * Loads a module from an .iml file with the specified path and adds it to the project. diff --git a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java index e5fe7d6adad2..23d1775a1778 100644 --- a/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/module/impl/ModuleManagerImpl.java @@ -472,10 +472,10 @@ public class ModuleManagerImpl extends ModuleManager implements ProjectComponent } @NotNull - public Module newModule(@NotNull String filePath, @NotNull ModuleType moduleType) { + public Module newModule(@NotNull String filePath, final String moduleTypeId) { myModificationCount++; final ModifiableModuleModel modifiableModel = getModifiableModel(); - final Module module = modifiableModel.newModule(filePath, moduleType.getId()); + final Module module = modifiableModel.newModule(filePath, moduleTypeId); modifiableModel.commit(); return module; } diff --git a/platform/lang-impl/src/com/intellij/platform/PlatformProjectConfigurator.java b/platform/lang-impl/src/com/intellij/platform/PlatformProjectConfigurator.java index 81409abdf669..37f60117cd8a 100644 --- a/platform/lang-impl/src/com/intellij/platform/PlatformProjectConfigurator.java +++ b/platform/lang-impl/src/com/intellij/platform/PlatformProjectConfigurator.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,7 +40,7 @@ public class PlatformProjectConfigurator implements DirectoryProjectConfigurator public void run() { String moduleName = baseDir.getName().replace(":", ""); // correct module name when opening root of drive as project (RUBY-5181) String imlName = baseDir.getPath() + "/.idea/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION; - final Module module = moduleManager.newModule(imlName, ModuleTypeManager.getInstance().getDefaultModuleType()); + final Module module = moduleManager.newModule(imlName, ModuleTypeManager.getInstance().getDefaultModuleType().getId()); ModuleRootManager rootManager = ModuleRootManager.getInstance(module); ModifiableRootModel rootModel = rootManager.getModifiableModel(); if (rootModel.getContentRoots().length == 0) { diff --git a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java index b3df4e20de88..72a4258cb213 100644 --- a/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/LightPlatformTestCase.java @@ -298,7 +298,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override public Module compute() { - return ModuleManager.getInstance(ourProject).newModule("light_idea_test_case.iml", moduleType); + return ModuleManager.getInstance(ourProject).newModule("light_idea_test_case.iml", moduleType.getId()); } }); } diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 6463c7c5e07b..354c47885495 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -305,7 +305,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro @Override protected void run(Result result) throws Throwable { final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile); - Module module = ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType); + Module module = ModuleManager.getInstance(project).newModule(virtualFile.getPath(), moduleType.getId()); module.getModuleFile(); result.setResult(module); } diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java index 9a1691e1e186..578d8c0d91c4 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/ModuleFixtureBuilderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ public abstract class ModuleFixtureBuilderImpl implemen final Project project = myFixtureBuilder.getFixture().getProject(); assert project != null; final String moduleFilePath = new File(project.getProjectFilePath()).getParent() + File.separator + getNextIndex() + ModuleFileType.DOT_DEFAULT_EXTENSION; - return ModuleManager.getInstance(project).newModule(moduleFilePath, myModuleType); + return ModuleManager.getInstance(project).newModule(moduleFilePath, myModuleType.getId()); } private static int getNextIndex() { diff --git a/plugins/android/src/org/jetbrains/android/importDependencies/CreateNewModuleTask.java b/plugins/android/src/org/jetbrains/android/importDependencies/CreateNewModuleTask.java index ab3af7c6a19c..a6feeaeac33b 100644 --- a/plugins/android/src/org/jetbrains/android/importDependencies/CreateNewModuleTask.java +++ b/plugins/android/src/org/jetbrains/android/importDependencies/CreateNewModuleTask.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.jetbrains.android.importDependencies; import com.intellij.openapi.application.ApplicationManager; @@ -35,7 +50,7 @@ class CreateNewModuleTask extends ModuleProvidingTask { public Module compute() { final Module depModule = ModuleManager.getInstance(myProject) - .newModule(myContentRoot.getPath() + '/' + myContentRoot.getName() + ".iml", StdModuleTypes.JAVA); + .newModule(myContentRoot.getPath() + '/' + myContentRoot.getName() + ".iml", StdModuleTypes.JAVA.getId()); final ModifiableRootModel model = ModuleRootManager.getInstance(depModule).getModifiableModel(); model.addContentEntry(myContentRoot); model.commit(); diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java index 2d9d8aca50c1..ea2034fe7520 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseClasspathTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -86,7 +86,7 @@ public class EclipseClasspathTest extends IdeaTestCase { @Override public Module compute() { return ModuleManager.getInstance(project) - .newModule(path + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA); + .newModule(path + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA.getId()); } }); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java index 296479e978d1..17f6d9514c82 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseEmlTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ public class EclipseEmlTest extends IdeaTestCase { @Override public Module compute() { return ModuleManager.getInstance(project) - .newModule(path + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA); + .newModule(path + "/" + EclipseProjectFinder.findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA.getId()); } }); diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java index 0ffc332cc99d..b47da4e11558 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/EclipseImlTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -88,7 +88,7 @@ public class EclipseImlTest extends IdeaTestCase { public Module compute() { return ModuleManager.getInstance(project) .newModule(new File(path) + File.separator + EclipseProjectFinder - .findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA); + .findProjectName(path) + IdeaXml.IML_EXT, StdModuleTypes.JAVA.getId()); } }); final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleModuleImporter.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleModuleImporter.java index 7a95fa3ea2bc..4f7f29d7d5fb 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleModuleImporter.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/importing/GradleModuleImporter.java @@ -78,7 +78,7 @@ public class GradleModuleImporter { } private void importModule(@NotNull ModuleManager moduleManager, @NotNull GradleModule module) { - final Module created = moduleManager.newModule(module.getModuleFilePath(), StdModuleTypes.JAVA); + final Module created = moduleManager.newModule(module.getModuleFilePath(), StdModuleTypes.JAVA.getId()); // Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via gradle) ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(created); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java index c150655db22c..c05e9a20810b 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -334,7 +334,7 @@ public abstract class MavenTestCase extends UsefulTestCase { @Override protected void run(Result moduleResult) throws Throwable { VirtualFile f = createProjectSubFile(name + "/" + name + ".iml"); - Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type); + Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type.getId()); ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); model.addContentEntry(f.getParent()); model.commit();