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

Side by Side Diff: tests/compiler/dart2js_extra/mirror_printer_test.dart

Issue 105453004: Remove use of deprecated mirror API from code that only runs against dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/polymer/lib/src/reflected_type.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Prints all information about all mirrors. This tests that it is possible to 5 /// Prints all information about all mirrors. This tests that it is possible to
6 /// enumerate all reflective information without crashing. 6 /// enumerate all reflective information without crashing.
7 7
8 // Note: Adding imports below is fine for regression tests. For example, 8 // Note: Adding imports below is fine for regression tests. For example,
9 // 'crash_library_metadata.dart' is imported to ensure the compiler doesn't 9 // 'crash_library_metadata.dart' is imported to ensure the compiler doesn't
10 // crash. 10 // crash.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 String stringifyInstance(InstanceMirror mirror) { 51 String stringifyInstance(InstanceMirror mirror) {
52 var reflectee = mirror.reflectee; 52 var reflectee = mirror.reflectee;
53 if (reflectee is String) return '"${reflectee}"'; 53 if (reflectee is String) return '"${reflectee}"';
54 if (reflectee is Null || reflectee is bool || reflectee is num || 54 if (reflectee is Null || reflectee is bool || reflectee is num ||
55 reflectee is List || reflectee is Map) { 55 reflectee is List || reflectee is Map) {
56 return '$reflectee'; 56 return '$reflectee';
57 } 57 }
58 StringBuffer buffer = new StringBuffer(); 58 StringBuffer buffer = new StringBuffer();
59 Map<Symbol, VariableMirror> variables = mirror.type.variables; 59 Map<Symbol, DeclarationMirror> declarations = mirror.type.declarations;
60 buffer 60 buffer
61 ..write(n(mirror.type.simpleName)) 61 ..write(n(mirror.type.simpleName))
62 ..write('('); 62 ..write('(');
63 bool first = true; 63 bool first = true;
64 variables.forEach((Symbol name, VariableMirror variable) { 64 declarations.forEach((Symbol name, DeclarationMirror declaration) {
65 if (declaration is! VariableMirror) return;
66 VariableMirror variable = declaration;
65 if (variable.isStatic) return; 67 if (variable.isStatic) return;
66 // TODO(ahe): Include superclasses. 68 // TODO(ahe): Include superclasses.
67 if (first) { 69 if (first) {
68 first = false; 70 first = false;
69 } else { 71 } else {
70 buffer.write(', '); 72 buffer.write(', ');
71 } 73 }
72 buffer 74 buffer
73 ..write(n(name)) 75 ..write(n(name))
74 ..write(': ') 76 ..write(': ')
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 w(';'); 125 w(';');
124 } 126 }
125 127
126 writeClass(ClassMirror mirror) { 128 writeClass(ClassMirror mirror) {
127 // TODO(ahe): Write 'abstract' if [mirror] is abstract. 129 // TODO(ahe): Write 'abstract' if [mirror] is abstract.
128 w('class ${n(mirror.simpleName)}'); 130 w('class ${n(mirror.simpleName)}');
129 // TODO(ahe): Write superclass and interfaces. 131 // TODO(ahe): Write superclass and interfaces.
130 w(' {'); 132 w(' {');
131 bool first = true; 133 bool first = true;
132 indented(() { 134 indented(() {
133 for (DeclarationMirror declaration in mirror.members.values) { 135 for (DeclarationMirror declaration in mirror.declarations.values) {
134 if (first) { 136 if (first) {
135 first = false; 137 first = false;
136 } else { 138 } else {
137 w('\n'); 139 w('\n');
138 } 140 }
139 writeDeclaration(declaration); 141 writeDeclaration(declaration);
140 } 142 }
141 }); 143 });
142 w('\n}\n'); 144 w('\n}\n');
143 } 145 }
(...skipping 14 matching lines...) Expand all
158 } else if (declaration is MethodMirror) { 160 } else if (declaration is MethodMirror) {
159 writeMethod(declaration); 161 writeMethod(declaration);
160 } else { 162 } else {
161 // TODO(ahe): Test other subclasses of DeclarationMirror. 163 // TODO(ahe): Test other subclasses of DeclarationMirror.
162 w('$declaration'); 164 w('$declaration');
163 } 165 }
164 } 166 }
165 167
166 writeLibrary(LibraryMirror library) { 168 writeLibrary(LibraryMirror library) {
167 w('library ${n(library.simpleName)};\n\n'); 169 w('library ${n(library.simpleName)};\n\n');
168 library.members.values.forEach(writeDeclaration); 170 library.declarations.values
171 .where((d)=> d is! TypeMirror)
172 .forEach(writeDeclaration);
169 w('\n'); 173 w('\n');
170 } 174 }
171 175
172 static StringBuffer stringify(Map<Uri, LibraryMirror> libraries) { 176 static StringBuffer stringify(Map<Uri, LibraryMirror> libraries) {
173 StringBuffer buffer = new StringBuffer(); 177 StringBuffer buffer = new StringBuffer();
174 libraries.values.forEach(new MirrorPrinter(buffer).writeLibrary); 178 libraries.values.forEach(new MirrorPrinter(buffer).writeLibrary);
175 return buffer; 179 return buffer;
176 } 180 }
177 } 181 }
178 182
179 main() { 183 main() {
180 print(MirrorPrinter.stringify(currentMirrorSystem().libraries)); 184 print(MirrorPrinter.stringify(currentMirrorSystem().libraries));
181 // Clear the nodes to avoid confusing the fine test framework (by "fine" I 185 // Clear the nodes to avoid confusing the fine test framework (by "fine" I
182 // mean something else) -- ahe. 186 // mean something else) -- ahe.
183 document.body.nodes.clear(); 187 document.body.nodes.clear();
184 } 188 }
OLDNEW
« no previous file with comments | « pkg/polymer/lib/src/reflected_type.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698