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

Side by Side Diff: lib/dartdoc/mirrors/mirrors_util.dart

Issue 10692040: Mirrors prototype added to dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Utility libraries added Created 8 years, 5 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
(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 #library('mirrors.util');
6
7 #import('mirrors.dart');
8
9 //------------------------------------------------------------------------------
10 // Utility functions for using the Mirror API
11 //------------------------------------------------------------------------------
12
13 /**
14 * Returns an iterable over the type declarations directly inheriting from
15 * the declaration of this type.
16 */
17 Iterable<InterfaceMirror> computeSubdeclarations(MirrorSystem system,
18 InterfaceMirror type) {
19 type = type.declaration;
20 var subtypes = <InterfaceMirror>[];
21 system.libraries().forEach((_, library) {
22 for (InterfaceMirror otherType in library.types().getValues()) {
23 var superClass = otherType.superclass();
24 if (superClass !== null) {
25 superClass = superClass.declaration;
26 if (type.library() === superClass.library()) {
27 if (superClass == type) {
28 subtypes.add(otherType);
29 }
30 }
31 }
32 final superInterfaces = otherType.interfaces().getValues();
33 for (InterfaceMirror superInterface in superInterfaces) {
34 superInterface = superInterface.declaration;
35 if (type.library() === superInterface.library()) {
36 if (superInterface == type) {
37 subtypes.add(otherType);
38 }
39 }
40 }
41 }
42 });
43 return subtypes;
44 }
45
46 /**
47 * Finds the mirror in [map] by the simple name [name]. If [constructorName] or
48 * [operatorName] is provided, a constructor/operator method by that name is
49 * returned.
Lasse Reichstein Nielsen 2012/07/04 10:58:59 If constructorName is given, but name matches a no
Johnni Winther 2012/07/04 13:19:17 It wasn't. The test has been rewritten.
50 */
51 Mirror findMirror(Map<Object,Mirror> map, String name,
52 [String constructorName, String operatorName]) {
53 var mirror = null;
54 map.forEach((_,m) {
Lasse Reichstein Nielsen 2012/07/04 10:58:59 space after comma, give "m" a better name and pref
Johnni Winther 2012/07/04 13:19:17 Done.
55 bool found = false;
56 if (m.simpleName() == name) {
57 found = true;
Lasse Reichstein Nielsen 2012/07/04 10:58:59 Seems convoluted, but I guess that's actually for
Johnni Winther 2012/07/04 13:19:17 This wouldn't work for if [m] is a FieldMirror and
58 if (constructorName !== null && m is MethodMirror) {
59 if (constructorName != m.constructorName) {
60 found = false;
61 }
62 }
63 if (operatorName !== null && m is MethodMirror) {
64 if (operatorName != m.operatorName) {
65 found = false;
66 }
67 }
68 }
69 if (found) {
70 mirror = m;
71 }
72 });
73 return mirror;
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698