From 4f992eeeb4f3e4cbd15ee43055640a00498b2deb Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Thu, 19 Feb 2015 13:53:56 +0300 Subject: [PATCH] JS: report right end of js() error --- .../com/google/gwt/dev/js/rhino/Context.java | 34 ++++--------------- .../gwt/dev/js/rhino/ErrorReporter.java | 24 +++++-------- .../google/gwt/dev/js/rhino/IRFactory.java | 4 +-- .../google/gwt/dev/js/rhino/TokenStream.java | 6 ++-- 4 files changed, 19 insertions(+), 49 deletions(-) diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/Context.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/Context.java index fea153703c3..f515415d1a7 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/Context.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/Context.java @@ -48,6 +48,8 @@ package com.google.gwt.dev.js.rhino; +import org.jetbrains.annotations.NotNull; + import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; @@ -325,42 +327,18 @@ public class Context { return locale; } - /** - * Report a warning using the error reporter for the current thread. - * - * @param message the warning message to report - * @param sourceName a string describing the source, such as a filename - * @param lineno the starting line number - * @param lineSource the text of the line (may be null) - * @param lineOffset the offset into lineSource where problem was detected - */ - public static void reportWarning(String message, String sourceName, - int lineno, String lineSource, - int lineOffset) + public static void reportWarning(@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition) { Context cx = Context.getContext(); - cx.getErrorReporter().warning(message, sourceName, lineno, - lineSource, lineOffset); + cx.getErrorReporter().warning(message, startPosition, endPosition); } - /** - * Report an error using the error reporter for the current thread. - * - * @param message the error message to report - * @param sourceName a string describing the source, such as a filename - * @param lineno the starting line number - * @param lineSource the text of the line (may be null) - * @param lineOffset the offset into lineSource where problem was detected - */ - public static void reportError(String message, String sourceName, - int lineno, String lineSource, - int lineOffset) + public static void reportError(@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition) { Context cx = getCurrentContext(); if (cx != null) { cx.errorCount++; - cx.getErrorReporter().error(message, sourceName, lineno, - lineSource, lineOffset); + cx.getErrorReporter().error(message, startPosition, endPosition); } else { throw new EvaluatorException(message); } diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/ErrorReporter.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/ErrorReporter.java index ba13d40c7d0..7a24e506a2a 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/ErrorReporter.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/ErrorReporter.java @@ -38,6 +38,8 @@ package com.google.gwt.dev.js.rhino; +import org.jetbrains.annotations.NotNull; + /** * This is interface defines a protocol for the reporting of * errors during JavaScript translation or execution. @@ -51,15 +53,11 @@ public interface ErrorReporter { * The implementing class may choose to ignore the warning * if it desires. * - * @param message a String describing the warning - * @param sourceName a String describing the JavaScript source - * where the warning occured; typically a filename or URL - * @param line the line number associated with the warning - * @param lineSource the text of the line (may be null) - * @param lineOffset the offset into lineSource where problem was detected + * @param message a String describing the error + * @param startPosition position before error token + * @param endPosition position after error token */ - void warning(String message, String sourceName, int line, - String lineSource, int lineOffset); + void warning(@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition); /** * Report an error. @@ -73,12 +71,8 @@ public interface ErrorReporter { * errors, however. * * @param message a String describing the error - * @param sourceName a String describing the JavaScript source - * where the error occured; typically a filename or URL - * @param line the line number associated with the error - * @param lineSource the text of the line (may be null) - * @param lineOffset the offset into lineSource where problem was detected + * @param startPosition position before error token + * @param endPosition position after error token */ - void error(String message, String sourceName, int line, - String lineSource, int lineOffset); + void error(@NotNull String message, @NotNull CodePosition startPosition, @NotNull CodePosition endPosition); } diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java index d244c0a780b..f374fe8ae80 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java @@ -407,9 +407,7 @@ public class IRFactory { private void reportError(String msgResource) { String message = Context.getMessage0(msgResource); - Context.reportError( - message, ts.getSourceName(), ts.getLineno(), - ts.getLine(), ts.getOffset()); + ts.reportSyntaxError(message, null); } // Only needed to get file/line information. Could create an interface diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/TokenStream.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/TokenStream.java index ebe0f6a5612..939f07eb621 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/TokenStream.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/TokenStream.java @@ -1419,7 +1419,7 @@ public class TokenStream { */ public void reportSyntaxError(String messageProperty, Object[] args) { String message = Context.getMessage(messageProperty, args); - Context.reportError(message, getSourceName(), secondToLastPosition.getLine(), getLine(), secondToLastPosition.getOffset()); + Context.reportError(message, secondToLastPosition, lastPosition); } /** @@ -1429,12 +1429,12 @@ public class TokenStream { */ private void reportTokenError(String messageProperty, Object[] args) { String message = Context.getMessage(messageProperty, args); - Context.reportError(message, getSourceName(), lastPosition.getLine(), getLine(), lastPosition.getOffset()); + Context.reportError(message, lastPosition, new CodePosition(getLineno(), getOffset())); } private void reportTokenWarning(String messageProperty, Object[] args) { String message = Context.getMessage(messageProperty, args); - Context.reportWarning(message, getSourceName(), lastPosition.getLine(), getLine(), lastPosition.getOffset()); + Context.reportWarning(message, lastPosition, new CodePosition(getLineno(), getOffset())); } /**