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

Side by Side Diff: pkg/serialization/lib/src/mirrors_helpers.dart

Issue 11293283: Initial version of a serialization framework (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Provides some additional convenience methods on top of the basic mirrors
7 */
8 library mirrors_helpers;
9
10 // Import and re-export mirrors here to minimize both dependence on mirrors
11 // and the number of times we have to be told that mirrors aren't finished yet.
Jennifer Messerly 2012/11/15 08:02:14 Did you know: mirrors aren't finished yet? ;)
Alan Knight 2012/11/15 20:51:03 :-)
12 import 'dart:mirrors';
13 export 'dart:mirrors';
14 import 'serialization_helpers.dart';
15
16 /**
17 * Return a list of all the public fields of a class, including inherited
18 * fields.
19 */
20 List<VariableMirror> publicFields(ClassMirror mirror) {
21 var mine = mirror.variables.values.filter(
22 (x) => !(x.isPrivate || x.isStatic));
23 var mySuperclass = mirror.superclass;
24 if (mySuperclass != mirror) {
25 return append(publicFields(mirror.superclass), mine);
26 } else {
27 return mine;
28 }
29 }
30
31 /**
32 * Return a list of all the public getters of a class, including inherited
33 * getters.
34 */
35 List<MethodMirror> publicGetters(ClassMirror mirror) {
36 var mine = mirror.getters.values.filter((x) => !(x.isPrivate || x.isStatic));
37 var mySuperclass = mirror.superclass;
38 if (mySuperclass != mirror) {
39 return append(publicGetters(mirror.superclass), mine);
40 } else {
41 return mine;
42 }
43 }
44
45 /**
46 * Return a list of all the public getters of a class which have corresponding
47 * setters.
48 */
49 List<MethodMirror> publicGettersWithMatchingSetters(ClassMirror mirror) {
50 var setters = mirror.setters;
51 return publicGetters(mirror).filter((each) =>
52 setters["${each.simpleName}="] != null);
53 }
54
55 /**
56 * A particularly bad case of polyfill, because we cannot yet use type names
57 * as literals, so we have to be passed an instance and then extract a
58 * ClassMirror from that. Given a horrible name as an extra reminder to fix it.
59 */
60 ClassMirror turnInstanceIntoSomethingWeCanUse(x) => reflect(x).type;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698