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