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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: lib/dartdoc/mirrors/mirrors_util.dart
diff --git a/lib/dartdoc/mirrors/mirrors_util.dart b/lib/dartdoc/mirrors/mirrors_util.dart
new file mode 100644
index 0000000000000000000000000000000000000000..33b65a801a905022853291c1d9d234e06861d2e6
--- /dev/null
+++ b/lib/dartdoc/mirrors/mirrors_util.dart
@@ -0,0 +1,74 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#library('mirrors.util');
+
+#import('mirrors.dart');
+
+//------------------------------------------------------------------------------
+// Utility functions for using the Mirror API
+//------------------------------------------------------------------------------
+
+/**
+ * Returns an iterable over the type declarations directly inheriting from
+ * the declaration of this type.
+ */
+Iterable<InterfaceMirror> computeSubdeclarations(MirrorSystem system,
+ InterfaceMirror type) {
+ type = type.declaration;
+ var subtypes = <InterfaceMirror>[];
+ system.libraries().forEach((_, library) {
+ for (InterfaceMirror otherType in library.types().getValues()) {
+ var superClass = otherType.superclass();
+ if (superClass !== null) {
+ superClass = superClass.declaration;
+ if (type.library() === superClass.library()) {
+ if (superClass == type) {
+ subtypes.add(otherType);
+ }
+ }
+ }
+ final superInterfaces = otherType.interfaces().getValues();
+ for (InterfaceMirror superInterface in superInterfaces) {
+ superInterface = superInterface.declaration;
+ if (type.library() === superInterface.library()) {
+ if (superInterface == type) {
+ subtypes.add(otherType);
+ }
+ }
+ }
+ }
+ });
+ return subtypes;
+}
+
+/**
+ * Finds the mirror in [map] by the simple name [name]. If [constructorName] or
+ * [operatorName] is provided, a constructor/operator method by that name is
+ * 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.
+ */
+Mirror findMirror(Map<Object,Mirror> map, String name,
+ [String constructorName, String operatorName]) {
+ var mirror = null;
+ 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.
+ bool found = false;
+ if (m.simpleName() == name) {
+ 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
+ if (constructorName !== null && m is MethodMirror) {
+ if (constructorName != m.constructorName) {
+ found = false;
+ }
+ }
+ if (operatorName !== null && m is MethodMirror) {
+ if (operatorName != m.operatorName) {
+ found = false;
+ }
+ }
+ }
+ if (found) {
+ mirror = m;
+ }
+ });
+ return mirror;
+}

Powered by Google App Engine
This is Rietveld 408576698