OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 docgen.models.doc_gen_type; | |
6 | |
7 import '../exports/source_mirrors.dart'; | |
8 | |
9 import '../library_helpers.dart'; | |
10 | |
11 import 'library.dart'; | |
12 import 'mirror_based.dart'; | |
13 | |
14 /// Docgen wrapper around the mirror for a return type, and/or its generic | |
15 /// type parameters. | |
16 /// | |
17 /// Return types are of a form [outer]<[inner]>. | |
18 /// If there is no [inner] part, [inner] will be an empty list. | |
19 /// | |
20 /// For example: | |
21 /// int size() | |
22 /// "return" : | |
23 /// - "outer" : "dart:core.int" | |
24 /// "inner" : | |
25 /// | |
26 /// List<String> toList() | |
27 /// "return" : | |
28 /// - "outer" : "dart:core.List" | |
29 /// "inner" : | |
30 /// - "outer" : "dart:core.String" | |
31 /// "inner" : | |
32 /// | |
33 /// Map<String, List<int>> | |
34 /// "return" : | |
35 /// - "outer" : "dart:core.Map" | |
36 /// "inner" : | |
37 /// - "outer" : "dart:core.String" | |
38 /// "inner" : | |
39 /// - "outer" : "dart:core.List" | |
40 /// "inner" : | |
41 /// - "outer" : "dart:core.int" | |
42 /// "inner" : | |
43 class DocGenType extends MirrorBased { | |
44 final TypeMirror mirror; | |
45 final Library owningLibrary; | |
46 | |
47 DocGenType(this.mirror, this.owningLibrary); | |
48 | |
49 Map toMap() { | |
50 var result = getDocgenObject(mirror, owningLibrary); | |
51 return { | |
52 // We may encounter types whose corresponding library has not been | |
53 // processed yet, so look up with the owningLibrary at the last moment. | |
54 'outer': result.packagePrefix + result.docName, | |
55 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), | |
56 }; | |
57 } | |
58 | |
59 /// Returns a list of [DocGenType] objects constructed from TypeMirrors. | |
60 List<DocGenType> _createTypeGenerics(TypeMirror mirror) { | |
61 if (mirror is! ClassMirror) return []; | |
62 return mirror.typeArguments | |
63 .map((e) => new DocGenType(e, owningLibrary)) | |
64 .toList(); | |
65 } | |
66 } | |
OLD | NEW |