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

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

Issue 21096002: added inherited methods and variables (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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/test/single_library_test.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 * **docgen** is a tool for creating machine readable representations of Dart 6 * **docgen** is a tool for creating machine readable representations of Dart
7 * code metadata, including: classes, members, comments and annotations. 7 * code metadata, including: classes, members, comments and annotations.
8 * 8 *
9 * docgen is run on a `.dart` file or a directory containing `.dart` files. 9 * docgen is run on a `.dart` file or a directory containing `.dart` files.
10 * 10 *
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 /// Current member being documented to be used for comment links. 47 /// Current member being documented to be used for comment links.
48 MemberMirror _currentMember; 48 MemberMirror _currentMember;
49 49
50 /// Resolves reference links in doc comments. 50 /// Resolves reference links in doc comments.
51 markdown.Resolver linkResolver; 51 markdown.Resolver linkResolver;
52 52
53 /// Index of all the qualified names documented. 53 /// Index of all the qualified names documented.
54 Set<String> qualifiedNameIndex = new Set<String>(); 54 Set<String> qualifiedNameIndex = new Set<String>();
55 55
56 /// Index of all the items to output. This also ensures that no class is
57 /// created more than once.
58 Map<String, Indexable> entityMap = new Map<String, Indexable>();
59
56 /** 60 /**
57 * Docgen constructor initializes the link resolver for markdown parsing. 61 * Docgen constructor initializes the link resolver for markdown parsing.
58 * Also initializes the command line arguments. 62 * Also initializes the command line arguments.
59 * 63 *
60 * [packageRoot] is the packages directory of the directory being analyzed. 64 * [packageRoot] is the packages directory of the directory being analyzed.
61 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will 65 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will
62 * also be documented. 66 * also be documented.
63 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. 67 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented.
64 * This option is useful when only the SDK libraries are needed. 68 * This option is useful when only the SDK libraries are needed.
65 * 69 *
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // Currently, a string is thrown when it fails to create a mirror 192 // Currently, a string is thrown when it fails to create a mirror
189 // system, and it is not possible to use the stack trace. BUG(#11622) 193 // system, and it is not possible to use the stack trace. BUG(#11622)
190 // To avoid printing the stack trace. 194 // To avoid printing the stack trace.
191 exit(1); 195 exit(1);
192 }); 196 });
193 } 197 }
194 198
195 /** 199 /**
196 * Creates documentation for filtered libraries. 200 * Creates documentation for filtered libraries.
197 */ 201 */
198 void _documentLibraries(List<LibraryMirror> libraries, 202 void _documentLibraries(List<LibraryMirror> libs,
199 {bool includeSdk:false, bool includePrivate:false, bool 203 {bool includeSdk:false, bool includePrivate:false, bool
200 outputToYaml:true}) { 204 outputToYaml:true}) {
201 libraries.forEach((lib) { 205 libs.forEach((lib) {
202 // Files belonging to the SDK have a uri that begins with 'dart:'. 206 // Files belonging to the SDK have a uri that begins with 'dart:'.
203 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { 207 if (includeSdk || !lib.uri.toString().startsWith('dart:')) {
204 var library = generateLibrary(lib, includePrivate: includePrivate); 208 var library = generateLibrary(lib, includePrivate: includePrivate);
205 _writeLibraryToFile(library, outputToYaml); 209 entityMap[library.qualifiedName] = library;
206 } 210 }
207 }); 211 });
208 // Outputs a text file with a list of files available after creating all 212 // Output libraries and classes to file after all information is generated.
209 // the libraries. This will help the viewer know what files are available 213 entityMap.values.forEach((e) => _writeIndexableToFile(e, outputToYaml));
214 // Outputs a text file with a list of libraries available after creating all
215 // the libraries. This will help the viewer know what libraries are available
210 // to read in. 216 // to read in.
211 _writeToFile(listDir('docs').join('\n').replaceAll('docs/', ''), 217 _writeToFile(entityMap.values.where((e) => e is Library)
212 'library_list.txt'); 218 .map((e) => e.qualifiedName).join('\n'), 'library_list.txt');
213 // Outputs all the qualified names documented. This will help generate search 219 // Outputs all the qualified names documented. This will help generate search
214 // results. 220 // results.
215 _writeToFile(qualifiedNameIndex.join('\n'), 'index.txt'); 221 _writeToFile(qualifiedNameIndex.join('\n'), 'index.txt');
216 } 222 }
217 223
218 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, 224 Library generateLibrary(dart2js.Dart2JsLibraryMirror library,
219 {bool includePrivate:false}) { 225 {bool includePrivate:false}) {
220 _currentLibrary = library; 226 _currentLibrary = library;
221 var result = new Library(library.qualifiedName, _getComment(library), 227 var result = new Library(library.qualifiedName, _commentToHtml(library),
222 _getVariables(library.variables, includePrivate), 228 _variables(library.variables, includePrivate),
223 _getMethods(library.functions, includePrivate), 229 _methods(library.functions, includePrivate),
224 _getClasses(library.classes, includePrivate)); 230 _classes(library.classes, includePrivate));
225 logger.fine('Generated library for ${result.name}'); 231 logger.fine('Generated library for ${result.name}');
226 return result; 232 return result;
227 } 233 }
228 234
229 void _writeLibraryToFile(Library result, bool outputToYaml) { 235 void _writeIndexableToFile(Indexable result, bool outputToYaml) {
230 if (outputToYaml) { 236 if (outputToYaml) {
231 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); 237 _writeToFile(getYamlString(result.toMap()), '${result.qualifiedName}.yaml');
232 } else { 238 } else {
233 _writeToFile(stringify(result.toMap()), '${result.name}.json'); 239 _writeToFile(stringify(result.toMap()), '${result.qualifiedName}.json');
234 } 240 }
235
236 } 241 }
237 242
238 /** 243 /**
239 * Returns a list of meta annotations assocated with a mirror. 244 * Returns a list of meta annotations assocated with a mirror.
240 */ 245 */
241 List<String> _getAnnotations(DeclarationMirror mirror) { 246 List<String> _annotations(DeclarationMirror mirror) {
242 var annotations = mirror.metadata.where((e) => 247 var annotations = mirror.metadata.where((e) =>
243 e is dart2js.Dart2JsConstructedConstantMirror); 248 e is dart2js.Dart2JsConstructedConstantMirror);
244 return annotations.map((e) => e.type.qualifiedName).toList(); 249 return annotations.map((e) => e.type.qualifiedName).toList();
245 } 250 }
246 251
247 /** 252 /**
248 * Returns any documentation comments associated with a mirror with 253 * Returns any documentation comments associated with a mirror with
249 * simple markdown converted to html. 254 * simple markdown converted to html.
250 */ 255 */
251 String _getComment(DeclarationMirror mirror) { 256 String _commentToHtml(DeclarationMirror mirror) {
252 String commentText; 257 String commentText;
253 mirror.metadata.forEach((metadata) { 258 mirror.metadata.forEach((metadata) {
254 if (metadata is CommentInstanceMirror) { 259 if (metadata is CommentInstanceMirror) {
255 CommentInstanceMirror comment = metadata; 260 CommentInstanceMirror comment = metadata;
256 if (comment.isDocComment) { 261 if (comment.isDocComment) {
257 if (commentText == null) { 262 if (commentText == null) {
258 commentText = comment.trimmedText; 263 commentText = comment.trimmedText;
259 } else { 264 } else {
260 commentText = '$commentText ${comment.trimmedText}'; 265 commentText = '$commentText ${comment.trimmedText}';
261 } 266 }
(...skipping 19 matching lines...) Expand all
281 var classScope = currentClass == null ? 286 var classScope = currentClass == null ?
282 null : currentClass.lookupInScope(name); 287 null : currentClass.lookupInScope(name);
283 reference = classScope != null ? classScope.qualifiedName : name; 288 reference = classScope != null ? classScope.qualifiedName : name;
284 } 289 }
285 return new markdown.Element.text('a', reference); 290 return new markdown.Element.text('a', reference);
286 } 291 }
287 292
288 /** 293 /**
289 * Returns a map of [Variable] objects constructed from [mirrorMap]. 294 * Returns a map of [Variable] objects constructed from [mirrorMap].
290 */ 295 */
291 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, 296 Map<String, Variable> _variables(Map<String, VariableMirror> mirrorMap,
292 bool includePrivate) { 297 bool includePrivate) {
293 var data = {}; 298 var data = {};
294 // TODO(janicejl): When map to map feature is created, replace the below with 299 // TODO(janicejl): When map to map feature is created, replace the below with
295 // a filter. Issue(#9590). 300 // a filter. Issue(#9590).
296 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { 301 mirrorMap.forEach((String mirrorName, VariableMirror mirror) {
297 if (includePrivate || !mirror.isPrivate) { 302 if (includePrivate || !mirror.isPrivate) {
298 _currentMember = mirror; 303 _currentMember = mirror;
299 data[mirrorName] = new Variable(mirrorName, mirror.isFinal, 304 data[mirrorName] = new Variable(mirrorName, mirror.isFinal,
300 mirror.isStatic, mirror.isConst, _type(mirror.type), 305 mirror.isStatic, mirror.isConst, _type(mirror.type),
301 _getComment(mirror), _getAnnotations(mirror), mirror.qualifiedName); 306 _commentToHtml(mirror), _annotations(mirror), mirror.qualifiedName);
302 } 307 }
303 }); 308 });
304 return data; 309 return data;
305 } 310 }
306 311
307 /** 312 /**
308 * Returns a map of [Method] objects constructed from [mirrorMap]. 313 * Returns a map of [Method] objects constructed from [mirrorMap].
309 */ 314 */
310 Map<String, Map<String, Method>> _getMethods 315 MethodGroup _methods
311 (Map<String, MethodMirror> mirrorMap, bool includePrivate) { 316 (Map<String, MethodMirror> mirrorMap, bool includePrivate) {
312 317
313 var setters = {}; 318 var group = new MethodGroup();
314 var getters = {};
315 var constructors = {};
316 var operators = {};
317 var methods = {};
318 319
319 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { 320 mirrorMap.forEach((String mirrorName, MethodMirror mirror) {
320 if (includePrivate || !mirror.isPrivate) { 321 if (includePrivate || !mirror.isPrivate) {
321 var method = new Method(mirrorName, mirror.isStatic, mirror.isAbstract, 322 var method = new Method(mirrorName, mirror.isStatic, mirror.isAbstract,
322 mirror.isConstConstructor, _type(mirror.returnType), 323 mirror.isConstConstructor, _type(mirror.returnType),
323 _getComment(mirror), _getParameters(mirror.parameters), 324 _commentToHtml(mirror), _parameters(mirror.parameters),
324 _getAnnotations(mirror), mirror.qualifiedName); 325 _annotations(mirror), mirror.qualifiedName);
325 _currentMember = mirror; 326 _currentMember = mirror;
Alan Knight 2013/07/30 22:12:53 This whole method seems more like it should be a
326 if (mirror.isSetter) { 327 if (mirror.isSetter) {
327 setters[mirrorName] = method; 328 group.setters[mirrorName] = method;
328 } else if (mirror.isGetter) { 329 } else if (mirror.isGetter) {
329 getters[mirrorName] = method; 330 group.getters[mirrorName] = method;
330 } else if (mirror.isConstructor) { 331 } else if (mirror.isConstructor) {
331 constructors[mirrorName] = method; 332 group.constructors[mirrorName] = method;
332 } else if (mirror.isOperator) { 333 } else if (mirror.isOperator) {
333 operators[mirrorName] = method; 334 group.operators[mirrorName] = method;
334 } else if (mirror.isRegularMethod) { 335 } else if (mirror.isRegularMethod) {
335 methods[mirrorName] = method; 336 group.regularMethods[mirrorName] = method;
336 } else { 337 } else {
337 throw new ArgumentError('$mirrorName - no method type match'); 338 throw new ArgumentError('$mirrorName - no method type match');
338 } 339 }
339 } 340 }
340 }); 341 });
341 return { 342 return group;
342 'setters': setters,
343 'getters': getters,
344 'constructors': constructors,
345 'operators': operators,
346 'methods': methods
347 };
348 } 343 }
349 344
350 /** 345 /**
346 * Returns the [Class] for the given [mirror] has already been created, and if
347 * it does not exist, creates it.
348 */
349 Class _findOrCreateClass(ClassMirror mirror, bool includePrivate) {
Alan Knight 2013/07/30 22:12:53 Naming nit. The fact that we're caching these isn'
janicejl 2013/08/01 04:30:26 Done.
350 var clazz = entityMap[mirror.qualifiedName];
351 if (clazz == null) {
352 var superclass = (mirror.superclass != null) ?
353 mirror.superclass.qualifiedName : '';
354 var interfaces =
355 mirror.superinterfaces.map((interface) => interface.qualifiedName);
356 clazz = new Class(mirror.simpleName, superclass, _commentToHtml(mirror),
357 interfaces.toList(),
358 _variables(mirror.variables, includePrivate),
359 _methods(mirror.methods, includePrivate),
360 _annotations(mirror),
361 _generics(mirror), mirror.qualifiedName);
362 entityMap[mirror.qualifiedName] = clazz;
363 }
364 return clazz;
365 }
366
367 /**
351 * Returns a map of [Class] objects constructed from [mirrorMap]. 368 * Returns a map of [Class] objects constructed from [mirrorMap].
352 */ 369 */
353 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, 370 ClassGroup _classes(Map<String, ClassMirror> mirrorMap,
354 bool includePrivate) { 371 bool includePrivate) {
355 372
356 var abstractClasses = {}; 373 var group = new ClassGroup();
357 var classes = {};
358 var typedefs = {};
359 var errors = {};
360 374
361 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { 375 mirrorMap.forEach((String mirrorName, ClassMirror mirror) {
362 if (includePrivate || !mirror.isPrivate) { 376 if (includePrivate || !mirror.isPrivate) {
363 var superclass = (mirror.superclass != null) ?
364 mirror.superclass.qualifiedName : '';
365 var interfaces =
366 mirror.superinterfaces.map((interface) => interface.qualifiedName);
367 var clazz = new Class(mirrorName, superclass, _getComment(mirror),
368 interfaces.toList(), _getVariables(mirror.variables, includePrivate),
369 _getMethods(mirror.methods, includePrivate),
370 _getAnnotations(mirror), _getGenerics(mirror), mirror.qualifiedName);
371 _currentClass = mirror; 377 _currentClass = mirror;
378 var clazz = _findOrCreateClass(mirror, includePrivate);
379
380 // Adding inherited superclass variables and methods.
381 if (clazz.superclass != '') {
382 var superclazz = _findOrCreateClass(mirror.superclass, includePrivate);
383 superclazz.subclasses.add(clazz.qualifiedName);
384 clazz.inheritedMethods.addInherited(superclazz);
385 }
386
387 // Adding inherited interface variables and methods.
388 mirror.superinterfaces.forEach((interface) {
389 var interfaceClass = _findOrCreateClass(interface, includePrivate);
390 interfaceClass.subclasses.add(clazz.qualifiedName);
391 clazz.inheritedVariables.addAll(interfaceClass.variables);
392 clazz.inheritedMethods.addInherited(interfaceClass);
393 });
372 394
373 if (isError(mirror.qualifiedName)) { 395 if (isError(mirror.qualifiedName)) {
374 errors[mirrorName] = clazz; 396 group.errors[mirrorName] = clazz;
375 } else if (mirror.isTypedef) { 397 } else if (mirror.isTypedef) {
376 typedefs[mirrorName] = new Typedef(mirrorName, 398 group.typedefs[mirrorName] = new Typedef(mirrorName,
377 mirror.value.returnType.qualifiedName, _getComment(mirror), 399 mirror.value.returnType.qualifiedName, _commentToHtml(mirror),
378 _getGenerics(mirror), _getParameters(mirror.value.parameters), 400 _generics(mirror), _parameters(mirror.value.parameters),
379 _getAnnotations(mirror), mirror.qualifiedName); 401 _annotations(mirror), mirror.qualifiedName);
380 } else if (mirror.isAbstract) { 402 } else if (mirror.isAbstract) {
381 abstractClasses[mirrorName] = clazz; 403 group.abstractClasses[mirrorName] = clazz;
382 } else if (mirror.isClass) { 404 } else if (mirror.isClass) {
383 classes[mirrorName] = clazz; 405 group.regularClasses[mirrorName] = clazz;
384 } else { 406 } else {
385 throw new ArgumentError('$mirrorName - no class type match. '); 407 throw new ArgumentError('$mirrorName - no class type match. ');
386 } 408 }
387 } 409 }
388 }); 410 });
389 return { 411 return group;
390 'abstract': abstractClasses,
391 'class': classes,
392 'typedef': typedefs,
393 'error': errors
394 };
395 } 412 }
396 413
397 /** 414 /**
398 * Returns a map of [Parameter] objects constructed from [mirrorList]. 415 * Returns a map of [Parameter] objects constructed from [mirrorList].
399 */ 416 */
400 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { 417 Map<String, Parameter> _parameters(List<ParameterMirror> mirrorList) {
401 var data = {}; 418 var data = {};
402 mirrorList.forEach((ParameterMirror mirror) { 419 mirrorList.forEach((ParameterMirror mirror) {
403 _currentMember = mirror; 420 _currentMember = mirror;
404 data[mirror.simpleName] = new Parameter(mirror.simpleName, 421 data[mirror.simpleName] = new Parameter(mirror.simpleName,
405 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, 422 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue,
406 _type(mirror.type), mirror.defaultValue, 423 _type(mirror.type), mirror.defaultValue,
407 _getAnnotations(mirror)); 424 _annotations(mirror));
408 }); 425 });
409 return data; 426 return data;
410 } 427 }
411 428
412 /** 429 /**
413 * Returns a map of [Generic] objects constructed from the class mirror. 430 * Returns a map of [Generic] objects constructed from the class mirror.
414 */ 431 */
415 Map<String, Generic> _getGenerics(ClassMirror mirror) { 432 Map<String, Generic> _generics(ClassMirror mirror) {
416 return new Map.fromIterable(mirror.typeVariables, 433 return new Map.fromIterable(mirror.typeVariables,
417 key: (e) => e.toString(), 434 key: (e) => e.toString(),
418 value: (e) => new Generic(e.toString(), e.upperBound.qualifiedName)); 435 value: (e) => new Generic(e.toString(), e.upperBound.qualifiedName));
419 } 436 }
420 437
421 /** 438 /**
422 * Returns a single [Type] object constructed from the Method.returnType 439 * Returns a single [Type] object constructed from the Method.returnType
423 * Type mirror. 440 * Type mirror.
424 */ 441 */
425 Type _type(TypeMirror mirror) { 442 Type _type(TypeMirror mirror) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 511
495 /** 512 /**
496 * A class containing contents of a Dart library. 513 * A class containing contents of a Dart library.
497 */ 514 */
498 class Library extends Indexable { 515 class Library extends Indexable {
499 516
500 /// Top-level variables in the library. 517 /// Top-level variables in the library.
501 Map<String, Variable> variables; 518 Map<String, Variable> variables;
502 519
503 /// Top-level functions in the library. 520 /// Top-level functions in the library.
504 Map<String, Map<String, Method>> functions; 521 MethodGroup functions;
505 522
506 /// Classes defined within the library 523 /// Classes defined within the library
507 Map<String, Class> classes; 524 ClassGroup classes;
508 525
509 Library(String name, String comment, this.variables, 526 Library(String name, String comment, this.variables,
510 this.functions, this.classes) : super(name, comment, name) {} 527 this.functions, this.classes) : super(name, comment, name) {}
511 528
512 /// Generates a map describing the [Library] object. 529 /// Generates a map describing the [Library] object.
513 Map toMap() => { 530 Map toMap() => {
514 'name': name, 531 'name': name,
515 'qualifiedname': qualifiedName, 532 'qualifiedname': qualifiedName,
516 'comment': comment, 533 'comment': comment,
517 'variables': recurseMap(variables), 534 'variables': recurseMap(variables),
518 'functions': recurseMap(functions), 535 'functions': functions.toMap(),
519 'classes': recurseMap(classes) 536 'classes': classes.toMap()
520 }; 537 };
521 } 538 }
522 539
523 /** 540 /**
524 * A class containing contents of a Dart class. 541 * A class containing contents of a Dart class.
525 */ 542 */
526 class Class extends Indexable { 543 class Class extends Indexable {
527 544
528 /// List of the names of interfaces that this class implements. 545 /// List of the names of interfaces that this class implements.
529 List<String> interfaces; 546 List<String> interfaces;
547
548 /// Names of classes that extends or implements this class.
549 List<String> subclasses = [];
530 550
531 /// Top-level variables in the class. 551 /// Top-level variables in the class.
532 Map<String, Variable> variables; 552 Map<String, Variable> variables;
553
554 /// Inherited variables in the class.
555 Map<String, Variable> inheritedVariables = {};
533 556
534 /// Methods in the class. 557 /// Methods in the class.
535 Map<String, Map<String, Method>> methods; 558 MethodGroup methods;
559
560 /// Inherited methods in the class.
561 MethodGroup inheritedMethods = new MethodGroup();
536 562
537 /// Generic infomation about the class. 563 /// Generic infomation about the class.
538 Map<String, Generic> generics; 564 Map<String, Generic> generics;
539 565
540 String superclass; 566 String superclass;
541 567
542 /// List of the meta annotations on the class. 568 /// List of the meta annotations on the class.
543 List<String> annotations; 569 List<String> annotations;
544 570
545 Class(String name, this.superclass, String comment, this.interfaces, 571 Class(String name, this.superclass, String comment, this.interfaces,
546 this.variables, this.methods, this.annotations, this.generics, 572 this.variables, this.methods, this.annotations, this.generics,
547 String qualifiedName) : super(name, comment, qualifiedName) {} 573 String qualifiedName) : super(name, comment, qualifiedName) {}
548 574
549 /// Generates a map describing the [Class] object. 575 /// Generates a map describing the [Class] object.
550 Map toMap() => { 576 Map toMap() => {
551 'name': name, 577 'name': name,
552 'qualifiedname': qualifiedName, 578 'qualifiedname': qualifiedName,
553 'comment': comment, 579 'comment': comment,
554 'superclass': superclass, 580 'superclass': superclass,
555 'implements': new List.from(interfaces), 581 'implements': new List.from(interfaces),
556 'variables': recurseMap(variables), 582 'subclass': new List.from(subclasses),
557 'methods': recurseMap(methods), 583 'variables': recurseMap(variables),
558 'annotations': new List.from(annotations), 584 'inheritedvariables': recurseMap(inheritedVariables),
559 'generics': recurseMap(generics) 585 'methods': methods.toMap(),
560 }; 586 'inheritedmethods': inheritedMethods.toMap(),
587 'annotations': new List.from(annotations),
588 'generics': recurseMap(generics)
589 };
590 }
591
592 /**
593 * A container to categorize classes into the following groups: abstract
594 * classes, regular classes, typedefs, and errors.
595 */
596 class ClassGroup {
597 Map<String, Class> abstractClasses = {};
598 Map<String, Class> regularClasses = {};
599 Map<String, Typedef> typedefs = {};
600 Map<String, Class> errors = {};
601
602 Map toMap() => {
603 'abstract': new List.from(abstractClasses.values
604 .map((e) => e.qualifiedName)),
605 'class': new List.from(regularClasses.values.map((e) => e.qualifiedName)),
606 'typedef': recurseMap(typedefs),
607 'error': new List.from(errors.values.map((e) => e.qualifiedName))
608 };
561 } 609 }
562 610
563 class Typedef extends Indexable { 611 class Typedef extends Indexable {
564 String returnType; 612 String returnType;
565 613
566 Map<String, Parameter> parameters; 614 Map<String, Parameter> parameters;
567 615
568 /// Generic information about the typedef. 616 /// Generic information about the typedef.
569 Map<String, Generic> generics; 617 Map<String, Generic> generics;
570 618
571 /// List of the meta annotations on the typedef. 619 /// List of the meta annotations on the typedef.
572 List<String> annotations; 620 List<String> annotations;
573 621
574 Typedef(String name, this.returnType, String comment, this.generics, 622 Typedef(String name, this.returnType, String comment, this.generics,
575 this.parameters, this.annotations, 623 this.parameters, this.annotations,
576 String qualifiedName) : super(name, comment, qualifiedName) {} 624 String qualifiedName) : super(name, comment, qualifiedName) {}
577 625
578 Map toMap() => { 626 Map toMap() => {
579 'name': name, 627 'name': name,
580 'qualifiedname': qualifiedName, 628 'qualifiedname': qualifiedName,
581 'comment': comment, 629 'comment': comment,
582 'return': returnType, 630 'return': returnType,
583 'parameters': recurseMap(parameters), 631 'parameters': recurseMap(parameters),
584 'annotations': new List.from(annotations), 632 'annotations': new List.from(annotations),
585 'generics': recurseMap(generics) 633 'generics': recurseMap(generics)
586 }; 634 };
587 } 635 }
588 636
589 /** 637 /**
590 * A class containing properties of a Dart variable. 638 * A class containing properties of a Dart variable.
591 */ 639 */
592 class Variable extends Indexable { 640 class Variable extends Indexable {
593 641
594 bool isFinal; 642 bool isFinal;
595 bool isStatic; 643 bool isStatic;
596 bool isConst; 644 bool isConst;
597 Type type; 645 Type type;
598 646
599 /// List of the meta annotations on the variable. 647 /// List of the meta annotations on the variable.
600 List<String> annotations; 648 List<String> annotations;
601 649
602 Variable(String name, this.isFinal, this.isStatic, this.isConst, this.type, 650 Variable(String name, this.isFinal, this.isStatic, this.isConst, this.type,
603 String comment, this.annotations, String qualifiedName) : super(name, 651 String comment, this.annotations, String qualifiedName) : super(name,
604 comment, qualifiedName); 652 comment, qualifiedName);
605 653
606 /// Generates a map describing the [Variable] object. 654 /// Generates a map describing the [Variable] object.
607 Map toMap() => { 655 Map toMap() => {
608 'name': name, 656 'name': name,
609 'qualifiedname': qualifiedName, 657 'qualifiedname': qualifiedName,
610 'comment': comment, 658 'comment': comment,
611 'final': isFinal.toString(), 659 'final': isFinal.toString(),
612 'static': isStatic.toString(), 660 'static': isStatic.toString(),
613 'constant': isConst.toString(), 661 'constant': isConst.toString(),
614 'type': new List.filled(1, type.toMap()), 662 'type': new List.filled(1, type.toMap()),
615 'annotations': new List.from(annotations) 663 'annotations': new List.from(annotations)
616 }; 664 };
617 } 665 }
618 666
619 /** 667 /**
620 * A class containing properties of a Dart method. 668 * A class containing properties of a Dart method.
621 */ 669 */
622 class Method extends Indexable { 670 class Method extends Indexable {
623 671
624 /// Parameters for this method. 672 /// Parameters for this method.
625 Map<String, Parameter> parameters; 673 Map<String, Parameter> parameters;
626 674
627 bool isStatic; 675 bool isStatic;
628 bool isAbstract; 676 bool isAbstract;
629 bool isConst; 677 bool isConst;
630 Type returnType; 678 Type returnType;
631 679
632 /// List of the meta annotations on the method. 680 /// List of the meta annotations on the method.
633 List<String> annotations; 681 List<String> annotations;
634 682
635 Method(String name, this.isStatic, this.isAbstract, this.isConst, 683 Method(String name, this.isStatic, this.isAbstract, this.isConst,
636 this.returnType, String comment, this.parameters, this.annotations, 684 this.returnType, String comment, this.parameters, this.annotations,
637 String qualifiedName) 685 String qualifiedName)
638 : super(name, comment, qualifiedName); 686 : super(name, comment, qualifiedName);
639 687
640 /// Generates a map describing the [Method] object. 688 /// Generates a map describing the [Method] object.
641 Map toMap() => { 689 Map toMap() => {
642 'name': name, 690 'name': name,
643 'qualifiedname': qualifiedName, 691 'qualifiedname': qualifiedName,
644 'comment': comment, 692 'comment': comment,
645 'static': isStatic.toString(), 693 'static': isStatic.toString(),
646 'abstract': isAbstract.toString(), 694 'abstract': isAbstract.toString(),
647 'constant': isConst.toString(), 695 'constant': isConst.toString(),
648 'return': new List.filled(1, returnType.toMap()), 696 'return': new List.filled(1, returnType.toMap()),
649 'parameters': recurseMap(parameters), 697 'parameters': recurseMap(parameters),
650 'annotations': new List.from(annotations) 698 'annotations': new List.from(annotations)
651 }; 699 };
652 } 700 }
653 701
654 /** 702 /**
703 * A container to categorize methods into the following groups: setters,
704 * getters, constructors, operators, regular methods.
705 */
706 class MethodGroup {
707 Map<String, Method> setters = {};
708 Map<String, Method> getters = {};
709 Map<String, Method> constructors = {};
710 Map<String, Method> operators = {};
711 Map<String, Method> regularMethods = {};
712
713 void addInherited(Class implemented) {
714 setters.addAll(implemented.methods.setters);
715 getters.addAll(implemented.methods.getters);
716 operators.addAll(implemented.methods.operators);
717 regularMethods.addAll(implemented.methods.regularMethods);
718 }
719
720 Map toMap() => {
721 'setters': recurseMap(setters),
722 'getters': recurseMap(getters),
723 'constructors': recurseMap(constructors),
724 'operators': recurseMap(operators),
725 'methods': recurseMap(regularMethods)
726 };
727 }
728
729 /**
655 * A class containing properties of a Dart method/function parameter. 730 * A class containing properties of a Dart method/function parameter.
656 */ 731 */
657 class Parameter { 732 class Parameter {
658 733
659 String name; 734 String name;
660 bool isOptional; 735 bool isOptional;
661 bool isNamed; 736 bool isNamed;
662 bool hasDefaultValue; 737 bool hasDefaultValue;
663 Type type; 738 Type type;
664 String defaultValue; 739 String defaultValue;
665 740
666 /// List of the meta annotations on the parameter. 741 /// List of the meta annotations on the parameter.
667 List<String> annotations; 742 List<String> annotations;
668 743
669 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue, 744 Parameter(this.name, this.isOptional, this.isNamed, this.hasDefaultValue,
670 this.type, this.defaultValue, this.annotations); 745 this.type, this.defaultValue, this.annotations);
671 746
672 /// Generates a map describing the [Parameter] object. 747 /// Generates a map describing the [Parameter] object.
673 Map toMap() => { 748 Map toMap() => {
674 'name': name, 749 'name': name,
675 'optional': isOptional.toString(), 750 'optional': isOptional.toString(),
676 'named': isNamed.toString(), 751 'named': isNamed.toString(),
677 'default': hasDefaultValue.toString(), 752 'default': hasDefaultValue.toString(),
678 'type': new List.filled(1, type.toMap()), 753 'type': new List.filled(1, type.toMap()),
679 'value': defaultValue, 754 'value': defaultValue,
680 'annotations': new List.from(annotations) 755 'annotations': new List.from(annotations)
681 }; 756 };
682 } 757 }
683 758
684 /** 759 /**
685 * A class containing properties of a Generic. 760 * A class containing properties of a Generic.
686 */ 761 */
687 class Generic { 762 class Generic {
688 String name; 763 String name;
689 String type; 764 String type;
690 765
691 Generic(this.name, this.type); 766 Generic(this.name, this.type);
692 767
693 Map toMap() => { 768 Map toMap() => {
694 'name': name, 769 'name': name,
695 'type': type 770 'type': type
696 }; 771 };
697 } 772 }
698 773
699 /** 774 /**
700 * Holds the name of a return type, and its generic type parameters. 775 * Holds the name of a return type, and its generic type parameters.
701 * 776 *
702 * Return types are of a form [outer]<[inner]>. 777 * Return types are of a form [outer]<[inner]>.
703 * If there is no [inner] part, [inner] will be an empty list. 778 * If there is no [inner] part, [inner] will be an empty list.
704 * 779 *
705 * For example: 780 * For example:
706 * int size() 781 * int size()
(...skipping 19 matching lines...) Expand all
726 * - "outer" : "dart.core.int" 801 * - "outer" : "dart.core.int"
727 * "inner" : 802 * "inner" :
728 */ 803 */
729 class Type { 804 class Type {
730 String outer; 805 String outer;
731 List<Type> inner; 806 List<Type> inner;
732 807
733 Type(this.outer, this.inner); 808 Type(this.outer, this.inner);
734 809
735 Map toMap() => { 810 Map toMap() => {
736 'outer': outer, 811 'outer': outer,
737 'inner': new List.from(inner.map((e) => e.toMap())) 812 'inner': new List.from(inner.map((e) => e.toMap()))
738 }; 813 };
739 } 814 }
OLDNEW
« no previous file with comments | « pkg/docgen/example/test.dart ('k') | pkg/docgen/test/single_library_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698