Chromium Code Reviews| 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.keys.forEach((qualifiedName) { | |
| 628 var method = methods[qualifiedName]; | |
|
Alan Knight
2013/08/02 18:32:22
Since you're actually using the value, this might
janicejl
2013/08/02 21:40:27
Done.
| |
| 629 if (method != null) { | |
| 630 if (method.comment == "") { | |
|
Alan Knight
2013/08/02 18:32:22
I think this might also work better if you named t
janicejl
2013/08/02 21:40:27
Done.
| |
| 631 var inheritedMethod = inheritedMethods[qualifiedName]; | |
| 632 method.comment = inheritedMethod.comment; | |
| 633 if (method.comment != "") { | |
|
Alan Knight
2013/08/02 18:32:22
In fact, I think this could be rewritten to be muc
janicejl
2013/08/02 21:40:27
Done.
| |
| 634 method.commentInheritedFrom = | |
| 635 inheritedMethod.commentInheritedFrom == "" ? | |
| 636 inheritedMethod.qualifiedName : | |
| 637 inheritedMethod.commentInheritedFrom; | |
| 638 } else { | |
| 639 entityMap[inheritedMethod.owner].ensureComments(); | |
| 640 method.comment = inheritedMethod.comment; | |
| 641 method.commentInheritedFrom = inheritedMethod.commentInheritedFrom; | |
| 642 } | |
| 643 } | |
| 644 } | |
| 645 }); | |
| 646 } | |
| 647 | |
| 623 /// Generates a map describing the [Class] object. | 648 /// Generates a map describing the [Class] object. |
| 624 Map toMap() => { | 649 Map toMap() => { |
| 625 'name': name, | 650 'name': name, |
| 626 'qualifiedname': qualifiedName, | 651 'qualifiedname': qualifiedName, |
| 627 'comment': comment, | 652 'comment': comment, |
| 628 'superclass': superclass == null ? "" : (_filterPrivate(superclass)) ? | 653 'superclass': superclass == null ? "" : (_filterPrivate(superclass)) ? |
| 629 superclass.qualifiedName : "", | 654 superclass.qualifiedName : "", |
| 630 'implements': new List.from(interfaces.where((e) => _filterPrivate(e)) | 655 'implements': new List.from(interfaces.where((e) => _filterPrivate(e)) |
| 631 .map((e) => e.qualifiedName)), | 656 .map((e) => e.qualifiedName)), |
| 632 'subclass': new List.from(subclasses), | 657 'subclass': new List.from(subclasses), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 653 _currentClass = mirror; | 678 _currentClass = mirror; |
| 654 var clazz = _class(mirror); | 679 var clazz = _class(mirror); |
| 655 | 680 |
| 656 // Adding inherited parent variables and methods. | 681 // Adding inherited parent variables and methods. |
| 657 clazz.parent().forEach((parent) { | 682 clazz.parent().forEach((parent) { |
| 658 if (_filterPrivate(clazz)) { | 683 if (_filterPrivate(clazz)) { |
| 659 parent.addSubclass(clazz); | 684 parent.addSubclass(clazz); |
| 660 } | 685 } |
| 661 clazz.addInherited(parent); | 686 clazz.addInherited(parent); |
| 662 }); | 687 }); |
| 688 | |
| 689 clazz.ensureComments(); | |
| 663 | 690 |
| 664 if (isError(mirror.qualifiedName)) { | 691 if (isError(mirror.qualifiedName)) { |
| 665 errors[mirror.simpleName] = clazz; | 692 errors[mirror.simpleName] = clazz; |
| 666 } else if (mirror.isTypedef) { | 693 } else if (mirror.isTypedef) { |
| 667 if (_includePrivate || !mirror.isPrivate) { | 694 if (_includePrivate || !mirror.isPrivate) { |
| 668 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName, | 695 entityMap[mirror.qualifiedName] = new Typedef(mirror.simpleName, |
| 669 mirror.value.returnType.qualifiedName, _commentToHtml(mirror), | 696 mirror.value.returnType.qualifiedName, _commentToHtml(mirror), |
| 670 _generics(mirror), _parameters(mirror.value.parameters), | 697 _generics(mirror), _parameters(mirror.value.parameters), |
| 671 _annotations(mirror), mirror.qualifiedName, _isPrivate(mirror), | 698 _annotations(mirror), mirror.qualifiedName, _isPrivate(mirror), |
| 672 mirror.owner.qualifiedName); | 699 mirror.owner.qualifiedName); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 764 class Method extends Indexable { | 791 class Method extends Indexable { |
| 765 | 792 |
| 766 /// Parameters for this method. | 793 /// Parameters for this method. |
| 767 Map<String, Parameter> parameters; | 794 Map<String, Parameter> parameters; |
| 768 | 795 |
| 769 bool isStatic; | 796 bool isStatic; |
| 770 bool isAbstract; | 797 bool isAbstract; |
| 771 bool isConst; | 798 bool isConst; |
| 772 Type returnType; | 799 Type returnType; |
| 773 | 800 |
| 801 /// Qualified name to state where the comment is inherited from. | |
| 802 String commentInheritedFrom = ""; | |
| 803 | |
| 774 /// List of the meta annotations on the method. | 804 /// List of the meta annotations on the method. |
| 775 List<String> annotations; | 805 List<String> annotations; |
| 776 | 806 |
| 777 Method(String name, this.isStatic, this.isAbstract, this.isConst, | 807 Method(String name, this.isStatic, this.isAbstract, this.isConst, |
| 778 this.returnType, String comment, this.parameters, this.annotations, | 808 this.returnType, String comment, this.parameters, this.annotations, |
| 779 String qualifiedName, bool isPrivate, String owner) : super(name, comment, | 809 String qualifiedName, bool isPrivate, String owner) : super(name, comment, |
| 780 qualifiedName, isPrivate, owner); | 810 qualifiedName, isPrivate, owner); |
| 781 | 811 |
| 782 /// Generates a map describing the [Method] object. | 812 /// Generates a map describing the [Method] object. |
| 783 Map toMap() => { | 813 Map toMap() => { |
| 784 'name': name, | 814 'name': name, |
| 785 'qualifiedname': qualifiedName, | 815 'qualifiedname': qualifiedName, |
| 786 'comment': comment, | 816 'comment': comment, |
| 817 'commentfrom': commentInheritedFrom, | |
| 787 'static': isStatic.toString(), | 818 'static': isStatic.toString(), |
| 788 'abstract': isAbstract.toString(), | 819 'abstract': isAbstract.toString(), |
| 789 'constant': isConst.toString(), | 820 'constant': isConst.toString(), |
| 790 'return': new List.filled(1, returnType.toMap()), | 821 'return': new List.filled(1, returnType.toMap()), |
| 791 'parameters': recurseMap(parameters), | 822 'parameters': recurseMap(parameters), |
| 792 'annotations': new List.from(annotations) | 823 'annotations': new List.from(annotations) |
| 793 }; | 824 }; |
| 794 } | 825 } |
| 795 | 826 |
| 796 /** | 827 /** |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 } | 871 } |
| 841 } | 872 } |
| 842 | 873 |
| 843 Map toMap() => { | 874 Map toMap() => { |
| 844 'setters': recurseMap(setters), | 875 'setters': recurseMap(setters), |
| 845 'getters': recurseMap(getters), | 876 'getters': recurseMap(getters), |
| 846 'constructors': recurseMap(constructors), | 877 'constructors': recurseMap(constructors), |
| 847 'operators': recurseMap(operators), | 878 'operators': recurseMap(operators), |
| 848 'methods': recurseMap(regularMethods) | 879 'methods': recurseMap(regularMethods) |
| 849 }; | 880 }; |
| 881 | |
| 882 Method operator [](String qualifiedName) { | |
| 883 var method = setters[qualifiedName]; | |
|
Alan Knight
2013/08/02 18:32:22
I don't love the deep nesting. Redo as a loop over
janicejl
2013/08/02 21:40:27
Done.
| |
| 884 if (method != null) return method; | |
| 885 else { | |
| 886 method = getters[qualifiedName]; | |
| 887 if (method != null) return method; | |
| 888 else { | |
| 889 method = operators[qualifiedName]; | |
| 890 if (method != null) return method; | |
| 891 else { | |
| 892 method = regularMethods[qualifiedName]; | |
| 893 if (method != null) return method; | |
| 894 else return null; | |
| 895 } | |
| 896 } | |
| 897 } | |
| 898 } | |
| 899 | |
| 900 Iterable<String> get keys { | |
|
Alan Knight
2013/08/02 18:32:22
=> [setters, getters, operators, regularMethods].e
janicejl
2013/08/02 21:40:27
Done.
| |
| 901 var qualifiedNames = []; | |
| 902 qualifiedNames.addAll(setters.keys); | |
| 903 qualifiedNames.addAll(getters.keys); | |
| 904 qualifiedNames.addAll(operators.keys); | |
| 905 qualifiedNames.addAll(regularMethods.keys); | |
| 906 return qualifiedNames; | |
| 907 } | |
| 850 } | 908 } |
| 851 | 909 |
| 852 /** | 910 /** |
| 853 * A class containing properties of a Dart method/function parameter. | 911 * A class containing properties of a Dart method/function parameter. |
| 854 */ | 912 */ |
| 855 class Parameter { | 913 class Parameter { |
| 856 | 914 |
| 857 String name; | 915 String name; |
| 858 bool isOptional; | 916 bool isOptional; |
| 859 bool isNamed; | 917 bool isNamed; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 928 String outer; | 986 String outer; |
| 929 List<Type> inner; | 987 List<Type> inner; |
| 930 | 988 |
| 931 Type(this.outer, this.inner); | 989 Type(this.outer, this.inner); |
| 932 | 990 |
| 933 Map toMap() => { | 991 Map toMap() => { |
| 934 'outer': outer, | 992 'outer': outer, |
| 935 'inner': new List.from(inner.map((e) => e.toMap())) | 993 'inner': new List.from(inner.map((e) => e.toMap())) |
| 936 }; | 994 }; |
| 937 } | 995 } |
| OLD | NEW |