OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 dart2js.source_information; | 5 library dart2js.source_information; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../elements/elements.dart' show | 8 import '../elements/elements.dart' show AstElement, LocalElement; |
9 AstElement, | 9 import '../tree/tree.dart' show Node, Send; |
10 LocalElement; | 10 import '../js/js.dart' show JavaScriptNodeSourceInformation; |
11 import '../tree/tree.dart' show | |
12 Node, | |
13 Send; | |
14 import '../js/js.dart' show | |
15 JavaScriptNodeSourceInformation; | |
16 import 'source_file.dart'; | 11 import 'source_file.dart'; |
17 | 12 |
18 /// Interface for passing source information, for instance for use in source | 13 /// Interface for passing source information, for instance for use in source |
19 /// maps, through the backend. | 14 /// maps, through the backend. |
20 abstract class SourceInformation extends JavaScriptNodeSourceInformation { | 15 abstract class SourceInformation extends JavaScriptNodeSourceInformation { |
21 const SourceInformation(); | 16 const SourceInformation(); |
22 | 17 |
23 SourceSpan get sourceSpan; | 18 SourceSpan get sourceSpan; |
24 | 19 |
25 /// The source location associated with the start of the JS node. | 20 /// The source location associated with the start of the JS node. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 int get column => _sourceFile.getColumn(line, offset); | 169 int get column => _sourceFile.getColumn(line, offset); |
175 | 170 |
176 /// The name associated with this source location, if any. | 171 /// The name associated with this source location, if any. |
177 String get sourceName; | 172 String get sourceName; |
178 | 173 |
179 /// `true` if the offset within the length of the source file. | 174 /// `true` if the offset within the length of the source file. |
180 bool get isValid => offset < _sourceFile.length; | 175 bool get isValid => offset < _sourceFile.length; |
181 | 176 |
182 int get hashCode { | 177 int get hashCode { |
183 return sourceUri.hashCode * 17 + | 178 return sourceUri.hashCode * 17 + |
184 offset.hashCode * 17 + | 179 offset.hashCode * 17 + |
185 sourceName.hashCode * 23; | 180 sourceName.hashCode * 23; |
186 } | 181 } |
187 | 182 |
188 bool operator ==(other) { | 183 bool operator ==(other) { |
189 if (identical(this, other)) return true; | 184 if (identical(this, other)) return true; |
190 if (other is! SourceLocation) return false; | 185 if (other is! SourceLocation) return false; |
191 return sourceUri == other.sourceUri && | 186 return sourceUri == other.sourceUri && |
192 offset == other.offset && | 187 offset == other.offset && |
193 sourceName == other.sourceName; | 188 sourceName == other.sourceName; |
194 } | 189 } |
195 | 190 |
196 String get shortText { | 191 String get shortText { |
197 // Use 1-based line/column info to match usual dart tool output. | 192 // Use 1-based line/column info to match usual dart tool output. |
198 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]'; | 193 return '${sourceUri.pathSegments.last}:[${line + 1},${column + 1}]'; |
199 } | 194 } |
200 | 195 |
201 String toString() { | 196 String toString() { |
202 // Use 1-based line/column info to match usual dart tool output. | 197 // Use 1-based line/column info to match usual dart tool output. |
203 return '${sourceUri}:[${line + 1},${column + 1}]'; | 198 return '${sourceUri}:[${line + 1},${column + 1}]'; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return '${computeElementNameForSourceMaps(local.executableContext)}.$name'; | 236 return '${computeElementNameForSourceMaps(local.executableContext)}.$name'; |
242 } else if (element.enclosingClass != null) { | 237 } else if (element.enclosingClass != null) { |
243 if (element.enclosingClass.isClosure) { | 238 if (element.enclosingClass.isClosure) { |
244 return computeElementNameForSourceMaps(element.enclosingClass); | 239 return computeElementNameForSourceMaps(element.enclosingClass); |
245 } | 240 } |
246 return '${element.enclosingClass.name}.${element.name}'; | 241 return '${element.enclosingClass.name}.${element.name}'; |
247 } else { | 242 } else { |
248 return element.name; | 243 return element.name; |
249 } | 244 } |
250 } | 245 } |
OLD | NEW |