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 // TODO(nweiz): Use SourceLocationMixin once we decide to cut a release with | 7 // TODO(nweiz): Use SourceLocationMixin once we decide to cut a release with |
8 // breaking changes. See SourceLocationMixin for details. | 8 // breaking changes. See SourceLocationMixin for details. |
9 | 9 |
10 /// A class that describes a single location within a source file. | 10 /// A class that describes a single location within a source file. |
11 /// | 11 /// |
12 /// This class should not be extended. Instead, [SourceLocationBase] should be | 12 /// This class should not be extended. Instead, [SourceLocationBase] should be |
13 /// extended instead. | 13 /// extended instead. |
14 class SourceLocation implements Comparable<SourceLocation> { | 14 class SourceLocation implements Comparable<SourceLocation> { |
15 // These fields go through getters so that subclasses of [SourceLocationBase] | |
16 // can override them. | |
17 | |
15 /// URL of the source containing this location. | 18 /// URL of the source containing this location. |
16 /// | 19 /// |
17 /// This may be null, indicating that the source URL is unknown or | 20 /// This may be null, indicating that the source URL is unknown or |
18 /// unavailable. | 21 /// unavailable. |
19 final Uri sourceUrl; | 22 Uri get sourceUrl => _sourceUrl; |
23 final Uri _sourceUrl; | |
Lasse Reichstein Nielsen
2016/03/01 15:22:42
What does this change?
A field already introduces
nweiz
2016/03/01 19:16:09
Yes, it does. I'll forward you the email thread wh
| |
20 | 24 |
21 /// The 0-based offset of this location in the source. | 25 /// The 0-based offset of this location in the source. |
22 final int offset; | 26 int get offset => _offset; |
27 final int _offset; | |
23 | 28 |
24 /// The 0-based line of this location in the source. | 29 /// The 0-based line of this location in the source. |
25 final int line; | 30 int get line => _line; |
31 final int _line; | |
26 | 32 |
27 /// The 0-based column of this location in the source | 33 /// The 0-based column of this location in the source |
28 final int column; | 34 int get column => _column; |
35 final int _column; | |
29 | 36 |
30 /// Returns a representation of this location in the `source:line:column` | 37 /// Returns a representation of this location in the `source:line:column` |
31 /// format used by text editors. | 38 /// format used by text editors. |
32 /// | 39 /// |
33 /// This prints 1-based lines and columns. | 40 /// This prints 1-based lines and columns. |
34 String get toolString { | 41 String get toolString { |
35 var source = sourceUrl == null ? 'unknown source' : sourceUrl; | 42 var source = sourceUrl == null ? 'unknown source' : sourceUrl; |
36 return '$source:${line + 1}:${column + 1}'; | 43 return '$source:${line + 1}:${column + 1}'; |
37 } | 44 } |
38 | 45 |
39 /// Creates a new location indicating [offset] within [sourceUrl]. | 46 /// Creates a new location indicating [offset] within [sourceUrl]. |
40 /// | 47 /// |
41 /// [line] and [column] default to assuming the source is a single line. This | 48 /// [line] and [column] default to assuming the source is a single line. This |
42 /// means that [line] defaults to 0 and [column] defaults to [offset]. | 49 /// means that [line] defaults to 0 and [column] defaults to [offset]. |
43 /// | 50 /// |
44 /// [sourceUrl] may be either a [String], a [Uri], or `null`. | 51 /// [sourceUrl] may be either a [String], a [Uri], or `null`. |
45 SourceLocation(int offset, {sourceUrl, int line, int column}) | 52 SourceLocation(int offset, {sourceUrl, int line, int column}) |
46 : sourceUrl = sourceUrl is String ? Uri.parse(sourceUrl) : sourceUrl, | 53 : _sourceUrl = sourceUrl is String ? Uri.parse(sourceUrl) : sourceUrl, |
47 offset = offset, | 54 _offset = offset, |
48 line = line == null ? 0 : line, | 55 _line = line == null ? 0 : line, |
49 column = column == null ? offset : column { | 56 _column = column == null ? offset : column { |
50 if (offset < 0) { | 57 if (offset < 0) { |
51 throw new RangeError("Offset may not be negative, was $offset."); | 58 throw new RangeError("Offset may not be negative, was $offset."); |
52 } else if (line != null && line < 0) { | 59 } else if (line != null && line < 0) { |
53 throw new RangeError("Line may not be negative, was $line."); | 60 throw new RangeError("Line may not be negative, was $line."); |
54 } else if (column != null && column < 0) { | 61 } else if (column != null && column < 0) { |
55 throw new RangeError("Column may not be negative, was $column."); | 62 throw new RangeError("Column may not be negative, was $column."); |
56 } | 63 } |
57 } | 64 } |
58 | 65 |
59 /// Returns the distance in characters between [this] and [other]. | 66 /// Returns the distance in characters between [this] and [other]. |
(...skipping 29 matching lines...) Expand all Loading... | |
89 | 96 |
90 String toString() => '<$runtimeType: $offset $toolString>'; | 97 String toString() => '<$runtimeType: $offset $toolString>'; |
91 } | 98 } |
92 | 99 |
93 /// A base class for source locations with [offset], [line], and [column] known | 100 /// A base class for source locations with [offset], [line], and [column] known |
94 /// at construction time. | 101 /// at construction time. |
95 class SourceLocationBase extends SourceLocation { | 102 class SourceLocationBase extends SourceLocation { |
96 SourceLocationBase(int offset, {sourceUrl, int line, int column}) | 103 SourceLocationBase(int offset, {sourceUrl, int line, int column}) |
97 : super(offset, sourceUrl: sourceUrl, line: line, column: column); | 104 : super(offset, sourceUrl: sourceUrl, line: line, column: column); |
98 } | 105 } |
OLD | NEW |