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

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

Issue 16915007: docgen working with a temporary link hack. (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]
Andrei Mouravski 2013/06/22 00:14:29 Make it: **myfile foodir ...**
janicejl 2013/06/22 00:36:44 Done.
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;
Andrei Mouravski 2013/06/22 00:14:29 Please order these like I've asked before.
janicejl 2013/06/22 00:36:44 Done.
24 import '../../args/lib/args.dart'; 21 import 'package:args/args.dart';
22 import 'dart2yaml.dart';
23 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
24 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart';
25 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro r.dart'
26 as dart2js;
25 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; 27 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ;
Andrei Mouravski 2013/06/22 00:14:29 Too long.
janicejl 2013/06/22 00:36:44 Cannot make shorter.
26 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; 28 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart';
29 import '../../../sdk/lib/_internal/compiler/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;
43 if (mirrors.isEmpty) {
44 print("no LibraryMirrors");
45 } else {
46 docgen.libraries = mirrors;
47 docgen.documentLibraries();
48 }
49 });
50 } 78 }
79 var libraries = new List<Path>();
80 var type = FileSystemEntity.typeSync(args[0]);
81
82 if (type == FileSystemEntityType.NOT_FOUND) {
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()}");
103 }
104 }
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 // DART_SDK should be set to the root of the SDK library.
163 var sdkRoot = Platform.environment["DART_SDK"];
164 if (sdkRoot != null) {
165 logger.info("Using DART_SDK to find SDK at $sdkRoot");
166 sdkRoot = new Path(sdkRoot);
167 } else {
168 // If DART_SDK is not defined in the environment,
169 // assuming the dart executable is from the Dart SDK folder inside bin.
170 sdkRoot = new Path(new Options().executable).directoryPath
171 .directoryPath;
172 logger.info("SDK Root: ${sdkRoot.toString()}");
173 }
174
175 Path packageDir = libraries.last.directoryPath.append("packages");
176 logger.info("Package Root: ${packageDir.toString()}");
177 getMirrorSystem(libraries, sdkRoot,
178 packageRoot: packageDir).then((MirrorSystem mirrorSystem) {
179 if (mirrorSystem.libraries.values.isEmpty) {
180 throw new UnsupportedError("No Library Mirrors.");
181 }
182 this.libraries = mirrorSystem.libraries.values;
183 documentLibraries();
184 });
185 }
186
187 /**
188 * Analyzes set of libraries and provides a mirror system which can be used
189 * for static inspection of the source code.
190 */
191 Future<MirrorSystem> getMirrorSystem(List<Path> libraries,
192 Path libraryRoot, {Path packageRoot}) {
193 SourceFileProvider provider = new SourceFileProvider();
194 api.DiagnosticHandler diagnosticHandler =
195 new FormattingDiagnosticHandler(provider).diagnosticHandler;
196 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot'));
197 Uri packageUri = null;
198 if (packageRoot != null) {
199 packageUri = currentDirectory.resolve(appendSlash('$packageRoot'));
200 }
201 List<Uri> librariesUri = <Uri>[];
202 libraries.forEach((library) {
203 librariesUri.add(currentDirectory.resolve(library.toString()));
204 });
205 return dart2js.analyze(librariesUri, libraryUri, packageUri,
206 provider.readStringFromUri, diagnosticHandler,
207 ['--preserve-comments', '--categories=Client,Server']);
208 }
209
210 /**
89 * Creates documentation for filtered libraries. 211 * Creates documentation for filtered libraries.
90 */ 212 */
91 void documentLibraries() { 213 void documentLibraries() {
92 //TODO(tmandel): Filter libraries and determine output type using flags.
93 _libraries.forEach((library) { 214 _libraries.forEach((library) {
94 _currentLibrary = library; 215 // Files belonging to the SDK have a uri that begins with "dart:".
95 var result = new Library(library.qualifiedName, _getComment(library), 216 if (sdk || !library.uri.toString().startsWith("dart:")) {
96 _getVariables(library.variables), _getMethods(library.functions), 217 _currentLibrary = library;
97 _getClasses(library.classes)); 218 var result = new Library(library.qualifiedName, _getComment(library),
98 if (outputToJson) { 219 _getVariables(library.variables), _getMethods(library.functions),
99 _writeToFile(stringify(result.toMap()), "${result.name}.json"); 220 _getClasses(library.classes), getID());
100 } else { 221 if (outputToJson) {
101 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml"); 222 _writeToFile(stringify(result.toMap()), "${result.name}.json");
102 } 223 }
224 if (outputToYaml) {
225 _writeToFile(getYamlString(result.toMap()), "${result.name}.yaml");
226 }
227 }
103 }); 228 });
104 } 229 }
105 230
106 /** 231 /**
107 * Returns any documentation comments associated with a mirror with 232 * Returns any documentation comments associated with a mirror with
108 * simple markdown converted to html. 233 * simple markdown converted to html.
109 */ 234 */
110 String _getComment(DeclarationMirror mirror) { 235 String _getComment(DeclarationMirror mirror) {
111 String commentText; 236 String commentText;
112 mirror.metadata.forEach((metadata) { 237 mirror.metadata.forEach((metadata) {
113 if (metadata is CommentInstanceMirror) { 238 if (metadata is CommentInstanceMirror) {
114 CommentInstanceMirror comment = metadata; 239 CommentInstanceMirror comment = metadata;
115 if (comment.isDocComment) { 240 if (comment.isDocComment) {
116 if (commentText == null) { 241 if (commentText == null) {
117 commentText = comment.trimmedText; 242 commentText = comment.trimmedText;
118 } else { 243 } else {
119 commentText = "$commentText ${comment.trimmedText}"; 244 commentText = "$commentText ${comment.trimmedText}";
120 } 245 }
121 } 246 }
122 } 247 }
123 }); 248 });
124 return commentText == null ? "" : 249 commentText = commentText == null ? "" :
125 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver); 250 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver)
251 .replaceAll("\n", "");
252 return commentText;
126 } 253 }
127 254
128 /** 255 /**
129 * Converts all [_] references in comments to <code>_</code>. 256 * Converts all [_] references in comments to <code>_</code>.
130 */ 257 */
131 // TODO(tmandel): Create proper links for [_] style markdown based 258 // TODO(tmandel): Create proper links for [_] style markdown based
132 // on scope once layout of viewer is finished. 259 // on scope once layout of viewer is finished.
133 markdown.Node fixReference(String name, LibraryMirror currentLibrary, 260 markdown.Node fixReference(String name, LibraryMirror currentLibrary,
134 ClassMirror currentClass, MemberMirror currentMember) { 261 ClassMirror currentClass, MemberMirror currentMember) {
135 return new markdown.Element.text('code', name); 262 return new markdown.Element.text('code', name);
136 } 263 }
137 264
138 /** 265 /**
139 * Returns a map of [Variable] objects constructed from inputted mirrors. 266 * Returns a map of [Variable] objects constructed from inputted mirrors.
140 */ 267 */
141 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { 268 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) {
142 var data = {}; 269 var data = {};
143 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 270 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
144 _currentMember = mirror; 271 if (!hidePrivate || !mirror.isPrivate) {
145 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 272 _currentMember = mirror;
146 mirror.isStatic, mirror.type.toString(), _getComment(mirror)); 273 data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
274 mirror.isStatic, mirror.type.toString(), _getComment(mirror),
275 getID());
276 }
147 }); 277 });
148 return data; 278 return data;
149 } 279 }
150 280
151 /** 281 /**
152 * Returns a map of [Method] objects constructed from inputted mirrors. 282 * Returns a map of [Method] objects constructed from inputted mirrors.
153 */ 283 */
154 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { 284 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) {
155 var data = {}; 285 var data = {};
156 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 286 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
157 _currentMember = mirror; 287 if (!hidePrivate || !mirror.isPrivate) {
158 data[mirrorName] = new Method(mirrorName, mirror.isSetter, 288 _currentMember = mirror;
159 mirror.isGetter, mirror.isConstructor, mirror.isOperator, 289 data[mirrorName] = new Method(mirrorName, mirror.isSetter,
160 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror), 290 mirror.isGetter, mirror.isConstructor, mirror.isOperator,
161 _getParameters(mirror.parameters)); 291 mirror.isStatic, mirror.returnType.toString(), _getComment(mirror),
292 _getParameters(mirror.parameters), getID());
293 }
162 }); 294 });
163 return data; 295 return data;
164 } 296 }
165 297
166 /** 298 /**
167 * Returns a map of [Class] objects constructed from inputted mirrors. 299 * Returns a map of [Class] objects constructed from inputted mirrors.
168 */ 300 */
169 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { 301 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) {
170 var data = {}; 302 var data = {};
171 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 303 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
172 _currentClass = mirror; 304 if (!hidePrivate || !mirror.isPrivate) {
173 var superclass; 305 _currentClass = mirror;
174 if (mirror.superclass != null) { 306 var superclass = (mirror.superclass != null) ?
175 superclass = mirror.superclass.qualifiedName; 307 mirror.superclass.qualifiedName : "";
308 var interfaces =
309 mirror.superinterfaces.map((interface) => interface.qualifiedName);
310 data[mirrorName] = new Class(mirrorName, superclass, mirror.isAbstract,
311 mirror.isTypedef, _getComment(mirror), interfaces.toList(),
312 _getVariables(mirror.variables), _getMethods(mirror.methods),
313 getID());
176 } 314 }
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 }); 315 });
183 return data; 316 return data;
184 } 317 }
185 318
186 /** 319 /**
187 * Returns a map of [Parameter] objects constructed from inputted mirrors. 320 * Returns a map of [Parameter] objects constructed from inputted mirrors.
188 */ 321 */
189 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 322 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) {
190 var data = {}; 323 var data = {};
191 mirrorList.forEach((ParameterMirror mirror) { 324 mirrorList.forEach((ParameterMirror mirror) {
192 _currentMember = mirror; 325 _currentMember = mirror;
193 data[mirror.simpleName] = new Parameter(mirror.simpleName, 326 data[mirror.simpleName] = new Parameter(mirror.simpleName,
194 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, 327 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
195 mirror.type.toString(), mirror.defaultValue); 328 mirror.type.toString(), mirror.defaultValue, getID());
196 }); 329 });
197 return data; 330 return data;
198 } 331 }
199 } 332 }
200 333
201 /** 334 /**
202 * Transforms the map by calling toMap on each value in it. 335 * Transforms the map by calling toMap on each value in it.
203 */ 336 */
204 Map recurseMap(Map inputMap) { 337 Map recurseMap(Map inputMap) {
205 var outputMap = {}; 338 var outputMap = {};
206 inputMap.forEach((key, value) { 339 inputMap.forEach((key, value) {
207 outputMap[key] = value.toMap(); 340 outputMap[key] = value.toMap();
208 }); 341 });
209 return outputMap; 342 return outputMap;
210 } 343 }
211 344
212 /** 345 /**
213 * A class containing contents of a Dart library. 346 * A class containing contents of a Dart library.
214 */ 347 */
215 class Library { 348 class Library {
216 349
350 /// Unique ID number for resolving links.
351 int id;
352
217 /// Documentation comment with converted markdown. 353 /// Documentation comment with converted markdown.
218 String comment; 354 String comment;
219 355
220 /// Top-level variables in the library. 356 /// Top-level variables in the library.
221 Map<String, Variable> variables; 357 Map<String, Variable> variables;
222 358
223 /// Top-level functions in the library. 359 /// Top-level functions in the library.
224 Map<String, Method> functions; 360 Map<String, Method> functions;
225 361
226 /// Classes defined within the library 362 /// Classes defined within the library
227 Map<String, Class> classes; 363 Map<String, Class> classes;
228 364
229 String name; 365 String name;
230 366
231 Library(this.name, this.comment, this.variables, 367 Library(this.name, this.comment, this.variables,
232 this.functions, this.classes); 368 this.functions, this.classes, this.id);
233 369
234 /// Generates a map describing the [Library] object. 370 /// Generates a map describing the [Library] object.
235 Map toMap() { 371 Map toMap() {
236 var libraryMap = {}; 372 var libraryMap = {};
373 libraryMap["id"] = id;
237 libraryMap["name"] = name; 374 libraryMap["name"] = name;
238 libraryMap["comment"] = comment; 375 libraryMap["comment"] = comment;
239 libraryMap["variables"] = recurseMap(variables); 376 libraryMap["variables"] = recurseMap(variables);
240 libraryMap["functions"] = recurseMap(functions); 377 libraryMap["functions"] = recurseMap(functions);
241 libraryMap["classes"] = recurseMap(classes); 378 libraryMap["classes"] = recurseMap(classes);
242 return libraryMap; 379 return libraryMap;
243 } 380 }
244 } 381 }
245 382
246 /** 383 /**
247 * A class containing contents of a Dart class. 384 * A class containing contents of a Dart class.
248 */ 385 */
249 // TODO(tmandel): Figure out how to do typedefs (what is needed) 386 // TODO(tmandel): Figure out how to do typedefs (what is needed)
250 class Class { 387 class Class {
251 388
389 /// Unique ID number for resolving links.
390 int id;
391
252 /// Documentation comment with converted markdown. 392 /// Documentation comment with converted markdown.
253 String comment; 393 String comment;
254 394
255 /// List of the names of interfaces that this class implements. 395 /// List of the names of interfaces that this class implements.
256 List<String> interfaces; 396 List<String> interfaces;
257 397
258 /// Top-level variables in the class. 398 /// Top-level variables in the class.
259 Map<String, Variable> variables; 399 Map<String, Variable> variables;
260 400
261 /// Methods in the class. 401 /// Methods in the class.
262 Map<String, Method> methods; 402 Map<String, Method> methods;
263 403
264 String name; 404 String name;
265 String superclass; 405 String superclass;
266 bool isAbstract; 406 bool isAbstract;
267 bool isTypedef; 407 bool isTypedef;
268 408
269 Class(this.name, this.superclass, this.isAbstract, this.isTypedef, 409 Class(this.name, this.superclass, this.isAbstract, this.isTypedef,
270 this.comment, this.interfaces, this.variables, this.methods); 410 this.comment, this.interfaces, this.variables, this.methods, this.id);
271 411
272 /// Generates a map describing the [Class] object. 412 /// Generates a map describing the [Class] object.
273 Map toMap() { 413 Map toMap() {
274 var classMap = {}; 414 var classMap = {};
415 classMap["id"] = id;
275 classMap["name"] = name; 416 classMap["name"] = name;
276 classMap["comment"] = comment; 417 classMap["comment"] = comment;
277 classMap["superclass"] = superclass; 418 classMap["superclass"] = superclass;
278 classMap["abstract"] = isAbstract.toString(); 419 classMap["abstract"] = isAbstract.toString();
279 classMap["typedef"] = isTypedef.toString(); 420 classMap["typedef"] = isTypedef.toString();
280 classMap["implements"] = new List.from(interfaces); 421 classMap["implements"] = new List.from(interfaces);
281 classMap["variables"] = recurseMap(variables); 422 classMap["variables"] = recurseMap(variables);
282 classMap["methods"] = recurseMap(methods); 423 classMap["methods"] = recurseMap(methods);
283 return classMap; 424 return classMap;
284 } 425 }
285 } 426 }
286 427
287 /** 428 /**
288 * A class containing properties of a Dart variable. 429 * A class containing properties of a Dart variable.
289 */ 430 */
290 class Variable { 431 class Variable {
291 432
433 /// Unique ID number for resolving links.
434 int id;
435
292 /// Documentation comment with converted markdown. 436 /// Documentation comment with converted markdown.
293 String comment; 437 String comment;
294 438
295 String name; 439 String name;
296 bool isFinal; 440 bool isFinal;
297 bool isStatic; 441 bool isStatic;
298 String type; 442 String type;
299 443
300 Variable(this.name, this.isFinal, this.isStatic, this.type, this.comment); 444 Variable(this.name, this.isFinal, this.isStatic, this.type,
445 this.comment, this.id);
301 446
302 /// Generates a map describing the [Variable] object. 447 /// Generates a map describing the [Variable] object.
303 Map toMap() { 448 Map toMap() {
304 var variableMap = {}; 449 var variableMap = {};
450 variableMap["id"] = id;
305 variableMap["name"] = name; 451 variableMap["name"] = name;
306 variableMap["comment"] = comment; 452 variableMap["comment"] = comment;
307 variableMap["final"] = isFinal.toString(); 453 variableMap["final"] = isFinal.toString();
308 variableMap["static"] = isStatic.toString(); 454 variableMap["static"] = isStatic.toString();
309 variableMap["type"] = type; 455 variableMap["type"] = type;
310 return variableMap; 456 return variableMap;
311 } 457 }
312 } 458 }
313 459
314 /** 460 /**
315 * A class containing properties of a Dart method. 461 * A class containing properties of a Dart method.
316 */ 462 */
317 class Method { 463 class Method {
318 464
465 /// Unique ID number for resolving links.
466 int id;
467
319 /// Documentation comment with converted markdown. 468 /// Documentation comment with converted markdown.
320 String comment; 469 String comment;
321 470
322 /// Parameters for this method. 471 /// Parameters for this method.
323 Map<String, Parameter> parameters; 472 Map<String, Parameter> parameters;
324 473
325 String name; 474 String name;
326 bool isSetter; 475 bool isSetter;
327 bool isGetter; 476 bool isGetter;
328 bool isConstructor; 477 bool isConstructor;
329 bool isOperator; 478 bool isOperator;
330 bool isStatic; 479 bool isStatic;
331 String returnType; 480 String returnType;
332 481
333 Method(this.name, this.isSetter, this.isGetter, this.isConstructor, 482 Method(this.name, this.isSetter, this.isGetter, this.isConstructor,
334 this.isOperator, this.isStatic, this.returnType, this.comment, 483 this.isOperator, this.isStatic, this.returnType, this.comment,
335 this.parameters); 484 this.parameters, this.id);
336 485
337 /// Generates a map describing the [Method] object. 486 /// Generates a map describing the [Method] object.
338 Map toMap() { 487 Map toMap() {
339 var methodMap = {}; 488 var methodMap = {};
489 methodMap["id"] = id;
340 methodMap["name"] = name; 490 methodMap["name"] = name;
341 methodMap["comment"] = comment; 491 methodMap["comment"] = comment;
342 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" : 492 methodMap["type"] = isSetter ? "setter" : isGetter ? "getter" :
343 isOperator ? "operator" : isConstructor ? "constructor" : "method"; 493 isOperator ? "operator" : isConstructor ? "constructor" : "method";
344 methodMap["static"] = isStatic.toString(); 494 methodMap["static"] = isStatic.toString();
345 methodMap["return"] = returnType; 495 methodMap["return"] = returnType;
346 methodMap["parameters"] = recurseMap(parameters); 496 methodMap["parameters"] = recurseMap(parameters);
347 return methodMap; 497 return methodMap;
348 } 498 }
349 } 499 }
350 500
351 /** 501 /**
352 * A class containing properties of a Dart method/function parameter. 502 * A class containing properties of a Dart method/function parameter.
353 */ 503 */
354 class Parameter { 504 class Parameter {
355 505
506 /// Unique ID number for resolving links.
507 int id;
508
356 String name; 509 String name;
357 bool isOptional; 510 bool isOptional;
358 bool isNamed; 511 bool isNamed;
359 bool hasDefaultValue; 512 bool hasDefaultValue;
360 String type; 513 String type;
361 String defaultValue; 514 String defaultValue;
362 515
363 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, 516 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
364 this.type, this.defaultValue); 517 this.type, this.defaultValue, this.id);
365 518
366 /// Generates a map describing the [Parameter] object. 519 /// Generates a map describing the [Parameter] object.
367 Map toMap() { 520 Map toMap() {
368 var parameterMap = {}; 521 var parameterMap = {};
522 parameterMap["id"] = id;
369 parameterMap["name"] = name; 523 parameterMap["name"] = name;
370 parameterMap["optional"] = isOptional.toString(); 524 parameterMap["optional"] = isOptional.toString();
371 parameterMap["named"] = isNamed.toString(); 525 parameterMap["named"] = isNamed.toString();
372 parameterMap["default"] = hasDefaultValue.toString(); 526 parameterMap["default"] = hasDefaultValue.toString();
373 parameterMap["type"] = type; 527 parameterMap["type"] = type;
374 parameterMap["value"] = defaultValue; 528 parameterMap["value"] = defaultValue;
375 return parameterMap; 529 return parameterMap;
376 } 530 }
377 } 531 }
378 532
379 /** 533 /**
380 * Writes text to a file in the 'docs' directory. 534 * Writes text to a file in the 'docs' directory.
381 */ 535 */
382 void _writeToFile(String text, String filename) { 536 void _writeToFile(String text, String filename) {
383 Directory dir = new Directory('docs'); 537 Directory dir = new Directory('docs');
384 if (!dir.existsSync()) { 538 if (!dir.existsSync()) {
385 dir.createSync(); 539 dir.createSync();
386 } 540 }
387 File file = new File('docs/$filename'); 541 File file = new File('docs/$filename');
388 if (!file.exists()) { 542 if (!file.existsSync()) {
389 file.createSync(); 543 file.createSync();
390 } 544 }
391 file.openSync(); 545 file.openSync();
392 file.writeAsString(text); 546 file.writeAsString(text);
393 } 547 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698