diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java index 47afaa99bd0..f92fdd9ac53 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompilerArguments.java @@ -17,6 +17,7 @@ package org.jetbrains.jet.cli.js; import com.sampullara.cli.Argument; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.cli.common.CompilerArguments; import org.jetbrains.k2js.facade.MainCallParameters; @@ -53,8 +54,9 @@ public class K2JSCompilerArguments extends CompilerArguments { @Argument(value = "version", description = "Display compiler version") public boolean version; - @Argument(value = "mainCall", description = "Whether a main function should be invoked; either 'main' or 'mainWithArgs'") - public String mainCall; + @Nullable + @Argument(value = "main", description = "Whether a main function should be called; either 'call' or 'noCall', default 'call' (main function will be auto detected)") + public String main; @Argument(value = "help", alias = "h", description = "Show help") public boolean help; @@ -85,15 +87,12 @@ public class K2JSCompilerArguments extends CompilerArguments { } public MainCallParameters createMainCallParameters() { - if (mainCall != null) { - if (mainCall.equals("main")) { - return MainCallParameters.mainWithoutArguments(); - } - if (mainCall.equals("mainWithArgs")) { - // TODO should we pass the arguments to the compiler? - return MainCallParameters.mainWithArguments(new ArrayList()); - } + if ("noCall".equals(main)) { + return MainCallParameters.noCall(); + } + else { + // TODO should we pass the arguments to the compiler? + return MainCallParameters.mainWithoutArguments(); } - return MainCallParameters.noCall(); } } diff --git a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java index bf4595c1f62..14360d671d7 100644 --- a/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java +++ b/idea/src/org/jetbrains/jet/plugin/compiler/K2JSCompiler.java @@ -48,7 +48,6 @@ import static org.jetbrains.jet.plugin.compiler.CompilerUtils.outputCompilerMess * @author Pavel Talanov */ public final class K2JSCompiler implements TranslatingCompiler { - @Override public boolean isCompilableFile(VirtualFile file, CompileContext context) { if (!(file.getFileType() instanceof JetFileType)) { @@ -130,8 +129,10 @@ public final class K2JSCompiler implements TranslatingCompiler { @NotNull private static String[] constructArguments(@NotNull Module module, @Nullable String outFile) { - ArrayList args = Lists.newArrayList("-tags", "-verbose", "-version", "-mainCall", "mainWithArgs"); - addPathToSourcesDir(module, args); + VirtualFile[] sourceFiles = getSourceFiles(module); + + ArrayList args = Lists.newArrayList("-tags", "-verbose", "-version"); + addPathToSourcesDir(sourceFiles, args); addOutputPath(outFile, args); addLibLocationAndTarget(module, args); return ArrayUtil.toStringArray(args); @@ -204,12 +205,12 @@ public final class K2JSCompiler implements TranslatingCompiler { } } - private static void addPathToSourcesDir(@NotNull Module module, @NotNull ArrayList args) { + private static void addPathToSourcesDir(@NotNull VirtualFile[] sourceFiles, @NotNull ArrayList args) { args.add("-sourceFiles"); StringBuilder sb = StringBuilderSpinAllocator.alloc(); try { - for (VirtualFile file : getSourceFiles(module)) { + for (VirtualFile file : sourceFiles) { sb.append(file.getPath()).append(','); } args.add(sb.substring(0, sb.length() - 1)); diff --git a/js/js.translator/src/org/jetbrains/k2js/facade/MainCallParameters.java b/js/js.translator/src/org/jetbrains/k2js/facade/MainCallParameters.java index d7c5bc8cf73..326d8683868 100644 --- a/js/js.translator/src/org/jetbrains/k2js/facade/MainCallParameters.java +++ b/js/js.translator/src/org/jetbrains/k2js/facade/MainCallParameters.java @@ -25,7 +25,6 @@ import java.util.List; * @author Pavel Talanov */ public abstract class MainCallParameters { - @NotNull public static MainCallParameters noCall() { return new MainCallParameters() { diff --git a/js/js.translator/src/org/jetbrains/k2js/translate/general/Translation.java b/js/js.translator/src/org/jetbrains/k2js/translate/general/Translation.java index 1bc80741eb5..8174b81588d 100644 --- a/js/js.translator/src/org/jetbrains/k2js/translate/general/Translation.java +++ b/js/js.translator/src/org/jetbrains/k2js/translate/general/Translation.java @@ -22,6 +22,7 @@ import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.util.AstUtil; import com.intellij.openapi.util.text.StringUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; @@ -181,7 +182,10 @@ public final class Translation { defineModule(statements, context, config); if (mainCallParameters.shouldBeGenerated()) { - statements.add(generateCallToMain(context, files, mainCallParameters.arguments())); + JsStatement statement = generateCallToMain(context, files, mainCallParameters.arguments()); + if (statement != null) { + statements.add(statement); + } } generateTestCalls(context, files, block, rawStatements); JsNamer namer = new JsPrettyNamer(); @@ -197,12 +201,12 @@ public final class Translation { context.jsScope().declareName("_").makeRef()).makeStmt()); } - @NotNull + @Nullable private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull List files, @NotNull List arguments) throws MainFunctionNotFoundException { JetNamedFunction mainFunction = getMainFunction(files); if (mainFunction == null) { - throw new MainFunctionNotFoundException("Main function was not found. Please check compiler arguments"); + return null; } JsInvocation translatedCall = generateInvocation(context, mainFunction); setArguments(context, arguments, translatedCall);