| 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 import 'span.dart'; | 5 import 'span.dart'; |
| 6 | 6 |
| 7 /// A class for exceptions that have source span information attached. | 7 /// A class for exceptions that have source span information attached. |
| 8 class SourceSpanException implements Exception { | 8 class SourceSpanException implements Exception { |
| 9 // This is a getter so that subclasses can override it. |
| 9 /// A message describing the exception. | 10 /// A message describing the exception. |
| 10 final String message; | 11 String get message => _message; |
| 12 final String _message; |
| 11 | 13 |
| 14 // This is a getter so that subclasses can override it. |
| 12 /// The span associated with this exception. | 15 /// The span associated with this exception. |
| 13 /// | 16 /// |
| 14 /// This may be `null` if the source location can't be determined. | 17 /// This may be `null` if the source location can't be determined. |
| 15 final SourceSpan span; | 18 SourceSpan get span => _span; |
| 19 final SourceSpan _span; |
| 16 | 20 |
| 17 SourceSpanException(this.message, this.span); | 21 SourceSpanException(this._message, this._span); |
| 18 | 22 |
| 19 /// Returns a string representation of [this]. | 23 /// Returns a string representation of [this]. |
| 20 /// | 24 /// |
| 21 /// [color] may either be a [String], a [bool], or `null`. If it's a string, | 25 /// [color] may either be a [String], a [bool], or `null`. If it's a string, |
| 22 /// it indicates an ANSII terminal color escape that should be used to | 26 /// it indicates an ANSII terminal color escape that should be used to |
| 23 /// highlight the span's text. If it's `true`, it indicates that the text | 27 /// highlight the span's text. If it's `true`, it indicates that the text |
| 24 /// should be highlighted using the default color. If it's `false` or `null`, | 28 /// should be highlighted using the default color. If it's `false` or `null`, |
| 25 /// it indicates that the text shouldn't be highlighted. | 29 /// it indicates that the text shouldn't be highlighted. |
| 26 String toString({color}) { | 30 String toString({color}) { |
| 27 if (span == null) return message; | 31 if (span == null) return message; |
| 28 return "Error on " + span.message(message, color: color); | 32 return "Error on " + span.message(message, color: color); |
| 29 } | 33 } |
| 30 } | 34 } |
| 31 | 35 |
| 32 /// A [SourceSpanException] that's also a [FormatException]. | 36 /// A [SourceSpanException] that's also a [FormatException]. |
| 33 class SourceSpanFormatException extends SourceSpanException | 37 class SourceSpanFormatException extends SourceSpanException |
| 34 implements FormatException { | 38 implements FormatException { |
| 39 // This is a getter so that subclasses can override it. |
| 40 dynamic get source => _source; |
| 35 final _source; | 41 final _source; |
| 36 | 42 |
| 37 // Subclasses may narrow the type. | |
| 38 dynamic get source => _source; | |
| 39 | |
| 40 int get offset => span == null ? null : span.start.offset; | 43 int get offset => span == null ? null : span.start.offset; |
| 41 | 44 |
| 42 SourceSpanFormatException(String message, SourceSpan span, [this._source]) | 45 SourceSpanFormatException(String message, SourceSpan span, [this._source]) |
| 43 : super(message, span); | 46 : super(message, span); |
| 44 } | 47 } |
| OLD | NEW |