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

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

Powered by Google App Engine
This is Rietveld 408576698