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..ed5f6a8371226ed65065789a6ec8ee043701426f 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 result = _start.compareTo(otherFile._start); |
+ return result == 0 ? _end.compareTo(otherFile._end) : result; |
+ } |
+ |
SourceSpan union(SourceSpan other) { |
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}) { |