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 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 final int _end; | 200 final int _end; |
201 | 201 |
202 FileLocation get start => new FileLocation._(file, _start); | 202 FileLocation get start => new FileLocation._(file, _start); |
203 FileLocation get end => new FileLocation._(file, _end); | 203 FileLocation get end => new FileLocation._(file, _end); |
204 | 204 |
205 String get text => file.getText(start.offset, end.offset); | 205 String get text => file.getText(start.offset, end.offset); |
206 | 206 |
207 FileSpan._(this.file, this._start, this._end) { | 207 FileSpan._(this.file, this._start, this._end) { |
208 if (_end < _start) { | 208 if (_end < _start) { |
209 throw new ArgumentError('End $_end must come after start $_start.'); | 209 throw new ArgumentError('End $_end must come after start $_start.'); |
| 210 } else if (_end > file.length) { |
| 211 throw new RangeError("End $_end must not be greater than the number " |
| 212 "of characters in the file, ${file.length}."); |
| 213 } else if (_start < 0) { |
| 214 throw new RangeError("Start may not be negative, was $_start."); |
210 } | 215 } |
211 } | 216 } |
212 | 217 |
213 SourceSpan union(SourceSpan other) { | 218 SourceSpan union(SourceSpan other) { |
214 if (other is! FileSpan) return super.union(other); | 219 if (other is! FileSpan) return super.union(other); |
215 | 220 |
216 var span = expand(other); | 221 var span = expand(other); |
217 var beginSpan = span.start == this.start ? this : other; | 222 var beginSpan = span.start == this.start ? this : other; |
218 var endSpan = span.end == this.end ? this : other; | 223 var endSpan = span.end == this.end ? this : other; |
219 | 224 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 274 } |
270 if (!textLine.endsWith('\n')) buffer.write('\n'); | 275 if (!textLine.endsWith('\n')) buffer.write('\n'); |
271 | 276 |
272 buffer.write(' ' * column); | 277 buffer.write(' ' * column); |
273 if (color != null) buffer.write(color); | 278 if (color != null) buffer.write(color); |
274 buffer.write('^' * math.max(toColumn - column, 1)); | 279 buffer.write('^' * math.max(toColumn - column, 1)); |
275 if (color != null) buffer.write(colors.NONE); | 280 if (color != null) buffer.write(colors.NONE); |
276 return buffer.toString(); | 281 return buffer.toString(); |
277 } | 282 } |
278 } | 283 } |
OLD | NEW |