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

Side by Side Diff: tests/lib/mirrors/stringify.dart

Issue 36023003: Add LibraryMirror.declarations and ClassMirror.declarations to the API and both implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: typevars are not static Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
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 /// Helper methods for converting a [Mirror] to a [String]. 5 /// Helper methods for converting a [Mirror] to a [String].
6 library test.stringify; 6 library test.stringify;
7 7
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 9
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 stringifyClass(ClassMirror cls) { 99 stringifyClass(ClassMirror cls) {
100 var buffer = new StringBuffer(); 100 var buffer = new StringBuffer();
101 writeDeclarationOn(cls, buffer); 101 writeDeclarationOn(cls, buffer);
102 return 'Class($buffer)'; 102 return 'Class($buffer)';
103 } 103 }
104 104
105 stringifyMethod(MethodMirror method) { 105 stringifyMethod(MethodMirror method) {
106 var buffer = new StringBuffer(); 106 var buffer = new StringBuffer();
107 writeDeclarationOn(method, buffer); 107 writeDeclarationOn(method, buffer);
108 if (method.isAbstract) buffer.write(', abstract');
108 if (method.isStatic) buffer.write(', static'); 109 if (method.isStatic) buffer.write(', static');
109 if (method.isGetter) buffer.write(', getter'); 110 if (method.isGetter) buffer.write(', getter');
110 if (method.isSetter) buffer.write(', setter'); 111 if (method.isSetter) buffer.write(', setter');
111 if (method.isConstructor) buffer.write(', constructor'); 112 if (method.isConstructor) buffer.write(', constructor');
112 return 'Method($buffer)'; 113 return 'Method($buffer)';
113 } 114 }
114 115
115 stringify(value) { 116 stringify(value) {
116 if (value is Map) return stringifyMap(value); 117 if (value is Map) return stringifyMap(value);
117 if (value is Iterable) return stringifyIterable(value); 118 if (value is Iterable) return stringifyIterable(value);
(...skipping 15 matching lines...) Expand all
133 Expect.stringEquals(expected, stringify(actual), reason); 134 Expect.stringEquals(expected, stringify(actual), reason);
134 } 135 }
135 136
136 compareSymbols(Symbol a, Symbol b) { 137 compareSymbols(Symbol a, Symbol b) {
137 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b)); 138 return MirrorSystem.getName(a).compareTo(MirrorSystem.getName(b));
138 } 139 }
139 140
140 simpleNames(Iterable<Mirror> i) => i.map((e) => e.simpleName); 141 simpleNames(Iterable<Mirror> i) => i.map((e) => e.simpleName);
141 142
142 sort(Iterable<Symbol> symbols) => symbols.toList()..sort(compareSymbols); 143 sort(Iterable<Symbol> symbols) => symbols.toList()..sort(compareSymbols);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698