From ae970044e24f1c9a6cd3d032c3d8558a5c04f228 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Fri, 20 Feb 2015 13:15:35 +0300 Subject: [PATCH] JS: extracted ThrowExceptionReporter --- .../gwt/dev/js/ThrowExceptionReporter.kt | 27 ++++++++++++++++++ .../reference/CallExpressionTranslator.java | 28 ++----------------- 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 js/js.parser/src/com/google/gwt/dev/js/ThrowExceptionReporter.kt diff --git a/js/js.parser/src/com/google/gwt/dev/js/ThrowExceptionReporter.kt b/js/js.parser/src/com/google/gwt/dev/js/ThrowExceptionReporter.kt new file mode 100644 index 00000000000..8b2121f9dac --- /dev/null +++ b/js/js.parser/src/com/google/gwt/dev/js/ThrowExceptionReporter.kt @@ -0,0 +1,27 @@ +/* + * 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 com.google.gwt.dev.js + +import com.google.gwt.dev.js.rhino.* +import com.google.gwt.dev.js.parserExceptions.* + +public object ThrowExceptionOnErrorReporter : ErrorReporter { + override fun warning(message: String, startPosition: CodePosition, endPosition: CodePosition) {} + + override fun error(message: String, startPosition: CodePosition, endPosition: CodePosition) = + throw JsParserException(message, startPosition) +} \ No newline at end of file diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java index e15cfcff88f..65c03c79778 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/reference/CallExpressionTranslator.java @@ -19,11 +19,8 @@ package org.jetbrains.kotlin.js.translate.reference; import com.google.dart.compiler.backend.js.ast.*; import com.google.dart.compiler.backend.js.ast.metadata.MetadataPackage; import com.google.dart.compiler.common.SourceInfoImpl; -import com.google.gwt.dev.js.AbortParsingException; import com.google.gwt.dev.js.JsParser; -import com.google.gwt.dev.js.JsParserException; -import com.google.gwt.dev.js.rhino.CodePosition; -import com.google.gwt.dev.js.rhino.ErrorReporter; +import com.google.gwt.dev.js.ThrowExceptionOnErrorReporter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.builtins.InlineStrategy; @@ -48,7 +45,6 @@ import org.jetbrains.kotlin.types.JetType; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import static org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage.getFunctionResolvedCallWithAssert; @@ -153,32 +149,12 @@ public final class CallExpressionTranslator extends AbstractCallExpressionTransl assert jsCode != null: jsCodeExpression.toString(); List statements = new ArrayList(); - ErrorReporter errorReporter = new ErrorReporter() { - @Override - public void warning( - @NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition - ) { - - } - - @Override - public void error( - @NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition - ) { - throw new IllegalStateException("JS parser error in backend (must have been checked in frontend): " + message); - } - }; try { SourceInfoImpl info = new SourceInfoImpl(null, 0, 0, 0, 0); JsScope scope = context().scope(); StringReader reader = new StringReader(jsCode); - statements.addAll(JsParser.parse(info, scope, reader, errorReporter, /* insideFunction= */ true)); - } catch (AbortParsingException e) { - /** @see JsCodeErrorReporter#error */ - return Collections.emptyList(); - } catch (JsParserException e) { - throw new RuntimeException(e); + statements.addAll(JsParser.parse(info, scope, reader, ThrowExceptionOnErrorReporter.INSTANCE$, /* insideFunction= */ true)); } catch (IOException e) { throw new RuntimeException(e); }