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

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

Powered by Google App Engine
This is Rietveld 408576698