| 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; | 7 import 'dart:collection' show UnmodifiableListView; |
| 8 | 8 |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../scanner/scannerlib.dart'; | 10 import '../scanner/scannerlib.dart'; |
| 11 import '../resolution/resolution.dart' show Scope; | 11 import '../resolution/resolution.dart' show Scope; |
| 12 import '../dart2jslib.dart'; | 12 import '../dart2jslib.dart'; |
| 13 import '../dart_types.dart'; | 13 import '../dart_types.dart'; |
| 14 import '../tree/tree.dart'; | 14 import '../tree/tree.dart'; |
| 15 import '../util/util.dart' show Spannable, Link, LinkBuilder; | 15 import '../util/util.dart' |
| 16 show Spannable, |
| 17 Link, |
| 18 LinkBuilder, |
| 19 NO_LOCATION_SPANNABLE; |
| 16 import '../util/characters.dart' show $CR, $LF; | 20 import '../util/characters.dart' show $CR, $LF; |
| 17 | 21 |
| 18 import 'source_mirrors.dart'; | 22 import 'source_mirrors.dart'; |
| 19 import 'mirrors_util.dart'; | 23 import 'mirrors_util.dart'; |
| 20 import 'util.dart'; | 24 import 'util.dart'; |
| 21 | 25 |
| 22 part 'dart2js_library_mirror.dart'; | 26 part 'dart2js_library_mirror.dart'; |
| 23 part 'dart2js_type_mirrors.dart'; | 27 part 'dart2js_type_mirrors.dart'; |
| 24 part 'dart2js_member_mirrors.dart'; | 28 part 'dart2js_member_mirrors.dart'; |
| 25 part 'dart2js_instance_mirrors.dart'; | 29 part 'dart2js_instance_mirrors.dart'; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 var members = <Dart2JsMemberMirror>[]; | 128 var members = <Dart2JsMemberMirror>[]; |
| 125 AbstractFieldElement field = element; | 129 AbstractFieldElement field = element; |
| 126 if (field.getter != null) { | 130 if (field.getter != null) { |
| 127 members.add(new Dart2JsMethodMirror(this, field.getter)); | 131 members.add(new Dart2JsMethodMirror(this, field.getter)); |
| 128 } | 132 } |
| 129 if (field.setter != null) { | 133 if (field.setter != null) { |
| 130 members.add(new Dart2JsMethodMirror(this, field.setter)); | 134 members.add(new Dart2JsMethodMirror(this, field.setter)); |
| 131 } | 135 } |
| 132 return members; | 136 return members; |
| 133 } | 137 } |
| 134 mirrorSystem.compiler.internalError( | 138 mirrorSystem.compiler.internalError(element, |
| 135 "Unexpected member type $element ${element.kind}"); | 139 "Unexpected member type $element ${element.kind}."); |
| 136 return null; | 140 return null; |
| 137 } | 141 } |
| 138 | 142 |
| 139 } | 143 } |
| 140 | 144 |
| 141 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { | 145 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { |
| 142 final Dart2JsMirrorSystem mirrorSystem; | 146 final Dart2JsMirrorSystem mirrorSystem; |
| 143 final Element _element; | 147 final Element _element; |
| 144 List<InstanceMirror> _metadata; | 148 List<InstanceMirror> _metadata; |
| 145 | 149 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 return new Dart2JsFunctionTypeMirror(this, type, signature); | 336 return new Dart2JsFunctionTypeMirror(this, type, signature); |
| 333 } else if (type is VoidType) { | 337 } else if (type is VoidType) { |
| 334 return new Dart2JsVoidMirror(this, type); | 338 return new Dart2JsVoidMirror(this, type); |
| 335 } else if (type is TypedefType) { | 339 } else if (type is TypedefType) { |
| 336 if (type.typeArguments.isEmpty) { | 340 if (type.typeArguments.isEmpty) { |
| 337 return _getTypeDeclarationMirror(type.element); | 341 return _getTypeDeclarationMirror(type.element); |
| 338 } else { | 342 } else { |
| 339 return new Dart2JsTypedefMirror(this, type); | 343 return new Dart2JsTypedefMirror(this, type); |
| 340 } | 344 } |
| 341 } | 345 } |
| 342 compiler.internalError("Unexpected type $type of kind ${type.kind}"); | 346 compiler.internalError(type.element, |
| 347 "Unexpected type $type of kind ${type.kind}."); |
| 343 return null; | 348 return null; |
| 344 } | 349 } |
| 345 | 350 |
| 346 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) { | 351 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) { |
| 347 if (element.isClass()) { | 352 if (element.isClass()) { |
| 348 return new Dart2JsClassDeclarationMirror(this, element.thisType); | 353 return new Dart2JsClassDeclarationMirror(this, element.thisType); |
| 349 } else if (element.isTypedef()) { | 354 } else if (element.isTypedef()) { |
| 350 return new Dart2JsTypedefDeclarationMirror(this, element.thisType); | 355 return new Dart2JsTypedefDeclarationMirror(this, element.thisType); |
| 351 } | 356 } |
| 352 compiler.internalError("Unexpected element $element"); | 357 compiler.internalError(element, "Unexpected element $element."); |
| 353 return null; | 358 return null; |
| 354 } | 359 } |
| 355 } | 360 } |
| 356 | 361 |
| 357 abstract class ContainerMixin { | 362 abstract class ContainerMixin { |
| 358 Map<Symbol, DeclarationMirror> _declarations; | 363 Map<Symbol, DeclarationMirror> _declarations; |
| 359 | 364 |
| 360 void _ensureDeclarations() { | 365 void _ensureDeclarations() { |
| 361 if (_declarations == null) { | 366 if (_declarations == null) { |
| 362 _declarations = <Symbol, DeclarationMirror>{}; | 367 _declarations = <Symbol, DeclarationMirror>{}; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 * | 458 * |
| 454 * All API in this class is experimental. | 459 * All API in this class is experimental. |
| 455 */ | 460 */ |
| 456 class BackDoor { | 461 class BackDoor { |
| 457 /// Return the compilation units comprising [library]. | 462 /// Return the compilation units comprising [library]. |
| 458 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { | 463 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { |
| 459 return library._element.compilationUnits.toList().map( | 464 return library._element.compilationUnits.toList().map( |
| 460 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); | 465 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); |
| 461 } | 466 } |
| 462 } | 467 } |
| OLD | NEW |