| Index: compiler/java/com/google/dart/compiler/DartCompilationError.java
|
| diff --git a/compiler/java/com/google/dart/compiler/DartCompilationError.java b/compiler/java/com/google/dart/compiler/DartCompilationError.java
|
| index 3cb1f411cdbb26301e9aa4dac1d7bd8cf41d5a62..c77a09dda1afb85be4f8fd8f069cd1653c77bf13 100644
|
| --- a/compiler/java/com/google/dart/compiler/DartCompilationError.java
|
| +++ b/compiler/java/com/google/dart/compiler/DartCompilationError.java
|
| @@ -4,38 +4,36 @@
|
|
|
| package com.google.dart.compiler;
|
|
|
| +import com.google.dart.compiler.common.HasSourceInfo;
|
| import com.google.dart.compiler.common.SourceInfo;
|
| import com.google.dart.compiler.parser.DartScanner.Location;
|
| import com.google.dart.compiler.parser.DartScanner.Position;
|
|
|
| /**
|
| * Information about a compilation error.
|
| - *
|
| + *
|
| * @see DartCompilerListener
|
| */
|
| public class DartCompilationError {
|
|
|
| /**
|
| - * The character offset from the beginning of the source (zero based) where
|
| - * the error occurred.
|
| + * The character offset from the beginning of the source (zero based) where the error occurred.
|
| */
|
| - private int startPosition = 0;
|
| + private int offset = 0;
|
|
|
| /**
|
| - * The number of characters from the startPosition to the end of the source
|
| - * which encompasses the compilation error.
|
| + * The number of characters from the startPosition to the end of the source which encompasses the
|
| + * compilation error.
|
| */
|
| private int length = 0;
|
|
|
| /**
|
| - * The line number in the source (one based) where the error occurred or -1 if
|
| - * it is undefined.
|
| + * The line number in the source (one based) where the error occurred or -1 if it is undefined.
|
| */
|
| private int lineNumber = -1;
|
|
|
| /**
|
| - * The column number in the source (one based) where the error occurred or -1
|
| - * if it is undefined.
|
| + * The column number in the source (one based) where the error occurred or -1 if it is undefined.
|
| */
|
| private int columnNumber = -1;
|
|
|
| @@ -55,10 +53,10 @@ public class DartCompilationError {
|
| private Source source;
|
|
|
| /**
|
| - * Instantiate a new instance representing an error for the specified {@link Source}.
|
| - *
|
| + * Compilation error for the specified {@link Source}, without location.
|
| + *
|
| * @param source the {@link Source} for which the exception occurred
|
| - * @param errorCode the error code to be associated with this error
|
| + * @param errorCode the {@link ErrorCode} to be associated with this error
|
| * @param arguments the arguments used to build the error message
|
| */
|
| public DartCompilationError(Source source, ErrorCode errorCode, Object... arguments) {
|
| @@ -68,44 +66,58 @@ public class DartCompilationError {
|
| }
|
|
|
| /**
|
| - * Instantiate a new instance representing a compilation error at the specified location.
|
| - *
|
| - * @param location the source range where the error occurred
|
| - * @param errorCode the error code to be associated with this error
|
| + * Compilation error at the {@link SourceInfo} from specified {@link HasSourceInfo}.
|
| + *
|
| + * @param hasSourceInfo the provider of {@link SourceInfo} where the error occurred
|
| + * @param errorCode the {@link ErrorCode} to be associated with this error
|
| + * @param arguments the arguments used to build the error message
|
| + */
|
| + public DartCompilationError(HasSourceInfo hasSourceInfo, ErrorCode errorCode, Object... arguments) {
|
| + this(hasSourceInfo.getSourceInfo(), errorCode, arguments);
|
| + }
|
| +
|
| + /**
|
| + * Compilation error at the specified {@link SourceInfo}.
|
| + *
|
| + * @param sourceInfo the {@link SourceInfo} where the error occurred
|
| + * @param errorCode the {@link ErrorCode} to be associated with this error
|
| * @param arguments the arguments used to build the error message
|
| */
|
| - public DartCompilationError(SourceInfo location, ErrorCode errorCode, Object... arguments) {
|
| - this.source = location.getSource();
|
| - this.lineNumber = location.getSourceLine();
|
| - this.columnNumber = location.getSourceColumn();
|
| - this.startPosition = location.getSourceStart();
|
| - this.length = location.getSourceLength();
|
| + public DartCompilationError(SourceInfo sourceInfo, ErrorCode errorCode, Object... arguments) {
|
| + this.source = sourceInfo.getSource();
|
| + this.lineNumber = sourceInfo.getLine();
|
| + this.columnNumber = sourceInfo.getColumn();
|
| + this.offset = sourceInfo.getOffset();
|
| + this.length = sourceInfo.getLength();
|
| this.errorCode = errorCode;
|
| this.message = String.format(errorCode.getMessage(), arguments);
|
| }
|
|
|
| /**
|
| * Instantiate a new instance representing a compilation error at the specified location.
|
| - *
|
| + *
|
| * @param source the source reference
|
| * @param location the source range where the error occurred
|
| * @param errorCode the error code to be associated with this error
|
| * @param arguments the arguments used to build the error message
|
| */
|
| - public DartCompilationError(Source source, Location location, ErrorCode errorCode, Object... arguments) {
|
| + public DartCompilationError(Source source,
|
| + Location location,
|
| + ErrorCode errorCode,
|
| + Object... arguments) {
|
| this.source = source;
|
| this.errorCode = errorCode;
|
| this.message = String.format(errorCode.getMessage(), arguments);
|
| if (location != null) {
|
| Position begin = location.getBegin();
|
| if (begin != null) {
|
| - startPosition = begin.getPos();
|
| + offset = begin.getPos();
|
| lineNumber = begin.getLine();
|
| columnNumber = begin.getCol();
|
| }
|
| Position end = location.getEnd();
|
| if (end != null) {
|
| - length = end.getPos() - startPosition;
|
| + length = end.getPos() - offset;
|
| if (length < 0) {
|
| length = 0;
|
| }
|
| @@ -142,19 +154,17 @@ public class DartCompilationError {
|
| }
|
|
|
| /**
|
| - * Return the source in which the error occurred or <code>null</code> if
|
| - * unknown.
|
| + * Return the source in which the error occurred or <code>null</code> if unknown.
|
| */
|
| public Source getSource() {
|
| return source;
|
| }
|
|
|
| /**
|
| - * The character offset from the beginning of the source (zero based) where
|
| - * the error occurred.
|
| + * The character offset from the beginning of the source (zero based) where the error occurred.
|
| */
|
| public int getStartPosition() {
|
| - return startPosition;
|
| + return offset;
|
| }
|
|
|
| /**
|
| @@ -166,7 +176,7 @@ public class DartCompilationError {
|
|
|
| @Override
|
| public int hashCode() {
|
| - int hashCode = startPosition;
|
| + int hashCode = offset;
|
| hashCode ^= (message != null) ? message.hashCode() : 0;
|
| hashCode ^= (source != null) ? source.getName().hashCode() : 0;
|
| return hashCode;
|
| @@ -186,5 +196,5 @@ public class DartCompilationError {
|
| sb.append("(" + lineNumber + ":" + columnNumber + "): ");
|
| sb.append(message);
|
| return sb.toString();
|
| - }
|
| + }
|
| }
|
|
|