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

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: Fixed cf. lrn's comments 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
« no previous file with comments | « lib/dartdoc/mirrors/mirrors.dart ('k') | lib/dartdoc/mirrors/util.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
50 */
51 Mirror findMirror(Map<Object,Mirror> map, String name,
52 [String constructorName, String operatorName]) {
53 var foundMirror = null;
54 map.forEach((_, Mirror mirror) {
55 if (mirror.simpleName() == name) {
56 if (constructorName !== null) {
57 if (mirror is MethodMirror &&
58 constructorName == mirror.constructorName) {
59 foundMirror = mirror;
60 }
61 } else if (operatorName !== null) {
62 if (mirror is MethodMirror &&
63 operatorName == mirror.operatorName) {
64 foundMirror = mirror;
65 }
66 } else {
67 foundMirror = mirror;
68 }
69 }
70 });
71 return foundMirror;
72 }
OLDNEW
« no previous file with comments | « lib/dartdoc/mirrors/mirrors.dart ('k') | lib/dartdoc/mirrors/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698