| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// Dart classes representing the souce spans and source files. | 5 /// Dart classes representing the souce spans and source files. |
| 6 library source_maps.span; | 6 library source_maps.span; |
| 7 | 7 |
| 8 import 'dart:math' show min, max; | 8 import 'dart:math' show min, max; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 int getOffset(int line, int column) => | 353 int getOffset(int line, int column) => |
| 354 super.getOffset(line - _baseLine, | 354 super.getOffset(line - _baseLine, |
| 355 line == _baseLine ? column - _baseColumn : column) + _baseOffset; | 355 line == _baseLine ? column - _baseColumn : column) + _baseOffset; |
| 356 | 356 |
| 357 /// Retrieve the text associated with the specified range. This method | 357 /// Retrieve the text associated with the specified range. This method |
| 358 /// operates on the real offsets from the original file, so that error | 358 /// operates on the real offsets from the original file, so that error |
| 359 /// messages can be reported accurately. | 359 /// messages can be reported accurately. |
| 360 String getText(int start, [int end]) => | 360 String getText(int start, [int end]) => |
| 361 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); | 361 super.getText(start - _baseOffset, end == null ? null : end - _baseOffset); |
| 362 } | 362 } |
| 363 |
| 364 /// A class for exceptions that have source span information attached. |
| 365 class SpanException implements Exception { |
| 366 /// A message describing the exception. |
| 367 final String message; |
| 368 |
| 369 /// The span associated with this exception. |
| 370 /// |
| 371 /// This may be `null` if the source location can't be determined. |
| 372 final Span span; |
| 373 |
| 374 SpanException(this.message, this.span); |
| 375 |
| 376 String toString({bool useColors: false, String color}) { |
| 377 if (span == null) return message; |
| 378 return span.getLocationMessage(message, useColors: useColors, color: color); |
| 379 } |
| 380 } |
| 381 |
| 382 /// A [SpanException] that's also a [FormatException]. |
| 383 class SpanFormatException extends SpanException implements FormatException { |
| 384 SpanFormatException(String message, Span span) |
| 385 : super(message, span); |
| 386 } |
| OLD | NEW |