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

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 16948010: added Command Line Arguments, support for directories, hiding private data, not parsing the SDK, rem (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
« no previous file with comments | « pkg/docgen/example/test.dart ('k') | pkg/docgen/lib/src/dart2js_mirrors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * The docgen tool takes in a library as input and produces documentation 6 * The docgen tool takes in a library as input and produces documentation
7 * for the library as well as all libraries it imports and uses. The tool can 7 * for the library as well as all libraries it imports and uses. The tool can
8 * be run by passing in the path to a .dart file like this: 8 * be run by passing in the path to a .dart file like this:
9 * 9 *
10 * ./dart docgen.dart path/to/file.dart 10 * ./dart docgen.dart path/to/file.dart
11 * 11 *
12 * This outputs information about all classes, variables, functions, and 12 * This outputs information about all classes, variables, functions, and
13 * methods defined in the library and its imported libraries. 13 * methods defined in the library and its imported libraries.
14 */ 14 */
15 library docgen; 15 library docgen;
16 16
17 // TODO(tmandel): Use 'package:' references for imports with relative paths. 17 // TODO(tmandel): Use 'package:' references for imports with relative paths.
18 import 'dart:io'; 18 import 'dart:io';
19 import 'dart:json'; 19 import 'dart:json';
20 import 'dart:async'; 20 import 'dart:async';
21 import '../lib/dart2yaml.dart';
22 import '../lib/src/dart2js_mirrors.dart';
23 import 'package:markdown/markdown.dart' as markdown; 21 import 'package:markdown/markdown.dart' as markdown;
24 import '../../args/lib/args.dart'; 22 import 'package:args/args.dart';
25 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; 23 import 'dart2yaml.dart';
26 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; 24 import 'package:compiler_unsupported/implementation/mirrors/dart2js_mirror.dart' ;
25 import 'package:compiler_unsupported/implementation/mirrors/mirrors.dart';
26 import 'package:compiler_unsupported/implementation/mirrors/mirrors_util.dart';
27
28 /// Unique ID, will get incremented everytime an ID is requested.
29 int _uid = 0;
30
31 int getID() => _uid++;
27 32
28 /** 33 /**
29 * Entry function to create YAML documentation from Dart files. 34 * Returns a ArgParser with all the flags and options created.
30 */ 35 */
31 void main() { 36 ArgParser initArgParser() {
32 // TODO(tmandel): Use args library once flags are clear. 37 var parser = new ArgParser();
33 Options opts = new Options(); 38 parser.addFlag("help", abbr: "h",
34 Docgen docgen = new Docgen(); 39 help: "Prints help and usage information",
40 negatable: false,
41 callback: (help) {
42 if (help) print(parser.getUsage());
43 });
44 parser.addFlag("yaml", abbr: "y",
45 help: "Outputs to YAML",
46 defaultsTo: true, negatable: true);
47 parser.addFlag("json", abbr: "j",
48 help: "Outputs to JSON",
49 defaultsTo: false, negatable: true);
50 parser.addFlag("hide-private",
51 help: "Hides private declarations" ,
52 defaultsTo: false, negatable: false);
53 parser.addFlag("sdk",
54 help: "Flag to parse SDK Library files",
55 defaultsTo: true, negatable: true);
35 56
36 if (opts.arguments.length > 0) { 57 return parser;
37 List<Path> libraries = [new Path(opts.arguments[0])]; 58 }
38 Path sdkDirectory = new Path("../../../sdk/"); 59
39 var workingMirrors = analyze(libraries, sdkDirectory, 60 List<Path> listLibraries(List<String> args) {
40 options: ['--preserve-comments', '--categories=Client,Server']); 61 if (args.length != 1) {
41 workingMirrors.then( (MirrorSystem mirrorSystem) { 62 throw new UnsupportedError("Usage: dart docgen.dart [OPTIONS] [FILE/DIR]");
42 var mirrors = mirrorSystem.libraries.values;
43 if (mirrors.isEmpty) {
44 print("no LibraryMirrors");
45 } else {
46 docgen.libraries = mirrors;
47 docgen.documentLibraries();
48 }
49 });
50 } 63 }
64 var libraries = new List<Path>();
65 var type = FileSystemEntity.typeSync(args[0]);
66
67 if (type == FileSystemEntityType.LINK) {
68 throw new UnsupportedError("""File should not be a link.
69 Usage: dart docgen.dart [OPTIONS] [FILE/DIR]""");
Emily Fortuna 2013/06/19 17:23:34 why not support links?
janicejl 2013/06/19 18:53:38 Done.
70 } else if (type == FileSystemEntityType.NOT_FOUND) {
71 throw new UnsupportedError("""File does not exist.
72 Usage: dart docgen.dart [OPTIONS] [FILE/DIR]""");
73 } else if (type == FileSystemEntityType.FILE) {
74 libraries.add(new Path(args[0]));
75 } else if (type == FileSystemEntityType.DIRECTORY) {
76 new Directory(args[0]).listSync(recursive: true,
77 followLinks: true).forEach((file) {
78 if (new Path(file.path).extension == "dart") {
79 if (!file.path.contains("/packages/")) {
80 libraries.add(new Path(file.path));
81 }
82 }
83 });
84 }
85 return libraries;
51 } 86 }
52 87
53 /** 88 /**
54 * This class documents a list of libraries. 89 * This class documents a list of libraries.
55 */ 90 */
56 class Docgen { 91 class Docgen {
57 92
58 /// Libraries to be documented. 93 /// Libraries to be documented.
59 List<LibraryMirror> _libraries; 94 List<LibraryMirror> _libraries;
60 95
61 /// Saves list of libraries for Docgen object. 96 /// Saves list of libraries for Docgen object.
62 void set libraries(value) => _libraries = value; 97 void set libraries(value) {
98 _libraries = value;
99 }
63 100
64 /// Current library being documented to be used for comment links. 101 /// Current library being documented to be used for comment links.
65 LibraryMirror _currentLibrary; 102 LibraryMirror _currentLibrary;
66 103
67 /// Current class being documented to be used for comment links. 104 /// Current class being documented to be used for comment links.
68 ClassMirror _currentClass; 105 ClassMirror _currentClass;
69 106
70 /// Current member being documented to be used for comment links. 107 /// Current member being documented to be used for comment links.
71 MemberMirror _currentMember; 108 MemberMirror _currentMember;
72 109
73 /// Should the output file type be JSON?
74 // TODO(tmandel): Add flag to allow for output to JSON.
75 bool outputToJson = false;
76
77 /// Resolves reference links 110 /// Resolves reference links
78 markdown.Resolver linkResolver; 111 markdown.Resolver linkResolver;
79 112
80 /** 113 /**
81 * Docgen constructor initializes the link resolver for markdown parsing. 114 * Docgen constructor initializes the link resolver for markdown parsing.
82 */ 115 */
83 Docgen() { 116 Docgen({Path sdkRoot, ArgResults argResults}) {
Emily Fortuna 2013/06/19 17:23:34 Docgen({this.sdkRoot, ArgResults argResults}) { ..
117 this.sdkRoot = sdkRoot;
118 outputToYaml = argResults["yaml"];
119 outputToJson = argResults["json"];
120 hidePrivate = argResults["hide-private"];
121 sdk = argResults["sdk"];
122
84 this.linkResolver = (name) => 123 this.linkResolver = (name) =>
85 fixReference(name, _currentLibrary, _currentClass, _currentMember); 124 fixReference(name, _currentLibrary, _currentClass, _currentMember);
86 } 125 }
87 126
127 /// Path to the SDK Libraries.
128 Path sdkRoot;
129
130 /// Should the output file type be YAML?
131 bool outputToYaml;
132 /// Should the output file type be JSON?
133 bool outputToJson;
134 /// Should the output file hide private declarations?
135 bool hidePrivate;
136 /// Should the output include SDK libraries?
137 bool sdk;
138
88 /** 139 /**
89 * Creates documentation for filtered libraries. 140 * Creates documentation for filtered libraries.
90 */ 141 */
91 void documentLibraries() { 142 void documentLibraries() {
92 //TODO(tmandel): Filter libraries and determine output type using flags.
93 _libraries.forEach((library) { 143 _libraries.forEach((library) {
94 _currentLibrary = library; 144 // Files belong to the SDK have a uri that begins with "dart:".
95 var result = new Library(library.qualifiedName, _getComment(library), 145 if (sdk || !library.uri.toString().startsWith("dart:")) {
96 _getVariables(library.variables), _getMethods(library.functions), 146 _currentLibrary = library;
97 _getClasses(library.classes)); 147 var result = new Library(library.qualifiedName, _getComment(library),
98 if (outputToJson) { 148 _getVariables(library.variables), _getMethods(library.functions),
99 _writeToFile(stringify(result.toMap()), "${result.name}.json"); 149 _getClasses(library.classes), getID());
100 } else { 150 if (outputToJson) {
101 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml"); 151 _writeToFile(stringify(result.toMap()), "${result.name}.json");
102 } 152 }
153 if (outputToYaml) {
Emily Fortuna 2013/06/19 17:23:34 seems like you might want to have a default output
janicejl 2013/06/19 18:53:38 Defaults to yaml through setting up the command li
154 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
155 }
156 }
103 }); 157 });
104 } 158 }
105 159
106 /** 160 /**
107 * Returns any documentation comments associated with a mirror with 161 * Returns any documentation comments associated with a mirror with
108 * simple markdown converted to html. 162 * simple markdown converted to html.
109 */ 163 */
110 String _getComment(DeclarationMirror mirror) { 164 String _getComment(DeclarationMirror mirror) {
111 String commentText; 165 String commentText;
112 mirror.metadata.forEach((metadata) { 166 mirror.metadata.forEach((metadata) {
113 if (metadata is CommentInstanceMirror) { 167 if (metadata is CommentInstanceMirror) {
114 CommentInstanceMirror comment = metadata; 168 CommentInstanceMirror comment = metadata;
115 if (comment.isDocComment) { 169 if (comment.isDocComment) {
116 if (commentText == null) { 170 if (commentText == null) {
117 commentText = comment.trimmedText; 171 commentText = comment.trimmedText;
118 } else { 172 } else {
119 commentText = "$commentText ${comment.trimmedText}"; 173 commentText = "$commentText ${comment.trimmedText}";
120 } 174 }
121 } 175 }
122 } 176 }
123 }); 177 });
124 return commentText == null ? "" : 178 commentText = commentText == null ? "" :
125 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver); 179 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver);
Emily Fortuna 2013/06/19 17:23:34 continuation of previous line should be indented t
janicejl 2013/06/19 18:53:38 I have changed it to replace all \n to "". This is
180 return commentText.replaceAll("\n", "<br/>");
126 } 181 }
127 182
128 /** 183 /**
129 * Converts all [_] references in comments to <code>_</code>. 184 * Converts all [_] references in comments to <code>_</code>.
130 */ 185 */
131 // TODO(tmandel): Create proper links for [_] style markdown based 186 // TODO(tmandel): Create proper links for [_] style markdown based
132 // on scope once layout of viewer is finished. 187 // on scope once layout of viewer is finished.
133 markdown.Node fixReference(String name, LibraryMirror currentLibrary, 188 markdown.Node fixReference(String name, LibraryMirror currentLibrary,
134 ClassMirror currentClass, MemberMirror currentMember) { 189 ClassMirror currentClass, MemberMirror currentMember) {
135 return new markdown.Element.text('code', name); 190 return new markdown.Element.text('code', name);
136 } 191 }
137 192
138 /** 193 /**
139 * Returns a map of [Variable] objects constructed from inputted mirrors. 194 * Returns a map of [Variable] objects constructed from inputted mirrors.
140 */ 195 */
141 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { 196 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) {
142 var data = {}; 197 var data = {};
143 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 198 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
144 _currentMember = mirror; 199 if (!hidePrivate || !mirror.isPrivate) {
145 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 200 _currentMember = mirror;
146 mirror.isStatic, mirror.type.toString(), _getComment(mirror)); 201 data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
202 mirror.isStatic, mirror.type.toString(), _getComment(mirror),
203 getID());
204 }
147 }); 205 });
148 return data; 206 return data;
149 } 207 }
150 208
151 /** 209 /**
152 * Returns a map of [Method] objects constructed from inputted mirrors. 210 * Returns a map of [Method] objects constructed from inputted mirrors.
153 */ 211 */
154 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { 212 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) {
155 var data = {}; 213 var data = {};
156 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 214 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
157 _currentMember = mirror; 215 if (!hidePrivate || !mirror.isPrivate) {
158 data[mirrorName] = new Method(mirrorName, mirror.isSetter, 216 _currentMember = mirror;
159 mirror.isGetter, mirror.isConstructor, mirror.isOperator, 217 data[mirrorName] = new Method(mirrorName, mirror.isSetter,
160 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror), 218 mirror.isGetter, mirror.isConstructor, mirror.isOperator,
161 _getParameters(mirror.parameters)); 219 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror),
220 _getParameters(mirror.parameters), getID());
221 }
162 }); 222 });
163 return data; 223 return data;
164 } 224 }
165 225
166 /** 226 /**
167 * Returns a map of [Class] objects constructed from inputted mirrors. 227 * Returns a map of [Class] objects constructed from inputted mirrors.
168 */ 228 */
169 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { 229 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) {
170 var data = {}; 230 var data = {};
171 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 231 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
172 _currentClass = mirror; 232 if (!hidePrivate || !mirror.isPrivate) {
173 var superclass; 233 _currentClass = mirror;
174 if (mirror.superclass != null) { 234 var superclass = (mirror.superclass != null) ?
175 superclass = mirror.superclass.qualifiedName; 235 mirror.superclass.qualifiedName : "";
236 var interfaces =
237 mirror.superinterfaces.map((interface) => interface.qualifiedName);
238 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
239 mirror.isTypedef, _getComment(mirror), interfaces.toList(),
240 _getVariables(mirror.variables), _getMethods(mirror.methods),
241 getID());
176 } 242 }
177 var interfaces =
178 mirror.superinterfaces.map((interface) => interface.qualifiedName);
179 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
180 mirror.isTypedef, _getComment(mirror), interfaces,
181 _getVariables(mirror.variables), _getMethods(mirror.methods));
182 }); 243 });
183 return data; 244 return data;
184 } 245 }
185 246
186 /** 247 /**
187 * Returns a map of [Parameter] objects constructed from inputted mirrors. 248 * Returns a map of [Parameter] objects constructed from inputted mirrors.
188 */ 249 */
189 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 250 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
190 var data = {}; 251 var data = {};
191 mirrorList.forEach((ParameterMirror mirror) { 252 mirrorList.forEach((ParameterMirror mirror) {
192 _currentMember = mirror; 253 _currentMember = mirror;
193 data[mirror.simpleName] = new Parameter(mirror.simpleName, 254 data[mirror.simpleName] = new Parameter(mirror.simpleName,
194 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, 255 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
195 mirror.type.toString(), mirror.defaultValue); 256 mirror.type.toString(), mirror.defaultValue, getID());
196 }); 257 });
197 return data; 258 return data;
198 } 259 }
199 } 260 }
200 261
201 /** 262 /**
202 * Transforms the map by calling toMap on each value in it. 263 * Transforms the map by calling toMap on each value in it.
203 */ 264 */
204 Map recurseMap(Map inputMap) { 265 Map recurseMap(Map inputMap) {
205 var outputMap = {}; 266 var outputMap = {};
206 inputMap.forEach((key, value) { 267 inputMap.forEach((key, value) {
207 outputMap[key] = value.toMap(); 268 outputMap[key] = value.toMap();
208 }); 269 });
209 return outputMap; 270 return outputMap;
210 } 271 }
211 272
212 /** 273 /**
213 * A class containing contents of a Dart library. 274 * A class containing contents of a Dart library.
214 */ 275 */
215 class Library { 276 class Library {
216 277
278 /// Unique ID number for resolving links.
279 int id;
280
217 /// Documentation comment with converted markdown. 281 /// Documentation comment with converted markdown.
218 String comment; 282 String comment;
219 283
220 /// Top-level variables in the library. 284 /// Top-level variables in the library.
221 Map<String, Variable> variables; 285 Map<String, Variable> variables;
222 286
223 /// Top-level functions in the library. 287 /// Top-level functions in the library.
224 Map<String, Method> functions; 288 Map<String, Method> functions;
225 289
226 /// Classes defined within the library 290 /// Classes defined within the library
227 Map<String, Class> classes; 291 Map<String, Class> classes;
228 292
229 String name; 293 String name;
230 294
231 Library(this.name, this.comment, this.variables, 295 Library(this.name, this.comment, this.variables,
232 this.functions, this.classes); 296 this.functions, this.classes, this.id);
233 297
234 /// Generates a map describing the [Library] object. 298 /// Generates a map describing the [Library] object.
235 Map toMap() { 299 Map toMap() {
236 var libraryMap = {}; 300 var libraryMap = {};
301 libraryMap["id"] = id;
237 libraryMap["name"] = name; 302 libraryMap["name"] = name;
238 libraryMap["comment"] = comment; 303 libraryMap["comment"] = comment;
239 libraryMap["variables"] = recurseMap(variables); 304 libraryMap["variables"] = recurseMap(variables);
240 libraryMap["functions"] = recurseMap(functions); 305 libraryMap["functions"] = recurseMap(functions);
241 libraryMap["classes"] = recurseMap(classes); 306 libraryMap["classes"] = recurseMap(classes);
242 return libraryMap; 307 return libraryMap;
243 } 308 }
244 } 309 }
245 310
246 /** 311 /**
247 * A class containing contents of a Dart class. 312 * A class containing contents of a Dart class.
248 */ 313 */
249 // TODO(tmandel): Figure out how to do typedefs (what is needed) 314 // TODO(tmandel): Figure out how to do typedefs (what is needed)
250 class Class { 315 class Class {
251 316
317 /// Unique ID number for resolving links.
318 int id;
319
252 /// Documentation comment with converted markdown. 320 /// Documentation comment with converted markdown.
253 String comment; 321 String comment;
254 322
255 /// List of the names of interfaces that this class implements. 323 /// List of the names of interfaces that this class implements.
256 List<String> interfaces; 324 List<String> interfaces;
257 325
258 /// Top-level variables in the class. 326 /// Top-level variables in the class.
259 Map<String, Variable> variables; 327 Map<String, Variable> variables;
260 328
261 /// Methods in the class. 329 /// Methods in the class.
262 Map<String, Method> methods; 330 Map<String, Method> methods;
263 331
264 String name; 332 String name;
265 String superclass; 333 String superclass;
266 bool isAbstract; 334 bool isAbstract;
267 bool isTypedef; 335 bool isTypedef;
268 336
269 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, 337 Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
270 this.comment, this.interfaces, this.variables, this.methods); 338 this.comment, this.interfaces, this.variables, this.methods, this.id);
271 339
272 /// Generates a map describing the [Class] object. 340 /// Generates a map describing the [Class] object.
273 Map toMap() { 341 Map toMap() {
274 var classMap = {}; 342 var classMap = {};
343 classMap["id"] = id;
275 classMap["name"] = name; 344 classMap["name"] = name;
276 classMap["comment"] = comment; 345 classMap["comment"] = comment;
277 classMap["superclass"] = superclass; 346 classMap["superclass"] = superclass;
278 classMap["abstract"] = isAbstract.toString(); 347 classMap["abstract"] = isAbstract.toString();
279 classMap["typedef"] = isTypedef.toString(); 348 classMap["typedef"] = isTypedef.toString();
280 classMap["implements"] = new List.from(interfaces); 349 classMap["implements"] = new List.from(interfaces);
281 classMap["variables"] = recurseMap(variables); 350 classMap["variables"] = recurseMap(variables);
282 classMap["methods"] = recurseMap(methods); 351 classMap["methods"] = recurseMap(methods);
283 return classMap; 352 return classMap;
284 } 353 }
285 } 354 }
286 355
287 /** 356 /**
288 * A class containing properties of a Dart variable. 357 * A class containing properties of a Dart variable.
289 */ 358 */
290 class Variable { 359 class Variable {
291 360
361 /// Unique ID number for resolving links.
362 int id;
363
292 /// Documentation comment with converted markdown. 364 /// Documentation comment with converted markdown.
293 String comment; 365 String comment;
294 366
295 String name; 367 String name;
296 bool isFinal; 368 bool isFinal;
297 bool isStatic; 369 bool isStatic;
298 String type; 370 String type;
299 371
300 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment); 372 Variable(this.name, this.isFinal, this.isStatic, this.type,
373 this.comment, this.id);
301 374
302 /// Generates a map describing the [Variable] object. 375 /// Generates a map describing the [Variable] object.
303 Map toMap() { 376 Map toMap() {
304 var variableMap = {}; 377 var variableMap = {};
378 variableMap["id"] = id;
305 variableMap["name"] = name; 379 variableMap["name"] = name;
306 variableMap["comment"] = comment; 380 variableMap["comment"] = comment;
307 variableMap["final"] = isFinal.toString(); 381 variableMap["final"] = isFinal.toString();
308 variableMap["static"] = isStatic.toString(); 382 variableMap["static"] = isStatic.toString();
309 variableMap["type"] = type; 383 variableMap["type"] = type;
310 return variableMap; 384 return variableMap;
311 } 385 }
312 } 386 }
313 387
314 /** 388 /**
315 * A class containing properties of a Dart method. 389 * A class containing properties of a Dart method.
316 */ 390 */
317 class Method { 391 class Method {
318 392
393 /// Unique ID number for resolving links.
394 int id;
395
319 /// Documentation comment with converted markdown. 396 /// Documentation comment with converted markdown.
320 String comment; 397 String comment;
321 398
322 /// Parameters for this method. 399 /// Parameters for this method.
323 Map<String, Parameter> parameters; 400 Map<String, Parameter> parameters;
324 401
325 String name; 402 String name;
326 bool isSetter; 403 bool isSetter;
327 bool isGetter; 404 bool isGetter;
328 bool isConstructor; 405 bool isConstructor;
329 bool isOperator; 406 bool isOperator;
330 bool isStatic; 407 bool isStatic;
331 String returnType; 408 String returnType;
332 409
333 Method(this.name, this.isSetter, this.isGetter, this.isConstructor, 410 Method(this.name, this.isSetter, this.isGetter, this.isConstructor,
334 this.isOperator, this.isStatic, this.returnType, this.comment, 411 this.isOperator, this.isStatic, this.returnType, this.comment,
335 this.parameters); 412 this.parameters, this.id);
336 413
337 /// Generates a map describing the [Method] object. 414 /// Generates a map describing the [Method] object.
338 Map toMap() { 415 Map toMap() {
339 var methodMap = {}; 416 var methodMap = {};
417 methodMap["id"] = id;
340 methodMap["name"] = name; 418 methodMap["name"] = name;
341 methodMap["comment"] = comment; 419 methodMap["comment"] = comment;
342 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" : 420 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" :
343 isOperator ? "operator" : isConstructor ? "constructor" : "method"; 421 isOperator ? "operator" : isConstructor ? "constructor" : "method";
344 methodMap["static"] = isStatic.toString(); 422 methodMap["static"] = isStatic.toString();
345 methodMap["return"] = returnType; 423 methodMap["return"] = returnType;
346 methodMap["parameters"] = recurseMap(parameters); 424 methodMap["parameters"] = recurseMap(parameters);
347 return methodMap; 425 return methodMap;
348 } 426 }
349 } 427 }
350 428
351 /** 429 /**
352 * A class containing properties of a Dart method/function parameter. 430 * A class containing properties of a Dart method/function parameter.
353 */ 431 */
354 class Parameter { 432 class Parameter {
355 433
434 /// Unique ID number for resolving links.
435 int id;
436
356 String name; 437 String name;
357 bool isOptional; 438 bool isOptional;
358 bool isNamed; 439 bool isNamed;
359 bool hasDefaultValue; 440 bool hasDefaultValue;
360 String type; 441 String type;
361 String defaultValue; 442 String defaultValue;
362 443
363 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, 444 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
364 this.type, this.defaultValue); 445 this.type, this.defaultValue, this.id);
365 446
366 /// Generates a map describing the [Parameter] object. 447 /// Generates a map describing the [Parameter] object.
367 Map toMap() { 448 Map toMap() {
368 var parameterMap = {}; 449 var parameterMap = {};
450 parameterMap["id"] = id;
369 parameterMap["name"] = name; 451 parameterMap["name"] = name;
370 parameterMap["optional"] = isOptional.toString(); 452 parameterMap["optional"] = isOptional.toString();
371 parameterMap["named"] = isNamed.toString(); 453 parameterMap["named"] = isNamed.toString();
372 parameterMap["default"] = hasDefaultValue.toString(); 454 parameterMap["default"] = hasDefaultValue.toString();
373 parameterMap["type"] = type; 455 parameterMap["type"] = type;
374 parameterMap["value"] = defaultValue; 456 parameterMap["value"] = defaultValue;
375 return parameterMap; 457 return parameterMap;
376 } 458 }
377 } 459 }
378 460
379 /** 461 /**
380 * Writes text to a file in the 'docs' directory. 462 * Writes text to a file in the 'docs' directory.
381 */ 463 */
382 void _writeToFile(String text, String filename) { 464 void _writeToFile(String text, String filename) {
383 Directory dir = new Directory('docs'); 465 Directory dir = new Directory('docs');
384 if (!dir.existsSync()) { 466 if (!dir.existsSync()) {
385 dir.createSync(); 467 dir.createSync();
386 } 468 }
387 File file = new File('docs/$filename'); 469 File file = new File('docs/$filename');
388 if (!file.exists()) { 470 if (!file.existsSync()) {
389 file.createSync(); 471 file.createSync();
390 } 472 }
391 file.openSync(); 473 file.openSync();
392 file.writeAsString(text); 474 file.writeAsString(text);
393 } 475 }
OLDNEW
« no previous file with comments | « pkg/docgen/example/test.dart ('k') | pkg/docgen/lib/src/dart2js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698