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

Powered by Google App Engine
This is Rietveld 408576698