diff --git a/build.xml b/build.xml index f1084a2b0b9..3a58cf12675 100644 --- a/build.xml +++ b/build.xml @@ -646,6 +646,7 @@ + @@ -680,6 +681,8 @@ + + - + @@ -708,7 +711,7 @@ - + @@ -719,7 +722,7 @@ - + @@ -737,7 +740,7 @@ - + diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java index d08b1ef5919..181981b3462 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClassFileFactory.java @@ -21,6 +21,7 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; +import kotlin.KotlinPackage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -84,9 +85,7 @@ public class ClassFileFactory implements OutputFileCollection { } private void writeModuleMappings(Collection values) { - String moduleName = state.getModule().getName().asString(); - moduleName = moduleName.replaceAll(">", "").replaceAll("<", ""); - moduleName = moduleName.substring(moduleName.lastIndexOf(" ") + 1); + String moduleName = KotlinPackage.removeSurrounding(state.getModule().getName().asString(), "<", ">"); String outputFilePath = "META-INF/" + moduleName + ".kotlin_module"; final StringWriter moduleMapping = new StringWriter(1024); for (PackageCodegen codegen : values) { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java index eedf271edff..853b2435ec8 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.java @@ -55,6 +55,9 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { @ValueDescription("") public String kotlinHome; + @Argument(value = "module-name", description = "Module name") + public String moduleName; + // Advanced options @Argument(value = "Xno-call-assertions", description = "Don't generate not-null assertion after each invocation of method returning not-null") @@ -74,4 +77,5 @@ public class K2JVMCompilerArguments extends CommonCompilerArguments { public String executableScriptFileName() { return "kotlinc-jvm"; } + } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index db31a8b0894..162dc6d816e 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -134,6 +134,8 @@ public open class K2JVMCompiler : CLICompiler() { else emptyList()) + configuration.put(JVMConfigurationKeys.MODULE_NAME, arguments.moduleName ?: "main") + putAdvancedOptions(configuration, arguments) messageSeverityCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", CompilerMessageLocation.NO_LOCATION) diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index c9020f66a10..c02ca339144 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -318,7 +318,8 @@ public class KotlinToJVMBytecodeCompiler { @Override public AnalysisResult invoke() { BindingTrace sharedTrace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(); - ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.getProject()); + ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.getProject(), + getModuleName(environment)); return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext( moduleContext, diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JVMConfigurationKeys.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JVMConfigurationKeys.java index 51f8b6f22ae..75dba22ca09 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JVMConfigurationKeys.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/JVMConfigurationKeys.java @@ -50,4 +50,8 @@ public class JVMConfigurationKeys { public static final CompilerConfigurationKey> MODULE_IDS = CompilerConfigurationKey.create("module id strings"); + + public static final CompilerConfigurationKey MODULE_NAME = + CompilerConfigurationKey.create("module name"); + } diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/ModuleName.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/ModuleName.kt new file mode 100644 index 00000000000..606b65b52ef --- /dev/null +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/config/ModuleName.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2015 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.kotlin.cli.jvm.config + +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment + +public fun KotlinCoreEnvironment.getModuleName(): String = configuration.get(JVMConfigurationKeys.MODULE_NAME)!! \ No newline at end of file diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java index c9e612057dd..078e5bfde53 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/repl/ReplInterpreter.java @@ -78,6 +78,7 @@ import java.util.Collections; import java.util.List; import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.getJvmClasspathRoots; +import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.getModuleName; import static org.jetbrains.kotlin.codegen.AsmUtil.asmTypeByFqNameWithoutInnerClasses; import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.registerClassNameForScript; import static org.jetbrains.kotlin.resolve.DescriptorToSourceUtils.descriptorToDeclaration; @@ -106,7 +107,7 @@ public class ReplInterpreter { Project project = environment.getProject(); this.psiFileFactory = (PsiFileFactoryImpl) PsiFileFactory.getInstance(project); this.trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(); - MutableModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project); + MutableModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, getModuleName(environment)); this.module = moduleContext.getModule(); scriptDeclarationFactory = new ScriptMutableDeclarationProviderFactory(); diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java index 217e85dccef..6750ad409f4 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/TopDownAnalyzerFacadeForJVM.java @@ -169,9 +169,9 @@ public enum TopDownAnalyzerFacadeForJVM { } @NotNull - public static MutableModuleContext createContextWithSealedModule(@NotNull Project project) { + public static MutableModuleContext createContextWithSealedModule(@NotNull Project project, @NotNull String moduleName) { MutableModuleContext context = ContextForNewModule( - project, Name.special(""), JVM_MODULE_PARAMETERS + project, Name.special("<" + moduleName + ">"), JVM_MODULE_PARAMETERS ); context.setDependencies(context.getModule(), KotlinBuiltIns.getInstance().getBuiltInsModule()); return context; diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java index b09723a7586..23ec20ec9dc 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/AbstractLoadJavaTest.java @@ -55,6 +55,7 @@ import java.util.Map; import java.util.regex.Pattern; import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.addJavaSourceRoot; +import static org.jetbrains.kotlin.cli.jvm.config.ConfigPackage.getModuleName; import static org.jetbrains.kotlin.config.ConfigPackage.addKotlinSourceRoot; import static org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil.*; import static org.jetbrains.kotlin.test.JetTestUtils.*; @@ -146,7 +147,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir { KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES); BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(); - ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.getProject()); + ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.getProject(), + getModuleName(environment)); TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental( moduleContext, diff --git a/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt b/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt index 6c59597de23..17732a9517b 100644 --- a/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/renderer/AbstractDescriptorRendererTest.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.testFramework.UsefulTestCase import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.config.getModuleName import org.jetbrains.kotlin.container.ComponentProvider import org.jetbrains.kotlin.container.get import org.jetbrains.kotlin.descriptors.ClassDescriptor @@ -53,7 +54,7 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment val fileText = FileUtil.loadFile(File(path), true) val psiFile = JetPsiFactory(getProject()).createFile(fileText) - val context = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject()) + val context = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject(), environment.getModuleName()) val container = createContainerForLazyResolve( diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.java b/compiler/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.java index d61f88c46a6..33102c25ca8 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/lazy/JvmResolveUtil.java @@ -67,7 +67,7 @@ public class JvmResolveUtil { @NotNull Project project, @NotNull Collection files ) { - ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project); + ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "java-integration-test"); BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace(); diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/lazy/LazyResolveTestUtil.java b/compiler/tests/org/jetbrains/kotlin/resolve/lazy/LazyResolveTestUtil.java index 29221fbcdb4..734e5230125 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/lazy/LazyResolveTestUtil.java +++ b/compiler/tests/org/jetbrains/kotlin/resolve/lazy/LazyResolveTestUtil.java @@ -52,7 +52,7 @@ public class LazyResolveTestUtil { @NotNull public static ModuleDescriptor resolve(@NotNull Project project, @NotNull BindingTrace trace, @NotNull List sourceFiles) { - ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project); + ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "test"); TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental( moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/AbstractLocalClassProtoTest.kt b/compiler/tests/org/jetbrains/kotlin/serialization/AbstractLocalClassProtoTest.kt index efae2cd2a34..665cbe7fd3a 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/AbstractLocalClassProtoTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/serialization/AbstractLocalClassProtoTest.kt @@ -20,6 +20,7 @@ import com.intellij.psi.search.GlobalSearchScope import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.config.getModuleName import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerForJvm import org.jetbrains.kotlin.incremental.components.LookupTracker @@ -53,7 +54,7 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() { JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, tmpdir), EnvironmentConfigFiles.JVM_CONFIG_FILES ) - val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project) + val moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(environment.project, environment.getModuleName()) val providerFactory = FileBasedDeclarationProviderFactory(moduleContext.storageManager, emptyList()) val container = createContainerForTopDownAnalyzerForJvm( diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextConsistencyTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextConsistencyTest.kt index babe45bc035..2e45f603c01 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextConsistencyTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextConsistencyTest.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.resolve.BindingTraceContext import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM -import kotlin.properties.Delegates public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() { @@ -41,7 +40,7 @@ public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() { override fun getModuleDescriptor(): ModuleDescriptor = TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext( - TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject()), + TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject(), "test"), listOf(), BindingTraceContext(), null, null ).moduleDescriptor