diff --git a/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/MainFunctionNotFoundException.java b/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/MainFunctionNotFoundException.java new file mode 100644 index 00000000000..fdbe4e5f640 --- /dev/null +++ b/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/MainFunctionNotFoundException.java @@ -0,0 +1,28 @@ +/* + * Copyright 2010-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.k2js.facade.exceptions; + +import org.jetbrains.annotations.NotNull; + +/** + * @author Pavel Talanov + */ +public class MainFunctionNotFoundException extends TranslationException { + public MainFunctionNotFoundException(@NotNull String message) { + super(message); + } +} diff --git a/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/TranslationException.java b/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/TranslationException.java index 54483d8f5ec..82cf86b4911 100644 --- a/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/TranslationException.java +++ b/js/js.translator/src/org/jetbrains/k2js/facade/exceptions/TranslationException.java @@ -23,6 +23,10 @@ import org.jetbrains.annotations.NotNull; */ public class TranslationException extends Exception { + public TranslationException(@NotNull String message) { + super(message); + } + public TranslationException(@NotNull Throwable cause) { super(cause); } 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 94595f723c8..a73256bc3bc 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 @@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.k2js.facade.MainCallParameters; +import org.jetbrains.k2js.facade.exceptions.MainFunctionNotFoundException; import org.jetbrains.k2js.facade.exceptions.TranslationInternalException; import org.jetbrains.k2js.facade.exceptions.TranslationException; import org.jetbrains.k2js.facade.exceptions.UnsupportedFeatureException; @@ -155,7 +156,7 @@ public final class Translation { @NotNull private static JsProgram doGenerateAst(@NotNull BindingContext bindingContext, @NotNull List files, - @NotNull MainCallParameters mainCallParameters) { + @NotNull MainCallParameters mainCallParameters) throws MainFunctionNotFoundException { //TODO: move some of the code somewhere JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance(); StaticContext staticContext = StaticContext.generateStaticContext(standardLibrary, bindingContext); @@ -172,10 +173,11 @@ public final class Translation { @NotNull private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull List files, - @NotNull List arguments) { + @NotNull List arguments) throws MainFunctionNotFoundException { JetNamedFunction mainFunction = getMainFunction(files); - //TODO: throw correct exception - assert mainFunction != null; + if (mainFunction == null) { + throw new MainFunctionNotFoundException("Main function was not found. Please check compiler arguments"); + } JsInvocation translatedCall = generateInvocation(context, mainFunction); setArguments(context, arguments, translatedCall); return translatedCall.makeStmt();