| 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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 this.isPrivate = true; | 613 this.isPrivate = true; |
| 614 // Since we are now making the mixin a private class, make all elements | 614 // Since we are now making the mixin a private class, make all elements |
| 615 // with the mixin as an owner private too. | 615 // with the mixin as an owner private too. |
| 616 entityMap.values.where((e) => e.owner == qualifiedName) | 616 entityMap.values.where((e) => e.owner == qualifiedName) |
| 617 .forEach((element) => element.isPrivate = true); | 617 .forEach((element) => element.isPrivate = true); |
| 618 // Move the subclass up to the next public superclass | 618 // Move the subclass up to the next public superclass |
| 619 subclasses.forEach((subclass) => addSubclass(entityMap[subclass])); | 619 subclasses.forEach((subclass) => addSubclass(entityMap[subclass])); |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 | 622 |
| 623 /** |
| 624 * Makes sure that all methods with inherited equivalents have comments. |
| 625 */ |
| 626 void ensureComments() { |
| 627 inheritedMethods.forEach((qualifiedName, inheritedMethod) { |
| 628 var method = methods[qualifiedName]; |
| 629 if (method != null) method.ensureCommentFor(inheritedMethod); |
| 630 }); |
| 631 } |
| 632 |
| 623 /** | 633 /** |
| 624 * If a class extends a private superclass, find the closest public superclass | 634 * If a class extends a private superclass, find the closest public superclass |
| 625 * of the private superclass. | 635 * of the private superclass. |
| 626 */ | 636 */ |
| 627 String validSuperclass() { | 637 String validSuperclass() { |
| 628 if (superclass == null) return 'dart.core.Object'; | 638 if (superclass == null) return 'dart.core.Object'; |
| 629 if (_isVisible(superclass)) return superclass.qualifiedName; | 639 if (_isVisible(superclass)) return superclass.qualifiedName; |
| 630 return superclass.validSuperclass(); | 640 return superclass.validSuperclass(); |
| 631 } | 641 } |
| 632 | 642 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 662 _currentClass = mirror; | 672 _currentClass = mirror; |
| 663 var clazz = _class(mirror); | 673 var clazz = _class(mirror); |
| 664 | 674 |
| 665 // Adding inherited parent variables and methods. | 675 // Adding inherited parent variables and methods. |
| 666 clazz.parent().forEach((parent) { | 676 clazz.parent().forEach((parent) { |
| 667 if (_isVisible(clazz)) { | 677 if (_isVisible(clazz)) { |
| 668 parent.addSubclass(clazz); | 678 parent.addSubclass(clazz); |
| 669 } | 679 } |
| 670 clazz.addInherited(parent); | 680 clazz.addInherited(parent); |
| 671 }); | 681 }); |
| 682 |
| 683 clazz.ensureComments(); |
| 672 | 684 |
| 673 if (isError(mirror.qualifiedName)) { | 685 if (isError(mirror.qualifiedName)) { |
| 674 errors[mirror.simpleName] = clazz; | 686 errors[mirror.simpleName] = clazz; |
| 675 } else if (mirror.isTypedef) { | 687 } else if (mirror.isTypedef) { |
| 676 if (_includePrivate || !mirror.isPrivate) { | 688 if (_includePrivate || !mirror.isPrivate) { |
| 677 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName, | 689 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName, |
| 678 mirror.value.returnType.qualifiedName, _commentToHtml(mirror), | 690 mirror.value.returnType.qualifiedName, _commentToHtml(mirror), |
| 679 _generics(mirror), _parameters(mirror.value.parameters), | 691 _generics(mirror), _parameters(mirror.value.parameters), |
| 680 _annotations(mirror), mirror.qualifiedName, _isPrivate(mirror), | 692 _annotations(mirror), mirror.qualifiedName, _isPrivate(mirror), |
| 681 mirror.owner.qualifiedName); | 693 mirror.owner.qualifiedName); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 class Method extends Indexable { | 785 class Method extends Indexable { |
| 774 | 786 |
| 775 /// Parameters for this method. | 787 /// Parameters for this method. |
| 776 Map<String, Parameter> parameters; | 788 Map<String, Parameter> parameters; |
| 777 | 789 |
| 778 bool isStatic; | 790 bool isStatic; |
| 779 bool isAbstract; | 791 bool isAbstract; |
| 780 bool isConst; | 792 bool isConst; |
| 781 Type returnType; | 793 Type returnType; |
| 782 | 794 |
| 795 /// Qualified name to state where the comment is inherited from. |
| 796 String commentInheritedFrom = ""; |
| 797 |
| 783 /// List of the meta annotations on the method. | 798 /// List of the meta annotations on the method. |
| 784 List<String> annotations; | 799 List<String> annotations; |
| 785 | 800 |
| 786 Method(String name, this.isStatic, this.isAbstract, this.isConst, | 801 Method(String name, this.isStatic, this.isAbstract, this.isConst, |
| 787 this.returnType, String comment, this.parameters, this.annotations, | 802 this.returnType, String comment, this.parameters, this.annotations, |
| 788 String qualifiedName, bool isPrivate, String owner) : super(name, comment, | 803 String qualifiedName, bool isPrivate, String owner) : super(name, comment, |
| 789 qualifiedName, isPrivate, owner); | 804 qualifiedName, isPrivate, owner); |
| 790 | 805 |
| 806 /** |
| 807 * Makes sure that the method with an inherited equivalent have comments. |
| 808 */ |
| 809 void ensureCommentFor(Method inheritedMethod) { |
| 810 if (comment.isNotEmpty) return; |
| 811 entityMap[inheritedMethod.owner].ensureComments(); |
| 812 comment = inheritedMethod.comment; |
| 813 commentInheritedFrom = inheritedMethod.commentInheritedFrom == '' ? |
| 814 inheritedMethod.qualifiedName : inheritedMethod.commentInheritedFrom; |
| 815 } |
| 816 |
| 791 /// Generates a map describing the [Method] object. | 817 /// Generates a map describing the [Method] object. |
| 792 Map toMap() => { | 818 Map toMap() => { |
| 793 'name': name, | 819 'name': name, |
| 794 'qualifiedname': qualifiedName, | 820 'qualifiedname': qualifiedName, |
| 795 'comment': comment, | 821 'comment': comment, |
| 822 'commentfrom': commentInheritedFrom, |
| 796 'static': isStatic.toString(), | 823 'static': isStatic.toString(), |
| 797 'abstract': isAbstract.toString(), | 824 'abstract': isAbstract.toString(), |
| 798 'constant': isConst.toString(), | 825 'constant': isConst.toString(), |
| 799 'return': new List.filled(1, returnType.toMap()), | 826 'return': new List.filled(1, returnType.toMap()), |
| 800 'parameters': recurseMap(parameters), | 827 'parameters': recurseMap(parameters), |
| 801 'annotations': new List.from(annotations) | 828 'annotations': new List.from(annotations) |
| 802 }; | 829 }; |
| 803 } | 830 } |
| 804 | 831 |
| 805 /** | 832 /** |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 } | 876 } |
| 850 } | 877 } |
| 851 | 878 |
| 852 Map toMap() => { | 879 Map toMap() => { |
| 853 'setters': recurseMap(setters), | 880 'setters': recurseMap(setters), |
| 854 'getters': recurseMap(getters), | 881 'getters': recurseMap(getters), |
| 855 'constructors': recurseMap(constructors), | 882 'constructors': recurseMap(constructors), |
| 856 'operators': recurseMap(operators), | 883 'operators': recurseMap(operators), |
| 857 'methods': recurseMap(regularMethods) | 884 'methods': recurseMap(regularMethods) |
| 858 }; | 885 }; |
| 886 |
| 887 Method operator [](String qualifiedName) { |
| 888 if (setters.containsKey(qualifiedName)) return setters[qualifiedName]; |
| 889 if (getters.containsKey(qualifiedName)) return getters[qualifiedName]; |
| 890 if (operators.containsKey(qualifiedName)) return operators[qualifiedName]; |
| 891 if (regularMethods.containsKey(qualifiedName)) { |
| 892 return regularMethods[qualifiedName]; |
| 893 } |
| 894 return null; |
| 895 } |
| 896 |
| 897 void forEach(void f(String key, Method value)) { |
| 898 setters.forEach(f); |
| 899 getters.forEach(f); |
| 900 operators.forEach(f); |
| 901 regularMethods.forEach(f); |
| 902 } |
| 859 } | 903 } |
| 860 | 904 |
| 861 /** | 905 /** |
| 862 * A class containing properties of a Dart method/function parameter. | 906 * A class containing properties of a Dart method/function parameter. |
| 863 */ | 907 */ |
| 864 class Parameter { | 908 class Parameter { |
| 865 | 909 |
| 866 String name; | 910 String name; |
| 867 bool isOptional; | 911 bool isOptional; |
| 868 bool isNamed; | 912 bool isNamed; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 String outer; | 981 String outer; |
| 938 List<Type> inner; | 982 List<Type> inner; |
| 939 | 983 |
| 940 Type(this.outer, this.inner); | 984 Type(this.outer, this.inner); |
| 941 | 985 |
| 942 Map toMap() => { | 986 Map toMap() => { |
| 943 'outer': outer, | 987 'outer': outer, |
| 944 'inner': new List.from(inner.map((e) => e.toMap())) | 988 'inner': new List.from(inner.map((e) => e.toMap())) |
| 945 }; | 989 }; |
| 946 } | 990 } |
| OLD | NEW |