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.file; | 5 library source_span.file; |
6 | 6 |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
9 | 9 |
10 import 'location.dart'; | 10 import 'location.dart'; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 if (other is! _FileSpan) return super.compareTo(other); | 235 if (other is! _FileSpan) return super.compareTo(other); |
236 | 236 |
237 _FileSpan otherFile = other; | 237 _FileSpan otherFile = other; |
238 var result = _start.compareTo(otherFile._start); | 238 var result = _start.compareTo(otherFile._start); |
239 return result == 0 ? _end.compareTo(otherFile._end) : result; | 239 return result == 0 ? _end.compareTo(otherFile._end) : result; |
240 } | 240 } |
241 | 241 |
242 SourceSpan union(SourceSpan other) { | 242 SourceSpan union(SourceSpan other) { |
243 if (other is! FileSpan) return super.union(other); | 243 if (other is! FileSpan) return super.union(other); |
244 | 244 |
| 245 |
245 _FileSpan span = expand(other); | 246 _FileSpan span = expand(other); |
246 var beginSpan = span._start == _start ? this : other; | |
247 var endSpan = span._end == _end ? this : other; | |
248 | 247 |
249 if (beginSpan._end < endSpan._start) { | 248 if (other is _FileSpan) { |
250 throw new ArgumentError("Spans $this and $other are disjoint."); | 249 if (this._start > other._end || other._start > this._end) { |
| 250 throw new ArgumentError("Spans $this and $other are disjoint."); |
| 251 } |
| 252 } else { |
| 253 if (this._start > other.end.offset || other.start.offset > this._end) { |
| 254 throw new ArgumentError("Spans $this and $other are disjoint."); |
| 255 } |
251 } | 256 } |
252 | 257 |
253 return span; | 258 return span; |
254 } | 259 } |
255 | 260 |
256 bool operator ==(other) { | 261 bool operator ==(other) { |
257 if (other is! FileSpan) return super == other; | 262 if (other is! FileSpan) return super == other; |
258 if (other is! _FileSpan) { | 263 if (other is! _FileSpan) { |
259 return super == other && sourceUrl == other.sourceUrl; | 264 return super == other && sourceUrl == other.sourceUrl; |
260 } | 265 } |
(...skipping 16 matching lines...) Expand all Loading... |
277 var start = math.min(this._start, other._start); | 282 var start = math.min(this._start, other._start); |
278 var end = math.max(this._end, other._end); | 283 var end = math.max(this._end, other._end); |
279 return new _FileSpan(file, start, end); | 284 return new _FileSpan(file, start, end); |
280 } else { | 285 } else { |
281 var start = math.min(this._start, other.start.offset); | 286 var start = math.min(this._start, other.start.offset); |
282 var end = math.max(this._end, other.end.offset); | 287 var end = math.max(this._end, other.end.offset); |
283 return new _FileSpan(file, start, end); | 288 return new _FileSpan(file, start, end); |
284 } | 289 } |
285 } | 290 } |
286 } | 291 } |
OLD | NEW |