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

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

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

Powered by Google App Engine
This is Rietveld 408576698