| OLD | NEW |
| 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 * Returns a map of [Class] objects constructed from inputted mirrors. | 361 * Returns a map of [Class] objects constructed from inputted mirrors. |
| 362 */ | 362 */ |
| 363 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, | 363 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, |
| 364 bool includePrivate) { | 364 bool includePrivate) { |
| 365 | 365 |
| 366 var abstractClasses = {}; | 366 var abstractClasses = {}; |
| 367 var classes = {}; | 367 var classes = {}; |
| 368 var typedefs = {}; | 368 var typedefs = {}; |
| 369 var errors = {}; | 369 var errors = {}; |
| 370 | 370 |
| 371 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { | 371 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
| 372 if (includePrivate || !mirror.isPrivate) { | 372 if (includePrivate || !mirror.isPrivate) { |
| 373 var superclass = (mirror.superclass != null) ? | 373 var superclass = (mirror.superclass != null) ? |
| 374 mirror.superclass.qualifiedName : ''; | 374 mirror.superclass.qualifiedName : ''; |
| 375 var interfaces = | 375 var interfaces = |
| 376 mirror.superinterfaces.map((interface) => interface.qualifiedName); | 376 mirror.superinterfaces.map((interface) => interface.qualifiedName); |
| 377 var clazz = new Class(mirrorName, superclass, _getComment(mirror), | 377 var clazz = new Class(mirrorName, superclass, _getComment(mirror), |
| 378 interfaces.toList(), _getVariables(mirror.variables, includePrivate), | 378 interfaces.toList(), _getVariables(mirror.variables, includePrivate), |
| 379 _getMethods(mirror.methods, includePrivate), | 379 _getMethods(mirror.methods, includePrivate), |
| 380 _getAnnotations(mirror), mirror.qualifiedName); | 380 _getAnnotations(mirror), _getGenerics(mirror), mirror.qualifiedName); |
| 381 _currentClass = mirror; | 381 _currentClass = mirror; |
| 382 | 382 |
| 383 if (isError(mirror.qualifiedName)) { | 383 if (isError(mirror.qualifiedName)) { |
| 384 errors[mirrorName] = clazz; | 384 errors[mirrorName] = clazz; |
| 385 } else if (mirror.isTypedef) { | 385 } else if (mirror.isTypedef) { |
| 386 typedefs[mirrorName] = clazz; | 386 typedefs[mirrorName] = clazz; |
| 387 } else if (mirror.isAbstract) { | 387 } else if (mirror.isAbstract) { |
| 388 abstractClasses[mirrorName] = clazz; | 388 abstractClasses[mirrorName] = clazz; |
| 389 } else if (mirror.isClass) { | 389 } else if (mirror.isClass) { |
| 390 classes[mirrorName] = clazz; | 390 classes[mirrorName] = clazz; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 410 _currentMember = mirror; | 410 _currentMember = mirror; |
| 411 data[mirror.simpleName] = new Parameter(mirror.simpleName, | 411 data[mirror.simpleName] = new Parameter(mirror.simpleName, |
| 412 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, | 412 mirror.isOptional, mirror.isNamed, mirror.hasDefaultValue, |
| 413 mirror.type.qualifiedName, mirror.defaultValue, | 413 mirror.type.qualifiedName, mirror.defaultValue, |
| 414 _getAnnotations(mirror)); | 414 _getAnnotations(mirror)); |
| 415 }); | 415 }); |
| 416 return data; | 416 return data; |
| 417 } | 417 } |
| 418 | 418 |
| 419 /** | 419 /** |
| 420 * Returns a map of [Generic] objects constructed from the class mirror. |
| 421 */ |
| 422 Map<String, Generic> _getGenerics(ClassMirror mirror) { |
| 423 return new Map.fromIterable(mirror.typeVariables, |
| 424 key: (e) => e.toString(), |
| 425 value: (e) => new Generic(e.toString(), e.upperBound.qualifiedName)); |
| 426 } |
| 427 |
| 428 /** |
| 420 * Writes text to a file in the 'docs' directory. | 429 * Writes text to a file in the 'docs' directory. |
| 421 */ | 430 */ |
| 422 void _writeToFile(String text, String filename) { | 431 void _writeToFile(String text, String filename) { |
| 423 Directory dir = new Directory('docs'); | 432 Directory dir = new Directory('docs'); |
| 424 if (!dir.existsSync()) { | 433 if (!dir.existsSync()) { |
| 425 dir.createSync(); | 434 dir.createSync(); |
| 426 } | 435 } |
| 427 File file = new File('docs/$filename'); | 436 File file = new File('docs/$filename'); |
| 428 if (!file.existsSync()) { | 437 if (!file.existsSync()) { |
| 429 file.createSync(); | 438 file.createSync(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 517 |
| 509 /// List of the names of interfaces that this class implements. | 518 /// List of the names of interfaces that this class implements. |
| 510 List<String> interfaces; | 519 List<String> interfaces; |
| 511 | 520 |
| 512 /// Top-level variables in the class. | 521 /// Top-level variables in the class. |
| 513 Map<String, Variable> variables; | 522 Map<String, Variable> variables; |
| 514 | 523 |
| 515 /// Methods in the class. | 524 /// Methods in the class. |
| 516 Map<String, Map<String, Method>> methods; | 525 Map<String, Map<String, Method>> methods; |
| 517 | 526 |
| 527 /// Generic infomation about the class. |
| 528 Map<String, Generic> generics; |
| 529 |
| 518 String name; | 530 String name; |
| 519 String superclass; | 531 String superclass; |
| 520 | 532 |
| 521 /// List of the meta annotations on the class. | 533 /// List of the meta annotations on the class. |
| 522 List<String> annotations; | 534 List<String> annotations; |
| 523 | 535 |
| 524 Class(this.name, this.superclass, this.comment, this.interfaces, | 536 Class(this.name, this.superclass, this.comment, this.interfaces, |
| 525 this.variables, this.methods, this.annotations, | 537 this.variables, this.methods, this.annotations, this.generics, |
| 526 String qualifiedName) : super(qualifiedName) {} | 538 String qualifiedName) : super(qualifiedName) {} |
| 527 | 539 |
| 528 /// Generates a map describing the [Class] object. | 540 /// Generates a map describing the [Class] object. |
| 529 Map toMap() { | 541 Map toMap() { |
| 530 var classMap = {}; | 542 var classMap = {}; |
| 531 classMap['name'] = name; | 543 classMap['name'] = name; |
| 532 classMap['comment'] = comment; | 544 classMap['comment'] = comment; |
| 533 classMap['superclass'] = superclass; | 545 classMap['superclass'] = superclass; |
| 534 classMap['implements'] = new List.from(interfaces); | 546 classMap['implements'] = new List.from(interfaces); |
| 535 classMap['variables'] = recurseMap(variables); | 547 classMap['variables'] = recurseMap(variables); |
| 536 classMap['methods'] = recurseMap(methods); | 548 classMap['methods'] = recurseMap(methods); |
| 537 classMap['annotations'] = new List.from(annotations); | 549 classMap['annotations'] = new List.from(annotations); |
| 550 classMap['generics'] = recurseMap(generics); |
| 538 return classMap; | 551 return classMap; |
| 539 } | 552 } |
| 540 } | 553 } |
| 541 | 554 |
| 542 /** | 555 /** |
| 543 * A class containing properties of a Dart variable. | 556 * A class containing properties of a Dart variable. |
| 544 */ | 557 */ |
| 545 class Variable extends Indexable { | 558 class Variable extends Indexable { |
| 546 | 559 |
| 547 /// Documentation comment with converted markdown. | 560 /// Documentation comment with converted markdown. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 parameterMap['name'] = name; | 643 parameterMap['name'] = name; |
| 631 parameterMap['optional'] = isOptional.toString(); | 644 parameterMap['optional'] = isOptional.toString(); |
| 632 parameterMap['named'] = isNamed.toString(); | 645 parameterMap['named'] = isNamed.toString(); |
| 633 parameterMap['default'] = hasDefaultValue.toString(); | 646 parameterMap['default'] = hasDefaultValue.toString(); |
| 634 parameterMap['type'] = type; | 647 parameterMap['type'] = type; |
| 635 parameterMap['value'] = defaultValue; | 648 parameterMap['value'] = defaultValue; |
| 636 parameterMap['annotations'] = new List.from(annotations); | 649 parameterMap['annotations'] = new List.from(annotations); |
| 637 return parameterMap; | 650 return parameterMap; |
| 638 } | 651 } |
| 639 } | 652 } |
| 653 |
| 654 /** |
| 655 * A class containing properties of a Generic. |
| 656 */ |
| 657 class Generic { |
| 658 String name; |
| 659 String type; |
| 660 |
| 661 Generic(this.name, this.type); |
| 662 |
| 663 Map toMap() { |
| 664 return { |
| 665 'name': name, |
| 666 'type': type |
| 667 }; |
| 668 } |
| 669 } |
| OLD | NEW |