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 'location.dart'; | 5 import 'location.dart'; |
6 import 'span_mixin.dart'; | 6 import 'span_mixin.dart'; |
7 | 7 |
8 /// A class that describes a segment of source text. | 8 /// A class that describes a segment of source text. |
9 abstract class SourceSpan implements Comparable<SourceSpan> { | 9 abstract class SourceSpan implements Comparable<SourceSpan> { |
10 /// The start location of this span. | 10 /// The start location of this span. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 /// it indicates an ANSII terminal color escape that should be used to | 51 /// it indicates an ANSII terminal color escape that should be used to |
52 /// highlight the span's text. If it's `true`, it indicates that the text | 52 /// highlight the span's text. If it's `true`, it indicates that the text |
53 /// should be highlighted using the default color. If it's `false` or `null`, | 53 /// should be highlighted using the default color. If it's `false` or `null`, |
54 /// it indicates that the text shouldn't be highlighted. | 54 /// it indicates that the text shouldn't be highlighted. |
55 String message(String message, {color}); | 55 String message(String message, {color}); |
56 } | 56 } |
57 | 57 |
58 /// A base class for source spans with [start], [end], and [text] known at | 58 /// A base class for source spans with [start], [end], and [text] known at |
59 /// construction time. | 59 /// construction time. |
60 class SourceSpanBase extends SourceSpanMixin { | 60 class SourceSpanBase extends SourceSpanMixin { |
61 final SourceLocation start; | 61 // These fields go through getters so that subclasses can override them. |
62 final SourceLocation end; | |
63 final String text; | |
64 | 62 |
65 SourceSpanBase(this.start, this.end, this.text) { | 63 SourceLocation get start => _start; |
| 64 final SourceLocation _start; |
| 65 |
| 66 SourceLocation get end => _end; |
| 67 final SourceLocation _end; |
| 68 |
| 69 String get text => _text; |
| 70 final String _text; |
| 71 |
| 72 SourceSpanBase(this._start, this._end, this._text) { |
66 if (end.sourceUrl != start.sourceUrl) { | 73 if (end.sourceUrl != start.sourceUrl) { |
67 throw new ArgumentError("Source URLs \"${start.sourceUrl}\" and " | 74 throw new ArgumentError("Source URLs \"${start.sourceUrl}\" and " |
68 " \"${end.sourceUrl}\" don't match."); | 75 " \"${end.sourceUrl}\" don't match."); |
69 } else if (end.offset < start.offset) { | 76 } else if (end.offset < start.offset) { |
70 throw new ArgumentError('End $end must come after start $start.'); | 77 throw new ArgumentError('End $end must come after start $start.'); |
71 } else if (text.length != start.distance(end)) { | 78 } else if (text.length != start.distance(end)) { |
72 throw new ArgumentError('Text "$text" must be ${start.distance(end)} ' | 79 throw new ArgumentError('Text "$text" must be ${start.distance(end)} ' |
73 'characters long.'); | 80 'characters long.'); |
74 } | 81 } |
75 } | 82 } |
76 } | 83 } |
OLD | NEW |