diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsCallChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsCallChecker.kt
index 07a4264aa0e..1679d381ffe 100644
--- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsCallChecker.kt
+++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsCallChecker.kt
@@ -16,7 +16,7 @@
package org.jetbrains.kotlin.resolve.diagnostics
-import com.google.gwt.dev.js.AbortParsingException
+import com.google.gwt.dev.js.parserExceptions.AbortParsingException
import com.google.gwt.dev.js.rhino.*
import com.google.gwt.dev.js.rhino.Utils.*
import org.jetbrains.annotations.TestOnly
diff --git a/js/js.parser/src/com/google/gwt/dev/js/JsParser.java b/js/js.parser/src/com/google/gwt/dev/js/JsParser.java
index 13b90612d8d..b99ee9fa3c2 100644
--- a/js/js.parser/src/com/google/gwt/dev/js/JsParser.java
+++ b/js/js.parser/src/com/google/gwt/dev/js/JsParser.java
@@ -18,6 +18,7 @@ package com.google.gwt.dev.js;
import com.google.dart.compiler.backend.js.ast.*;
import com.google.dart.compiler.backend.js.ast.JsLiteral.JsBooleanLiteral;
import com.google.dart.compiler.common.SourceInfo;
+import com.google.gwt.dev.js.parserExceptions.JsParserException;
import com.google.gwt.dev.js.rhino.*;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
@@ -26,7 +27,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
import java.util.Stack;
@@ -86,7 +86,8 @@ public class JsParser {
}
private static JsParserException createParserException(String msg, Node offender) {
- return new JsParserException(msg, offender.getLineno(), null, 0, SOURCE_NAME_STUB);
+ CodePosition position = new CodePosition(offender.getLineno(), 0);
+ return new JsParserException("Parser encountered internal error: " + msg, position);
}
private JsScope getScope() {
diff --git a/js/js.parser/src/com/google/gwt/dev/js/JsParserException.java b/js/js.parser/src/com/google/gwt/dev/js/JsParserException.java
deleted file mode 100644
index 1c42668e9fe..00000000000
--- a/js/js.parser/src/com/google/gwt/dev/js/JsParserException.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2007 Google Inc.
- *
- * 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;
-
-/**
- * Indicates inability to parse JavaScript source.
- */
-public class JsParserException extends Exception {
-
- /**
- * Represents the location of a parser exception.
- */
- public static class SourceDetail {
- private final String fileName;
- private final int line;
- private final int lineOffset;
- private final String lineSource;
-
- public SourceDetail(int line, String lineSource, int lineOffset,
- String fileName) {
- this.line = line;
- this.lineSource = lineSource;
- this.lineOffset = lineOffset;
- this.fileName = fileName;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public int getLine() {
- return line;
- }
-
- public int getLineOffset() {
- return lineOffset;
- }
-
- public String getLineSource() {
- return lineSource;
- }
- }
-
- private static String createMessageWithDetail(String msg,
- SourceDetail sourceDetail) {
- if (sourceDetail == null) {
- return msg;
- }
- StringBuffer sb = new StringBuffer();
- sb.append(sourceDetail.getFileName());
- sb.append('(');
- sb.append(sourceDetail.getLine());
- sb.append(')');
- sb.append(": ");
- sb.append(msg);
- if (sourceDetail.getLineSource() != null) {
- sb.append("\n> ");
- sb.append(sourceDetail.getLineSource());
- sb.append("\n> ");
- for (int i = 0, n = sourceDetail.getLineOffset(); i < n; ++i) {
- sb.append('-');
- }
- sb.append('^');
- }
- return sb.toString();
- }
-
- private final SourceDetail sourceDetail;
-
- public JsParserException(String msg) {
- this(msg, null);
- }
-
- public JsParserException(String msg, int line, String lineSource,
- int lineOffset, String fileName) {
- this(msg, new SourceDetail(line, lineSource, lineOffset, fileName));
- }
-
- public JsParserException(String msg, SourceDetail sourceDetail) {
- super(createMessageWithDetail(msg, sourceDetail));
- this.sourceDetail = sourceDetail;
- }
-
- /**
- * Provides additional source detail in some cases.
- *
- * @return additional detail regarding the error, or null if no
- * additional detail is available
- */
- public SourceDetail getSourceDetail() {
- return sourceDetail;
- }
-}
diff --git a/js/js.parser/src/com/google/gwt/dev/js/AbortParsingException.java b/js/js.parser/src/com/google/gwt/dev/js/parserExceptions/parserExceptions.kt
similarity index 64%
rename from js/js.parser/src/com/google/gwt/dev/js/AbortParsingException.java
rename to js/js.parser/src/com/google/gwt/dev/js/parserExceptions/parserExceptions.kt
index 666adce3fde..e5b46014602 100644
--- a/js/js.parser/src/com/google/gwt/dev/js/AbortParsingException.java
+++ b/js/js.parser/src/com/google/gwt/dev/js/parserExceptions/parserExceptions.kt
@@ -13,11 +13,16 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.google.gwt.dev.js;
+package com.google.gwt.dev.js.parserExceptions
+
+import com.google.gwt.dev.js.rhino.CodePosition
/**
- * Used only to exit parser on error
+ * Can be used in Error reporter to exit parser
*/
-public class AbortParsingException extends RuntimeException {
- public AbortParsingException() {}
-}
+public class AbortParsingException : RuntimeException()
+
+public class JsParserException(
+ message: String,
+ val position: CodePosition
+) : RuntimeException("$message at $position")
\ No newline at end of file
diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/CodePosition.kt b/js/js.parser/src/com/google/gwt/dev/js/rhino/CodePosition.kt
index 7184605456f..3c432a0f680 100644
--- a/js/js.parser/src/com/google/gwt/dev/js/rhino/CodePosition.kt
+++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/CodePosition.kt
@@ -23,4 +23,6 @@ class CodePosition(val line: Int, val offset: Int) : Comparable {
line > other.line -> 1
else -> offset.compareTo(other.offset)
}
+
+ override fun toString(): String = "($line, $offset)"
}