Refactor K2JSTranslator facade
Add MainFunctionNotFoundException
This commit is contained in:
+28
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
*/
|
*/
|
||||||
public class TranslationException extends Exception {
|
public class TranslationException extends Exception {
|
||||||
|
|
||||||
|
public TranslationException(@NotNull String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
public TranslationException(@NotNull Throwable cause) {
|
public TranslationException(@NotNull Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
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.TranslationInternalException;
|
||||||
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
import org.jetbrains.k2js.facade.exceptions.TranslationException;
|
||||||
import org.jetbrains.k2js.facade.exceptions.UnsupportedFeatureException;
|
import org.jetbrains.k2js.facade.exceptions.UnsupportedFeatureException;
|
||||||
@@ -155,7 +156,7 @@ public final class Translation {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JsProgram doGenerateAst(@NotNull BindingContext bindingContext, @NotNull List<JetFile> files,
|
private static JsProgram doGenerateAst(@NotNull BindingContext bindingContext, @NotNull List<JetFile> files,
|
||||||
@NotNull MainCallParameters mainCallParameters) {
|
@NotNull MainCallParameters mainCallParameters) throws MainFunctionNotFoundException {
|
||||||
//TODO: move some of the code somewhere
|
//TODO: move some of the code somewhere
|
||||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
StaticContext staticContext = StaticContext.generateStaticContext(standardLibrary, bindingContext);
|
StaticContext staticContext = StaticContext.generateStaticContext(standardLibrary, bindingContext);
|
||||||
@@ -172,10 +173,11 @@ public final class Translation {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull List<JetFile> files,
|
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull List<JetFile> files,
|
||||||
@NotNull List<String> arguments) {
|
@NotNull List<String> arguments) throws MainFunctionNotFoundException {
|
||||||
JetNamedFunction mainFunction = getMainFunction(files);
|
JetNamedFunction mainFunction = getMainFunction(files);
|
||||||
//TODO: throw correct exception
|
if (mainFunction == null) {
|
||||||
assert mainFunction != null;
|
throw new MainFunctionNotFoundException("Main function was not found. Please check compiler arguments");
|
||||||
|
}
|
||||||
JsInvocation translatedCall = generateInvocation(context, mainFunction);
|
JsInvocation translatedCall = generateInvocation(context, mainFunction);
|
||||||
setArguments(context, arguments, translatedCall);
|
setArguments(context, arguments, translatedCall);
|
||||||
return translatedCall.makeStmt();
|
return translatedCall.makeStmt();
|
||||||
|
|||||||
Reference in New Issue
Block a user