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

Unified Diff: pkg/docgen/lib/src/models/doc_gen_type.dart

Issue 242363004: pkg/docgen: moved model classes into minilibs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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: pkg/docgen/lib/src/models/doc_gen_type.dart
diff --git a/pkg/docgen/lib/src/models/doc_gen_type.dart b/pkg/docgen/lib/src/models/doc_gen_type.dart
new file mode 100644
index 0000000000000000000000000000000000000000..df7ca2da8647138070a8f56b15b5d28f6866b293
--- /dev/null
+++ b/pkg/docgen/lib/src/models/doc_gen_type.dart
@@ -0,0 +1,60 @@
+library docgen.models.doc_gen_type;
+
+import '../exports/source_mirrors.dart';
+
+import '../library_helpers.dart';
+
+import 'library.dart';
+import 'mirror_based.dart';
+
+/// Docgen wrapper around the mirror for a return type, and/or its generic
+/// type parameters.
+///
+/// Return types are of a form [outer]<[inner]>.
+/// If there is no [inner] part, [inner] will be an empty list.
+///
+/// For example:
+/// int size()
+/// "return" :
+/// - "outer" : "dart-core.int"
+/// "inner" :
+///
+/// List<String> toList()
+/// "return" :
+/// - "outer" : "dart-core.List"
+/// "inner" :
+/// - "outer" : "dart-core.String"
+/// "inner" :
+///
+/// Map<String, List<int>>
+/// "return" :
+/// - "outer" : "dart-core.Map"
+/// "inner" :
+/// - "outer" : "dart-core.String"
+/// "inner" :
+/// - "outer" : "dart-core.List"
+/// "inner" :
+/// - "outer" : "dart-core.int"
+/// "inner" :
+class DocGenType extends MirrorBased {
+ final TypeMirror mirror;
+ final Library owningLibrary;
+
+ DocGenType(this.mirror, this.owningLibrary);
+
+ Map toMap() {
+ var result = getDocgenObject(mirror, owningLibrary);
+ return {
+ // We may encounter types whose corresponding library has not been
+ // processed yet, so look up with the owningLibrary at the last moment.
+ 'outer': result.packagePrefix + result.docName,
+ 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(),
+ };
+ }
+
+ /// Returns a list of [DocGenType] objects constructed from TypeMirrors.
+ List<DocGenType> _createTypeGenerics(TypeMirror mirror) {
+ if (mirror is! ClassMirror) return [];
+ return mirror.typeArguments.map((e) => new DocGenType(e, owningLibrary)).toList();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698