Chromium Code Reviews| Index: pkg/source_span/lib/src/file.dart |
| diff --git a/pkg/source_span/lib/src/file.dart b/pkg/source_span/lib/src/file.dart |
| index 14aa22627fe4747d8e42f9442d9952cbf9c6f00d..4f0b4e6f06279abff1e1f9220b533c5e3da21ba1 100644 |
| --- a/pkg/source_span/lib/src/file.dart |
| +++ b/pkg/source_span/lib/src/file.dart |
| @@ -199,10 +199,11 @@ class FileSpan extends SourceSpanMixin { |
| /// objects. |
| final int _end; |
| + Uri get sourceUrl => file.url; |
| + int get length => _end - _start; |
| FileLocation get start => new FileLocation._(file, _start); |
| FileLocation get end => new FileLocation._(file, _end); |
| - |
| - String get text => file.getText(start.offset, end.offset); |
| + String get text => file.getText(_start, _end); |
| FileSpan._(this.file, this._start, this._end) { |
| if (_end < _start) { |
| @@ -215,20 +216,37 @@ class FileSpan extends SourceSpanMixin { |
| } |
| } |
| + int compareTo(SourceSpan other) { |
| + if (other is! FileSpan) return super.compareTo(other); |
| + |
| + FileSpan otherFile = other; |
| + var d = _start.compareTo(otherFile._start); |
|
Bob Nystrom
2014/11/21 23:38:18
"d" seems random to me. How about "result"?
nweiz
2014/11/21 23:47:31
Done. This is a relic of the old source_maps code.
|
| + return d == 0 ? _end.compareTo(otherFile._end) : d; |
| + } |
| + |
| SourceSpan union(SourceSpan other) { |
|
Bob Nystrom
2014/11/21 23:38:17
Is this an override? If not, doc comment.
nweiz
2014/11/21 23:47:31
Yes, it is.
|
| if (other is! FileSpan) return super.union(other); |
| var span = expand(other); |
| - var beginSpan = span.start == this.start ? this : other; |
| - var endSpan = span.end == this.end ? this : other; |
| + var beginSpan = span._start == _start ? this : other; |
| + var endSpan = span._end == _end ? this : other; |
| - if (beginSpan.end.compareTo(endSpan.start) < 0) { |
| + if (beginSpan._end < endSpan._start) { |
| throw new ArgumentError("Spans $this and $other are disjoint."); |
| } |
| return span; |
| } |
| + bool operator ==(other) { |
| + if (other is! FileSpan) return super == other; |
| + return _start == other._start && _end == other._end && |
| + sourceUrl == other.sourceUrl; |
| + } |
| + |
| + int get hashCode => _start.hashCode + 5 * _end.hashCode + |
| + 7 * sourceUrl.hashCode; |
| + |
| /// Returns a new span that covers both [this] and [other]. |
| /// |
| /// Unlike [union], [other] may be disjoint from [this]. If it is, the text |
| @@ -241,7 +259,7 @@ class FileSpan extends SourceSpanMixin { |
| var start = math.min(this._start, other._start); |
| var end = math.max(this._end, other._end); |
| - return new FileSpan._(file, start, end); |
| + return new FileSpan._(file, start, end); |
| } |
| String message(String message, {color}) { |