Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Unified Diff: dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart

Issue 257863002: Prototype API for accessing AST nodes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/samples/constants/constants.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart
diff --git a/dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart b/dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart
index a4f88c2f31249cf227cd1a0d8a895d12189de20e..8ab65c65916f2578211332fe6decb7d2855a84ce 100644
--- a/dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart
+++ b/dart/sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirrors.dart
@@ -452,6 +452,19 @@ class Dart2JsCompilationUnitMirror extends Dart2JsMirror
Uri get uri => _element.script.resourceUri;
}
+class ResolvedNode {
+ final node;
kevmoo 2014/04/25 12:58:11 Types here? Is nice...
ahe 2014/04/25 13:06:09 I didn't want to add types as I didn't want to add
+ final _elements;
+ final _mirrorSystem;
+ ResolvedNode(this.node, this._elements, this._mirrorSystem);
+
+ Mirror resolvedMirror(node) {
+ var element = _elements[node];
+ if (element == null) return null;
+ return _convertElementToDeclarationMirror(_mirrorSystem, element);
+ }
+}
+
/**
* Transitional class that allows access to features that have not yet
* made it to the mirror API.
@@ -464,4 +477,32 @@ class BackDoor {
return library._element.compilationUnits.toList().map(
(cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList();
}
+
+ static Iterable metadataSyntaxOf(Dart2JsElementMirror declaration) {
+ Compiler compiler = declaration.mirrorSystem.compiler;
+ return declaration._element.metadata.toList().map((metadata) {
+ var node = metadata.parseNode(compiler);
+ Element annotatedElement = metadata.annotatedElement;
+ var context = annotatedElement.enclosingElement;
+ if (context == null) {
+ context = annotatedElement;
+ }
+ return new ResolvedNode(
+ node, context.treeElements, declaration.mirrorSystem);
+ });
+ }
+
+ static ResolvedNode initializerSyntaxOf(Dart2JsFieldMirror variable) {
+ var node = variable._variable.initializer;
+ if (node == null) return null;
+ return new ResolvedNode(
+ node, variable._variable.treeElements, variable.mirrorSystem);
+ }
+
+ static ResolvedNode defaultValueSyntaxOf(Dart2JsParameterMirror parameter) {
+ if (!parameter.hasDefaultValue) return null;
+ var node = parameter._element.initializer;
+ return new ResolvedNode(
+ node, parameter.owner._element.treeElements, parameter.mirrorSystem);
+ }
}
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/samples/constants/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698