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

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

Powered by Google App Engine
This is Rietveld 408576698