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 '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
10 import '../scanner/scannerlib.dart'; | 10 import '../scanner/scannerlib.dart'; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 // TODO(johnniwinther): make sure that these are returned in declaration | 451 // TODO(johnniwinther): make sure that these are returned in declaration |
452 // order. | 452 // order. |
453 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f); | 453 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f); |
454 | 454 |
455 Iterable<DeclarationMirror> _getDeclarationMirrors(Element element) => | 455 Iterable<DeclarationMirror> _getDeclarationMirrors(Element element) => |
456 _library._getDeclarationMirrors(element); | 456 _library._getDeclarationMirrors(element); |
457 | 457 |
458 Uri get uri => _element.script.resourceUri; | 458 Uri get uri => _element.script.resourceUri; |
459 } | 459 } |
460 | 460 |
461 class ResolvedNode { | |
462 final node; | |
kevmoo
2014/05/02 00:21:23
Types?
| |
463 final _elements; | |
464 final _mirrorSystem; | |
465 ResolvedNode(this.node, this._elements, this._mirrorSystem); | |
466 | |
467 Mirror resolvedMirror(node) { | |
kevmoo
2014/05/02 00:21:23
Type of node?
| |
468 var element = _elements[node]; | |
469 if (element == null) return null; | |
470 return _convertElementToDeclarationMirror(_mirrorSystem, element); | |
471 } | |
472 } | |
473 | |
461 /** | 474 /** |
462 * Transitional class that allows access to features that have not yet | 475 * Transitional class that allows access to features that have not yet |
463 * made it to the mirror API. | 476 * made it to the mirror API. |
464 * | 477 * |
465 * All API in this class is experimental. | 478 * All API in this class is experimental. |
466 */ | 479 */ |
467 class BackDoor { | 480 class BackDoor { |
468 /// Return the compilation units comprising [library]. | 481 /// Return the compilation units comprising [library]. |
469 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { | 482 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { |
470 return library._element.compilationUnits.toList().map( | 483 return library._element.compilationUnits.toList().map( |
471 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); | 484 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); |
472 } | 485 } |
486 | |
487 static Iterable metadataSyntaxOf(Dart2JsElementMirror declaration) { | |
488 Compiler compiler = declaration.mirrorSystem.compiler; | |
489 return declaration._element.metadata.toList().map( | |
490 (MetadataAnnotation metadata) { | |
491 var node = metadata.parseNode(compiler); | |
492 Element annotatedElement = metadata.annotatedElement; | |
493 var context = annotatedElement.enclosingElement; | |
494 if (context == null) { | |
495 context = annotatedElement; | |
496 } | |
497 return new ResolvedNode( | |
498 node, context.treeElements, declaration.mirrorSystem); | |
499 }); | |
500 } | |
501 | |
502 static ResolvedNode initializerSyntaxOf(Dart2JsFieldMirror variable) { | |
503 var node = variable._variable.initializer; | |
504 if (node == null) return null; | |
505 return new ResolvedNode( | |
506 node, variable._variable.treeElements, variable.mirrorSystem); | |
507 } | |
508 | |
509 static ResolvedNode defaultValueSyntaxOf(Dart2JsParameterMirror parameter) { | |
510 if (!parameter.hasDefaultValue) return null; | |
511 var node = parameter._element.initializer; | |
512 return new ResolvedNode( | |
513 node, parameter.owner._element.treeElements, parameter.mirrorSystem); | |
514 } | |
473 } | 515 } |
OLD | NEW |