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

Side by Side Diff: pkg/docgen/lib/src/models/method.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library docgen.models.method;
2
3 import 'package:markdown/markdown.dart' as markdown;
4
5 import '../exports/mirrors_util.dart' as dart2js_util;
6 import '../exports/source_mirrors.dart';
7
8 import '../library_helpers.dart';
9
10 import 'class.dart';
11 import 'doc_gen_type.dart';
12 import 'dummy_mirror.dart';
13 import 'indexable.dart';
14 import 'model_helpers.dart';
15 import 'owned_indexable.dart';
16 import 'parameter.dart';
17
18
19 /// A class containing properties of a Dart method.
20 class Method extends OwnedIndexable {
21
22 /// Parameters for this method.
23 final Map<String, Parameter> parameters;
24
25 final bool isStatic;
26 final bool isAbstract;
27 final bool isConst;
28 final DocGenType returnType;
29 Method methodInheritedFrom;
30
31 /// Qualified name to state where the comment is inherited from.
32 String commentInheritedFrom = "";
33
34 factory Method(MethodMirror mirror, Indexable owner,
35 [Method methodInheritedFrom]) {
36 var method = getDocgenObject(mirror, owner);
37 if (method is DummyMirror) {
38 method = new Method._(mirror, owner, methodInheritedFrom);
39 }
40 return method;
41 }
42
43 Method._(MethodMirror mirror, Indexable owner, this.methodInheritedFrom)
44 : returnType = new DocGenType(mirror.returnType, owner.owningLibrary),
45 isStatic = mirror.isStatic,
46 isAbstract = mirror.isAbstract,
47 isConst = mirror.isConstConstructor,
48 parameters = createParameters(mirror.parameters, owner),
49 super(mirror, owner);
50
51 Method get originallyInheritedFrom => methodInheritedFrom == null ?
52 this : methodInheritedFrom.originallyInheritedFrom;
53
54 /// Look for the specified name starting with the current member, and
55 /// progressively working outward to the current library scope.
56 String findElementInScope(String name) {
57 var lookupFunc = determineLookupFunc(name);
58
59 var memberScope = lookupFunc(this.mirror, name);
60 if (memberScope != null) {
61 // do we check for a dummy mirror returned here and look up with an owner
62 // higher ooooor in getDocgenObject do we include more things in our
63 // lookup
64 var result = getDocgenObject(memberScope, owner);
65 if (result is DummyMirror && owner.owner != null
66 && owner.owner is! DummyMirror) {
67 var aresult = getDocgenObject(memberScope, owner.owner);
68 if (aresult is! DummyMirror) result = aresult;
69 }
70 if (result is DummyMirror) return packagePrefix + result.docName;
71 return result.packagePrefix + result.docName;
72 }
73
74 if (owner != null) {
75 var result = owner.findElementInScope(name);
76 if (result != null) return result;
77 }
78 return super.findElementInScope(name);
79 }
80
81 String get docName {
82 if ((mirror as MethodMirror).isConstructor) {
83 // We name constructors specially -- including the class name again and a
84 // "-" to separate the constructor from its name (if any).
85 return '${owner.docName}.${dart2js_util.nameOf(mirror.owner)}-'
86 '${dart2js_util.nameOf(mirror)}';
87 }
88 return super.docName;
89 }
90
91 String get fileName => packagePrefix + docName;
92
93 /// Makes sure that the method with an inherited equivalent have comments.
94 void ensureCommentFor(Method inheritedMethod) {
95 if (comment.isNotEmpty) return;
96
97 comment = inheritedMethod.commentToHtml(this);
98 unresolvedComment = inheritedMethod.unresolvedComment;
99 commentInheritedFrom = inheritedMethod.commentInheritedFrom == '' ?
100 new DummyMirror(inheritedMethod.mirror).docName :
101 inheritedMethod.commentInheritedFrom;
102 }
103
104 /// Generates a map describing the [Method] object.
105 Map toMap() => {
106 'name': name,
107 'qualifiedName': qualifiedName,
108 'comment': comment,
109 'commentFrom': (methodInheritedFrom != null &&
110 commentInheritedFrom == methodInheritedFrom.docName ? ''
111 : commentInheritedFrom),
112 'inheritedFrom': (methodInheritedFrom == null? '' :
113 originallyInheritedFrom.docName),
114 'static': isStatic,
115 'abstract': isAbstract,
116 'constant': isConst,
117 'return': [returnType.toMap()],
118 'parameters': recurseMap(parameters),
119 'annotations': annotations.map((a) => a.toMap()).toList()
120 };
121
122 String get typeName {
123 MethodMirror theMirror = mirror;
124 if (theMirror.isConstructor) return 'constructor';
125 if (theMirror.isGetter) return 'getter';
126 if (theMirror.isSetter) return 'setter';
127 if (theMirror.isOperator) return 'operator';
128 return 'method';
129 }
130
131 String get comment {
132 if (commentField != null) return commentField;
133 if (owner is Class) {
134 (owner as Class).ensureComments();
135 }
136 var result = super.comment;
137 if (result == '' && methodInheritedFrom != null) {
138 // This should be NOT from the MIRROR, but from the COMMENT.
139 methodInheritedFrom.comment; // Ensure comment field has been populated.
140 unresolvedComment = methodInheritedFrom.unresolvedComment;
141
142 comment = unresolvedComment == null ? '' :
143 markdown.markdownToHtml(unresolvedComment.trim(),
144 linkResolver: fixReference, inlineSyntaxes: MARKDOWN_SYNTAXES);
145 commentInheritedFrom = comment != '' ?
146 methodInheritedFrom.commentInheritedFrom : '';
147 result = comment;
148 }
149 return result;
150 }
151
152 bool isValidMirror(DeclarationMirror mirror) => mirror is MethodMirror;
153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698