diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 0609009dbf81..4305c37547e5 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -335,6 +335,7 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { return iprFile; } + @NotNull @Override protected Module doCreateRealModule(String moduleName) { //todo[nik] reuse code from PlatformTestCase diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java index f2b71328a349..f35843479b31 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceFieldWitSetUpInitializationTest.java @@ -1,5 +1,17 @@ /* - * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2017 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. */ /* @@ -21,6 +33,7 @@ import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.introduceField.BaseExpressionToFieldHandler; import com.intellij.refactoring.introduceField.LocalToFieldHandler; import com.intellij.util.PathUtil; +import org.jetbrains.annotations.NotNull; import org.junit.Before; import java.io.File; @@ -31,6 +44,7 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas return JavaTestUtil.getJavaTestDataPath(); } + @NotNull @Override protected Module createModule(final String name) { final Module module = super.createModule(name); diff --git a/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java b/java/testFramework/src/com/intellij/testFramework/ModuleTestCase.java index bc00a96b8a3f..cf23fce616db 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-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -81,7 +81,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { } } - protected Module createModule(final File moduleFile) { + protected Module createModule(@NotNull File moduleFile) { return createModule(moduleFile, StdModuleTypes.JAVA); } @@ -99,14 +99,16 @@ public abstract class ModuleTestCase extends IdeaTestCase { return module; } - protected Module loadModule(@NotNull String modulePath) { - final String normalizedPath = FileUtil.toSystemIndependentName(modulePath); - LocalFileSystem.getInstance().refreshAndFindFileByPath(normalizedPath); + protected Module loadModule(@NotNull VirtualFile file) { + return loadModule(file.getPath()); + } + protected Module loadModule(@NotNull String modulePath) { final ModuleManager moduleManager = ModuleManager.getInstance(myProject); Module module; try { - module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> moduleManager.loadModule(normalizedPath)); + module = ApplicationManager.getApplication().runWriteAction((ThrowableComputable)() -> moduleManager.loadModule( + FileUtil.toSystemIndependentName(modulePath))); } catch (Exception e) { LOG.error(e); @@ -130,7 +132,7 @@ public abstract class ModuleTestCase extends IdeaTestCase { @Override public boolean visitFile(@NotNull VirtualFile file) { if (!file.isDirectory() && file.getName().endsWith(ModuleFileType.DOT_DEFAULT_EXTENSION)) { - ModuleImpl module = (ModuleImpl)loadModule(file.getPath()); + ModuleImpl module = (ModuleImpl)loadModule(file); if (moduleConsumer != null) { moduleConsumer.consume(module); } diff --git a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java index 7ef52032a98a..0e25a83c0d61 100644 --- a/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java +++ b/platform/projectModel-api/src/com/intellij/openapi/module/ModuleManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -64,8 +64,7 @@ public abstract class ModuleManager extends SimpleModificationTracker { * @throws ModuleWithNameAlreadyExists if a module with such a name already exists in the project. */ @NotNull - public abstract Module loadModule(@NotNull String filePath) - throws InvalidDataException, IOException, JDOMException, ModuleWithNameAlreadyExists; + public abstract Module loadModule(@NotNull String filePath) throws IOException, JDOMException, ModuleWithNameAlreadyExists; /** * Disposes of the specified module and removes it from the project. diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java index 7820ec8b4e19..bd1fb16f906f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -74,6 +74,7 @@ import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndexImpl; import com.intellij.util.indexing.IndexableSetContributor; import com.intellij.util.ui.UIUtil; +import gnu.trove.THashSet; import junit.framework.TestCase; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -105,7 +106,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro protected ProjectManagerEx myProjectManager; protected Project myProject; protected Module myModule; - protected static final Collection myFilesToDelete = new HashSet<>(); + protected static final Collection myFilesToDelete = new THashSet<>(); protected boolean myAssertionsInTestDetected; protected static final Logger LOG = Logger.getInstance("#com.intellij.testFramework.PlatformTestCase"); public static Thread ourTestThread; @@ -327,25 +328,29 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro }.execute().throwException(); } + @NotNull protected Module createMainModule() throws IOException { return createModule(myProject.getName()); } + @NotNull protected Module createModule(@NonNls final String moduleName) { return doCreateRealModule(moduleName); } + @NotNull protected Module doCreateRealModule(final String moduleName) { return doCreateRealModuleIn(moduleName, myProject, getModuleType()); } + @NotNull protected static Module doCreateRealModuleIn(String moduleName, final Project project, final ModuleType moduleType) { final VirtualFile baseDir = project.getBaseDir(); assertNotNull(baseDir); - String path = baseDir.getPath(); - return createModuleAt(moduleName, project, moduleType, path); + return createModuleAt(moduleName, project, moduleType, baseDir.getPath()); } + @NotNull protected static Module createModuleAt(String moduleName, Project project, ModuleType moduleType, String path) { File moduleFile = new File(FileUtil.toSystemDependentName(path), moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); FileUtil.createIfDoesntExist(moduleFile); diff --git a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java index f2b6ca4904d9..bd6dce66a6ca 100644 --- a/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java +++ b/plugins/eclipse/testSources/org/jetbrains/idea/eclipse/Eclipse2ModulesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 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. @@ -55,6 +55,7 @@ public abstract class Eclipse2ModulesTest extends IdeaTestCase { copyDirContentsTo(vTestRoot, getProject().getBaseDir()); } + @NotNull @Override protected Module createMainModule() { return createModule(DEPEND_MODULE_NAME);