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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/dartdoc/mirrors/mirrors.dart ('k') | lib/dartdoc/mirrors/util.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..727d5cb6c91759dbbff770346299d526e67c1953
--- /dev/null
+++ b/lib/dartdoc/mirrors/mirrors_util.dart
@@ -0,0 +1,72 @@
+// 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.
+ */
+Mirror findMirror(Map<Object,Mirror> map, String name,
+ [String constructorName, String operatorName]) {
+ var foundMirror = null;
+ map.forEach((_, Mirror mirror) {
+ if (mirror.simpleName() == name) {
+ if (constructorName !== null) {
+ if (mirror is MethodMirror &&
+ constructorName == mirror.constructorName) {
+ foundMirror = mirror;
+ }
+ } else if (operatorName !== null) {
+ if (mirror is MethodMirror &&
+ operatorName == mirror.operatorName) {
+ foundMirror = mirror;
+ }
+ } else {
+ foundMirror = mirror;
+ }
+ }
+ });
+ return foundMirror;
+}
« 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