JS: report right end of js() error

This commit is contained in:
Alexey Tsvetkov
2015-02-19 13:53:56 +03:00
parent 05ef358177
commit 4f992eeeb4
4 changed files with 19 additions and 49 deletions
@@ -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);
}
@@ -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);
}
@@ -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
@@ -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()));
}
/**