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

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

Powered by Google App Engine
This is Rietveld 408576698