OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.mirrors; | 5 library dart2js.mirrors; |
6 | 6 |
7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView; | 7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView; |
8 | 8 |
9 import '../compiler.dart' show | 9 import '../compiler.dart' show |
10 Compiler; | 10 Compiler; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 var members = <Dart2JsMemberMirror>[]; | 128 var members = <Dart2JsMemberMirror>[]; |
129 AbstractFieldElement field = element; | 129 AbstractFieldElement field = element; |
130 if (field.getter != null) { | 130 if (field.getter != null) { |
131 members.add(new Dart2JsMethodMirror(this, field.getter)); | 131 members.add(new Dart2JsMethodMirror(this, field.getter)); |
132 } | 132 } |
133 if (field.setter != null) { | 133 if (field.setter != null) { |
134 members.add(new Dart2JsMethodMirror(this, field.setter)); | 134 members.add(new Dart2JsMethodMirror(this, field.setter)); |
135 } | 135 } |
136 return members; | 136 return members; |
137 } | 137 } |
138 mirrorSystem.compiler.internalError(element, | 138 mirrorSystem.compiler.reporter.internalError(element, |
139 "Unexpected member type $element ${element.kind}."); | 139 "Unexpected member type $element ${element.kind}."); |
140 return null; | 140 return null; |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { | 144 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
145 final Dart2JsMirrorSystem mirrorSystem; | 145 final Dart2JsMirrorSystem mirrorSystem; |
146 final Element _element; | 146 final Element _element; |
147 List<InstanceMirror> _metadata; | 147 List<InstanceMirror> _metadata; |
148 | 148 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 Script getScript() => _element.compilationUnit.script; | 201 Script getScript() => _element.compilationUnit.script; |
202 | 202 |
203 SourceLocation get location { | 203 SourceLocation get location { |
204 Token beginToken = getFirstToken(); | 204 Token beginToken = getFirstToken(); |
205 Script script = getScript(); | 205 Script script = getScript(); |
206 SourceSpan span; | 206 SourceSpan span; |
207 if (beginToken == null) { | 207 if (beginToken == null) { |
208 span = new SourceSpan(script.resourceUri, 0, 0); | 208 span = new SourceSpan(script.resourceUri, 0, 0); |
209 } else { | 209 } else { |
210 Token endToken = getEndToken(); | 210 Token endToken = getEndToken(); |
211 span = mirrorSystem.compiler.spanFromTokens( | 211 span = new SourceSpan.fromTokens( |
212 beginToken, endToken, script.resourceUri); | 212 script.resourceUri, beginToken, endToken); |
213 } | 213 } |
214 return new Dart2JsSourceLocation(script, span); | 214 return new Dart2JsSourceLocation(script, span); |
215 } | 215 } |
216 | 216 |
217 String toString() => _element.toString(); | 217 String toString() => _element.toString(); |
218 | 218 |
219 void _appendCommentTokens(Token commentToken) { | 219 void _appendCommentTokens(Token commentToken) { |
220 while (commentToken != null && commentToken.kind == Tokens.COMMENT_TOKEN) { | 220 while (commentToken != null && commentToken.kind == Tokens.COMMENT_TOKEN) { |
221 _metadata.add(new Dart2JsCommentInstanceMirror( | 221 _metadata.add(new Dart2JsCommentInstanceMirror( |
222 mirrorSystem, commentToken.value)); | 222 mirrorSystem, commentToken.value)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return new Dart2JsFunctionTypeMirror(this, type); | 341 return new Dart2JsFunctionTypeMirror(this, type); |
342 } else if (type is VoidType) { | 342 } else if (type is VoidType) { |
343 return new Dart2JsVoidMirror(this, type); | 343 return new Dart2JsVoidMirror(this, type); |
344 } else if (type is TypedefType) { | 344 } else if (type is TypedefType) { |
345 if (type.typeArguments.isEmpty) { | 345 if (type.typeArguments.isEmpty) { |
346 return _getTypeDeclarationMirror(type.element); | 346 return _getTypeDeclarationMirror(type.element); |
347 } else { | 347 } else { |
348 return new Dart2JsTypedefMirror(this, type); | 348 return new Dart2JsTypedefMirror(this, type); |
349 } | 349 } |
350 } | 350 } |
351 compiler.internalError(type.element, | 351 compiler.reporter.internalError(type.element, |
352 "Unexpected type $type of kind ${type.kind}."); | 352 "Unexpected type $type of kind ${type.kind}."); |
353 return null; | 353 return null; |
354 } | 354 } |
355 | 355 |
356 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) { | 356 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) { |
357 if (element.isClass) { | 357 if (element.isClass) { |
358 return new Dart2JsClassDeclarationMirror(this, element.thisType); | 358 return new Dart2JsClassDeclarationMirror(this, element.thisType); |
359 } else if (element.isTypedef) { | 359 } else if (element.isTypedef) { |
360 return new Dart2JsTypedefDeclarationMirror(this, element.thisType); | 360 return new Dart2JsTypedefDeclarationMirror(this, element.thisType); |
361 } | 361 } |
362 compiler.internalError(element, "Unexpected element $element."); | 362 compiler.reporter.internalError(element, "Unexpected element $element."); |
363 return null; | 363 return null; |
364 } | 364 } |
365 } | 365 } |
366 | 366 |
367 abstract class ContainerMixin { | 367 abstract class ContainerMixin { |
368 UnmodifiableMapView<Symbol, DeclarationMirror> _declarations; | 368 UnmodifiableMapView<Symbol, DeclarationMirror> _declarations; |
369 | 369 |
370 void _ensureDeclarations() { | 370 void _ensureDeclarations() { |
371 if (_declarations == null) { | 371 if (_declarations == null) { |
372 var declarations = <Symbol, DeclarationMirror>{}; | 372 var declarations = <Symbol, DeclarationMirror>{}; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 if (!parameter.hasDefaultValue) return null; | 486 if (!parameter.hasDefaultValue) return null; |
487 ParameterElement parameterElement = parameter._element; | 487 ParameterElement parameterElement = parameter._element; |
488 Compiler compiler = parameter.mirrorSystem.compiler; | 488 Compiler compiler = parameter.mirrorSystem.compiler; |
489 return compiler.constants.getConstantForVariable(parameterElement); | 489 return compiler.constants.getConstantForVariable(parameterElement); |
490 } | 490 } |
491 | 491 |
492 static Mirror getMirrorFromElement(Dart2JsMirror mirror, Element element) { | 492 static Mirror getMirrorFromElement(Dart2JsMirror mirror, Element element) { |
493 return _convertElementToDeclarationMirror(mirror.mirrorSystem, element); | 493 return _convertElementToDeclarationMirror(mirror.mirrorSystem, element); |
494 } | 494 } |
495 } | 495 } |
OLD | NEW |