| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library source_span.location; | 5 library source_span.location; |
| 6 | 6 |
| 7 import 'span.dart'; | 7 import 'span.dart'; |
| 8 | 8 |
| 9 // A class that describes a single location within a source file. | 9 // A class that describes a single location within a source file. |
| 10 class SourceLocation implements Comparable<SourceLocation> { | 10 class SourceLocation implements Comparable<SourceLocation> { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 /// | 36 /// |
| 37 /// [line] and [column] default to assuming the source is a single line. This | 37 /// [line] and [column] default to assuming the source is a single line. This |
| 38 /// means that [line] defaults to 0 and [column] defaults to [offset]. | 38 /// means that [line] defaults to 0 and [column] defaults to [offset]. |
| 39 /// | 39 /// |
| 40 /// [sourceUrl] may be either a [String], a [Uri], or `null`. | 40 /// [sourceUrl] may be either a [String], a [Uri], or `null`. |
| 41 SourceLocation(int offset, {sourceUrl, int line, int column}) | 41 SourceLocation(int offset, {sourceUrl, int line, int column}) |
| 42 : sourceUrl = sourceUrl is String ? Uri.parse(sourceUrl) : sourceUrl, | 42 : sourceUrl = sourceUrl is String ? Uri.parse(sourceUrl) : sourceUrl, |
| 43 offset = offset, | 43 offset = offset, |
| 44 line = line == null ? 0 : line, | 44 line = line == null ? 0 : line, |
| 45 column = column == null ? offset : column { | 45 column = column == null ? offset : column { |
| 46 if (this.offset < 0) { | 46 if (offset < 0) { |
| 47 throw new RangeError("Offset may not be negative, was ${this.offset}."); | 47 throw new RangeError("Offset may not be negative, was $offset."); |
| 48 } else if (this.line < 0) { | 48 } else if (line != null && line < 0) { |
| 49 throw new RangeError("Line may not be negative, was ${this.line}."); | 49 throw new RangeError("Line may not be negative, was $line."); |
| 50 } else if (this.column < 0) { | 50 } else if (column != null && column < 0) { |
| 51 throw new RangeError("Column may not be negative, was ${this.column}."); | 51 throw new RangeError("Column may not be negative, was $column."); |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 | 54 |
| 55 /// Returns the distance in characters between [this] and [other]. | 55 /// Returns the distance in characters between [this] and [other]. |
| 56 /// | 56 /// |
| 57 /// This always returns a non-negative value. | 57 /// This always returns a non-negative value. |
| 58 int distance(SourceLocation other) { | 58 int distance(SourceLocation other) { |
| 59 if (sourceUrl != other.sourceUrl) { | 59 if (sourceUrl != other.sourceUrl) { |
| 60 throw new ArgumentError("Source URLs \"${sourceUrl}\" and " | 60 throw new ArgumentError("Source URLs \"${sourceUrl}\" and " |
| 61 "\"${other.sourceUrl}\" don't match."); | 61 "\"${other.sourceUrl}\" don't match."); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool operator ==(other) => | 80 bool operator ==(other) => |
| 81 other is SourceLocation && sourceUrl == other.sourceUrl && | 81 other is SourceLocation && sourceUrl == other.sourceUrl && |
| 82 offset == other.offset; | 82 offset == other.offset; |
| 83 | 83 |
| 84 int get hashCode => sourceUrl.hashCode + offset; | 84 int get hashCode => sourceUrl.hashCode + offset; |
| 85 | 85 |
| 86 String toString() => '<$runtimeType: $offset $toolString>'; | 86 String toString() => '<$runtimeType: $offset $toolString>'; |
| 87 } | 87 } |
| OLD | NEW |