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

Side by Side Diff: pkg/docgen/lib/src/models/method.dart

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

Powered by Google App Engine
This is Rietveld 408576698