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.typedef; | |
6 | |
7 import '../exports/source_mirrors.dart'; | |
8 | |
9 import '../library_helpers.dart'; | |
10 | |
11 import 'dummy_mirror.dart'; | |
12 import 'library.dart'; | |
13 import 'model_helpers.dart'; | |
14 import 'generic.dart'; | |
15 import 'parameter.dart'; | |
16 import 'owned_indexable.dart'; | |
17 | |
18 class Typedef extends OwnedIndexable<TypedefMirror> { | |
19 final String returnType; | |
20 | |
21 final Map<String, Parameter> parameters; | |
22 | |
23 /// Generic information about the typedef. | |
24 final Map<String, Generic> generics; | |
25 | |
26 /// Returns the [Library] for the given [mirror] if it has already been | |
27 /// created, else creates it. | |
28 factory Typedef(TypedefMirror mirror, Library owningLibrary) { | |
29 var aTypedef = getDocgenObject(mirror, owningLibrary); | |
30 if (aTypedef is DummyMirror) { | |
31 aTypedef = new Typedef._(mirror, owningLibrary); | |
32 } | |
33 return aTypedef; | |
34 } | |
35 | |
36 Typedef._(TypedefMirror mirror, Library owningLibrary) | |
37 : returnType = getDocgenObject(mirror.referent.returnType).docName, | |
38 generics = createGenerics(mirror), | |
39 parameters = createParameters(mirror.referent.parameters, | |
40 owningLibrary), | |
41 super(mirror, owningLibrary); | |
42 | |
43 Map toMap() { | |
44 var map = { | |
45 'name': name, | |
46 'qualifiedName': qualifiedName, | |
47 'comment': comment, | |
48 'return': returnType, | |
49 'parameters': recurseMap(parameters), | |
50 'annotations': annotations.map((a) => a.toMap()).toList(), | |
51 'generics': recurseMap(generics) | |
52 }; | |
53 | |
54 // Typedef is displayed on the library page as a class, so a preview is | |
55 // added manually | |
56 var pre = preview; | |
57 if (pre != null) map['preview'] = pre; | |
58 | |
59 return map; | |
60 } | |
61 | |
62 String get typeName => 'typedef'; | |
63 | |
64 bool isValidMirror(DeclarationMirror mirror) => mirror is TypedefMirror; | |
65 } | |
OLD | NEW |