diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java index 1175b7fd3a7..f32606c4e4b 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/KotlinToJVMBytecodeCompiler.java @@ -131,6 +131,22 @@ public class KotlinToJVMBytecodeCompiler { return true; } + @Nullable + private static FqName findMainClass(@NotNull List files) { + FqName mainClass = null; + for (JetFile file : files) { + if (JetMainDetector.hasMain(file.getDeclarations())) { + if (mainClass != null) { + // more than one main + return null; + } + FqName fqName = JetPsiUtil.getFQName(file); + mainClass = fqName.child(Name.identifier(JvmAbi.PACKAGE_CLASS)); + } + } + return mainClass; + } + public static boolean compileBunchOfSources( K2JVMCompileEnvironmentConfiguration configuration, @Nullable File jar, @@ -138,14 +154,7 @@ public class KotlinToJVMBytecodeCompiler { boolean script, boolean includeRuntime ) { - FqName mainClass = null; - for (JetFile file : configuration.getEnvironment().getSourceFiles()) { - if (JetMainDetector.hasMain(file.getDeclarations())) { - FqName fqName = JetPsiUtil.getFQName(file); - mainClass = fqName.child(Name.identifier(JvmAbi.PACKAGE_CLASS)); - break; - } - } + FqName mainClass = findMainClass(configuration.getEnvironment().getSourceFiles()); GenerationState generationState = analyzeAndGenerate(configuration); if (generationState == null) {