| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 * To generate docs for a library, run this script with the path to an | 6 * To generate docs for a library, run this script with the path to an |
| 7 * entrypoint .dart file, like: | 7 * entrypoint .dart file, like: |
| 8 * | 8 * |
| 9 * $ dart dartdoc.dart foo.dart | 9 * $ dart dartdoc.dart foo.dart |
| 10 * | 10 * |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 /** Set by Dartdoc user to print extra information during generation. */ | 189 /** Set by Dartdoc user to print extra information during generation. */ |
| 190 bool verbose = false; | 190 bool verbose = false; |
| 191 | 191 |
| 192 /** Set this to include API libraries in the documentation. */ | 192 /** Set this to include API libraries in the documentation. */ |
| 193 bool includeApi = false; | 193 bool includeApi = false; |
| 194 | 194 |
| 195 /** Set this to generate links to the online API. */ | 195 /** Set this to generate links to the online API. */ |
| 196 bool linkToApi = false; | 196 bool linkToApi = false; |
| 197 | 197 |
| 198 /** Set this to generate docs for private types and members. */ |
| 199 bool showPrivate = false; |
| 200 |
| 201 /** Set this to inherit from Object. */ |
| 202 bool inheritFromObject = false; |
| 203 |
| 198 /** Set this to select the libraries to include in the documentation. */ | 204 /** Set this to select the libraries to include in the documentation. */ |
| 199 List<String> includedLibraries = const <String>[]; | 205 List<String> includedLibraries = const <String>[]; |
| 200 | 206 |
| 201 /** Set this to select the libraries to exclude from the documentation. */ | 207 /** Set this to select the libraries to exclude from the documentation. */ |
| 202 List<String> excludedLibraries = const <String>[]; | 208 List<String> excludedLibraries = const <String>[]; |
| 203 | 209 |
| 204 /** | 210 /** |
| 205 * This list contains the libraries sorted in by the library name. | 211 * This list contains the libraries sorted in by the library name. |
| 206 */ | 212 */ |
| 207 List<LibraryMirror> _sortedLibraries; | 213 List<LibraryMirror> _sortedLibraries; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 void docLibraryNavigationJson(LibraryMirror library, List libraryList) { | 571 void docLibraryNavigationJson(LibraryMirror library, List libraryList) { |
| 566 var libraryInfo = {}; | 572 var libraryInfo = {}; |
| 567 libraryInfo[NAME] = library.simpleName; | 573 libraryInfo[NAME] = library.simpleName; |
| 568 final List members = docMembersJson(library.declaredMembers); | 574 final List members = docMembersJson(library.declaredMembers); |
| 569 if (!members.isEmpty()) { | 575 if (!members.isEmpty()) { |
| 570 libraryInfo[MEMBERS] = members; | 576 libraryInfo[MEMBERS] = members; |
| 571 } | 577 } |
| 572 | 578 |
| 573 final types = []; | 579 final types = []; |
| 574 for (InterfaceMirror type in orderByName(library.types.getValues())) { | 580 for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| 575 if (type.isPrivate) continue; | 581 if (!showPrivate && type.isPrivate) continue; |
| 576 | 582 |
| 577 var typeInfo = {}; | 583 var typeInfo = {}; |
| 578 typeInfo[NAME] = type.displayName; | 584 typeInfo[NAME] = type.displayName; |
| 579 if (type.isClass) { | 585 if (type.isClass) { |
| 580 typeInfo[KIND] = CLASS; | 586 typeInfo[KIND] = CLASS; |
| 581 } else if (type.isInterface) { | 587 } else if (type.isInterface) { |
| 582 typeInfo[KIND] = INTERFACE; | 588 typeInfo[KIND] = INTERFACE; |
| 583 } else { | 589 } else { |
| 584 assert(type.isTypedef); | 590 assert(type.isTypedef); |
| 585 typeInfo[KIND] = TYPEDEF; | 591 typeInfo[KIND] = TYPEDEF; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 601 if (!types.isEmpty()) { | 607 if (!types.isEmpty()) { |
| 602 libraryInfo[TYPES] = types; | 608 libraryInfo[TYPES] = types; |
| 603 } | 609 } |
| 604 | 610 |
| 605 libraryList.add(libraryInfo); | 611 libraryList.add(libraryInfo); |
| 606 } | 612 } |
| 607 | 613 |
| 608 List docMembersJson(Map<Object,MemberMirror> memberMap) { | 614 List docMembersJson(Map<Object,MemberMirror> memberMap) { |
| 609 final members = []; | 615 final members = []; |
| 610 for (MemberMirror member in orderByName(memberMap.getValues())) { | 616 for (MemberMirror member in orderByName(memberMap.getValues())) { |
| 611 if (member.isPrivate) continue; | 617 if (!showPrivate && member.isPrivate) continue; |
| 612 | 618 |
| 613 var memberInfo = {}; | 619 var memberInfo = {}; |
| 614 if (member.isField) { | 620 if (member.isField) { |
| 615 memberInfo[KIND] = FIELD; | 621 memberInfo[KIND] = FIELD; |
| 616 } else { | 622 } else { |
| 617 MethodMirror method = member; | 623 MethodMirror method = member; |
| 618 if (method.isConstructor) { | 624 if (method.isConstructor) { |
| 619 memberInfo[KIND] = CONSTRUCTOR; | 625 memberInfo[KIND] = CONSTRUCTOR; |
| 620 } else if (method.isSetter) { | 626 } else if (method.isSetter) { |
| 621 memberInfo[KIND] = SETTER; | 627 memberInfo[KIND] = SETTER; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 writeln('</div>'); | 669 writeln('</div>'); |
| 664 } | 670 } |
| 665 | 671 |
| 666 /** Writes the navigation for the types contained by the given library. */ | 672 /** Writes the navigation for the types contained by the given library. */ |
| 667 void docLibraryNavigation(LibraryMirror library) { | 673 void docLibraryNavigation(LibraryMirror library) { |
| 668 // Show the exception types separately. | 674 // Show the exception types separately. |
| 669 final types = <InterfaceMirror>[]; | 675 final types = <InterfaceMirror>[]; |
| 670 final exceptions = <InterfaceMirror>[]; | 676 final exceptions = <InterfaceMirror>[]; |
| 671 | 677 |
| 672 for (InterfaceMirror type in orderByName(library.types.getValues())) { | 678 for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| 673 if (type.isPrivate) continue; | 679 if (!showPrivate && type.isPrivate) continue; |
| 674 | 680 |
| 675 if (isException(type)) { | 681 if (isException(type)) { |
| 676 exceptions.add(type); | 682 exceptions.add(type); |
| 677 } else { | 683 } else { |
| 678 types.add(type); | 684 types.add(type); |
| 679 } | 685 } |
| 680 } | 686 } |
| 681 | 687 |
| 682 if ((types.length == 0) && (exceptions.length == 0)) return; | 688 if ((types.length == 0) && (exceptions.length == 0)) return; |
| 683 | 689 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 // Document the top-level members. | 735 // Document the top-level members. |
| 730 docMembers(library); | 736 docMembers(library); |
| 731 | 737 |
| 732 // Document the types. | 738 // Document the types. |
| 733 final classes = <InterfaceMirror>[]; | 739 final classes = <InterfaceMirror>[]; |
| 734 final interfaces = <InterfaceMirror>[]; | 740 final interfaces = <InterfaceMirror>[]; |
| 735 final typedefs = <TypedefMirror>[]; | 741 final typedefs = <TypedefMirror>[]; |
| 736 final exceptions = <InterfaceMirror>[]; | 742 final exceptions = <InterfaceMirror>[]; |
| 737 | 743 |
| 738 for (InterfaceMirror type in orderByName(library.types.getValues())) { | 744 for (InterfaceMirror type in orderByName(library.types.getValues())) { |
| 739 if (type.isPrivate) continue; | 745 if (!showPrivate && type.isPrivate) continue; |
| 740 | 746 |
| 741 if (isException(type)) { | 747 if (isException(type)) { |
| 742 exceptions.add(type); | 748 exceptions.add(type); |
| 743 } else if (type.isClass) { | 749 } else if (type.isClass) { |
| 744 classes.add(type); | 750 classes.add(type); |
| 745 } else if (type.isInterface){ | 751 } else if (type.isInterface){ |
| 746 interfaces.add(type); | 752 interfaces.add(type); |
| 747 } else if (type is TypedefMirror) { | 753 } else if (type is TypedefMirror) { |
| 748 typedefs.add(type); | 754 typedefs.add(type); |
| 749 } else { | 755 } else { |
| 750 throw new InternalError("internal error: unknown type $type."); | 756 throw new InternalError("internal error: unknown type $type."); |
| 751 } | 757 } |
| 752 } | 758 } |
| 753 | 759 |
| 754 docTypes(classes, 'Classes'); | 760 docTypes(classes, 'Classes'); |
| 755 docTypes(interfaces, 'Interfaces'); | 761 docTypes(interfaces, 'Interfaces'); |
| 756 docTypes(typedefs, 'Typedefs'); | 762 docTypes(typedefs, 'Typedefs'); |
| 757 docTypes(exceptions, 'Exceptions'); | 763 docTypes(exceptions, 'Exceptions'); |
| 758 | 764 |
| 759 writeFooter(); | 765 writeFooter(); |
| 760 endFile(); | 766 endFile(); |
| 761 | 767 |
| 762 for (final type in library.types.getValues()) { | 768 for (final type in library.types.getValues()) { |
| 763 if (type.isPrivate) continue; | 769 if (!showPrivate && type.isPrivate) continue; |
| 764 | 770 |
| 765 docType(type); | 771 docType(type); |
| 766 } | 772 } |
| 767 } | 773 } |
| 768 | 774 |
| 769 void docTypes(List types, String header) { | 775 void docTypes(List types, String header) { |
| 770 if (types.length == 0) return; | 776 if (types.length == 0) return; |
| 771 | 777 |
| 772 writeln('<div>'); | 778 writeln('<div>'); |
| 773 writeln('<h3>$header</h3>'); | 779 writeln('<h3>$header</h3>'); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 'Hide inherited</button>'); | 826 'Hide inherited</button>'); |
| 821 | 827 |
| 822 writeln('<div class="doc">'); | 828 writeln('<div class="doc">'); |
| 823 docComment(type, getTypeComment(type)); | 829 docComment(type, getTypeComment(type)); |
| 824 docCode(type.location); | 830 docCode(type.location); |
| 825 writeln('</div>'); | 831 writeln('</div>'); |
| 826 | 832 |
| 827 docInheritance(type); | 833 docInheritance(type); |
| 828 docTypedef(type); | 834 docTypedef(type); |
| 829 | 835 |
| 830 docConstructors(type); | |
| 831 docMembers(type); | 836 docMembers(type); |
| 832 | 837 |
| 833 writeTypeFooter(); | 838 writeTypeFooter(); |
| 834 writeFooter(); | 839 writeFooter(); |
| 835 endFile(); | 840 endFile(); |
| 836 } | 841 } |
| 837 | 842 |
| 838 /** Override this to write additional content at the end of a type's page. */ | 843 /** Override this to write additional content at the end of a type's page. */ |
| 839 void writeTypeFooter() { | 844 void writeTypeFooter() { |
| 840 // Do nothing. | 845 // Do nothing. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 869 */ | 874 */ |
| 870 void docInheritance(InterfaceMirror type) { | 875 void docInheritance(InterfaceMirror type) { |
| 871 // Don't show the inheritance details for Object. It doesn't have any base | 876 // Don't show the inheritance details for Object. It doesn't have any base |
| 872 // class (obviously) and it has too many subclasses to be useful. | 877 // class (obviously) and it has too many subclasses to be useful. |
| 873 if (type.isObject) return; | 878 if (type.isObject) return; |
| 874 | 879 |
| 875 // Writes an unordered list of references to types with an optional header. | 880 // Writes an unordered list of references to types with an optional header. |
| 876 listTypes(types, header) { | 881 listTypes(types, header) { |
| 877 if (types == null) return; | 882 if (types == null) return; |
| 878 | 883 |
| 879 // Skip private types. | 884 var publicTypes; |
| 880 final publicTypes = new List.from(types.filter((t) => !t.isPrivate)); | 885 if (showPrivate) { |
| 886 publicTypes = types; |
| 887 } else { |
| 888 // Skip private types. |
| 889 publicTypes = new List.from(types.filter((t) => !t.isPrivate)); |
| 890 } |
| 881 if (publicTypes.length == 0) return; | 891 if (publicTypes.length == 0) return; |
| 882 | 892 |
| 883 writeln('<h3>$header</h3>'); | 893 writeln('<h3>$header</h3>'); |
| 884 writeln('<p>'); | 894 writeln('<p>'); |
| 885 bool first = true; | 895 bool first = true; |
| 886 for (final t in publicTypes) { | 896 for (final t in publicTypes) { |
| 887 if (!first) write(', '); | 897 if (!first) write(', '); |
| 888 typeSpan(t); | 898 typeSpan(t); |
| 889 first = false; | 899 first = false; |
| 890 } | 900 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 title="Permalink to ${type.simpleName}">#</a>'''); | 978 title="Permalink to ${type.simpleName}">#</a>'''); |
| 969 writeln('</h4>'); | 979 writeln('</h4>'); |
| 970 | 980 |
| 971 writeln('<div class="doc">'); | 981 writeln('<div class="doc">'); |
| 972 docCode(type.location); | 982 docCode(type.location); |
| 973 writeln('</div>'); | 983 writeln('</div>'); |
| 974 | 984 |
| 975 writeln('</div>'); | 985 writeln('</div>'); |
| 976 } | 986 } |
| 977 | 987 |
| 978 /** Document the constructors for [Type], if any. */ | |
| 979 void docConstructors(InterfaceMirror type) { | |
| 980 final constructors = <MethodMirror>[]; | |
| 981 for (var constructor in type.constructors.getValues()) { | |
| 982 if (!constructor.isPrivate) { | |
| 983 constructors.add(constructor); | |
| 984 } | |
| 985 } | |
| 986 | |
| 987 if (constructors.length > 0) { | |
| 988 writeln('<div>'); | |
| 989 writeln('<h3>Constructors</h3>'); | |
| 990 constructors.sort((x, y) => x.constructorName.toUpperCase().compareTo( | |
| 991 y.constructorName.toUpperCase())); | |
| 992 | |
| 993 for (final constructor in constructors) { | |
| 994 docMethod(type, constructor); | |
| 995 } | |
| 996 writeln('</div>'); | |
| 997 } | |
| 998 } | |
| 999 | |
| 1000 static const operatorOrder = const <String>[ | 988 static const operatorOrder = const <String>[ |
| 1001 '[]', '[]=', // Indexing. | 989 '[]', '[]=', // Indexing. |
| 1002 '+', Mirror.UNARY_MINUS, '-', '*', '/', '~/', '%', // Arithmetic. | 990 '+', Mirror.UNARY_MINUS, '-', '*', '/', '~/', '%', // Arithmetic. |
| 1003 '&', '|', '^', '~', // Bitwise. | 991 '&', '|', '^', '~', // Bitwise. |
| 1004 '<<', '>>', // Shift. | 992 '<<', '>>', // Shift. |
| 1005 '<', '<=', '>', '>=', // Relational. | 993 '<', '<=', '>', '>=', // Relational. |
| 1006 '==', // Equality. | 994 '==', // Equality. |
| 1007 ]; | 995 ]; |
| 1008 | 996 |
| 1009 static final Map<String, int> operatorOrderMap = (){ | 997 static final Map<String, int> operatorOrderMap = (){ |
| 1010 var map = new Map<String, int>(); | 998 var map = new Map<String, int>(); |
| 1011 var index = 0; | 999 var index = 0; |
| 1012 for (String operator in operatorOrder) { | 1000 for (String operator in operatorOrder) { |
| 1013 map[operator] = index++; | 1001 map[operator] = index++; |
| 1014 } | 1002 } |
| 1015 return map; | 1003 return map; |
| 1016 }(); | 1004 }(); |
| 1017 | 1005 |
| 1018 void docMembers(ObjectMirror host) { | 1006 void docMembers(ObjectMirror host) { |
| 1019 // Collect the different kinds of members. | 1007 // Collect the different kinds of members. |
| 1020 final staticMethods = []; | 1008 final staticMethods = []; |
| 1021 final staticGetters = new Map<String,MemberMirror>(); | 1009 final staticGetters = new Map<String,MemberMirror>(); |
| 1022 final staticSetters = new Map<String,MemberMirror>(); | 1010 final staticSetters = new Map<String,MemberMirror>(); |
| 1023 final memberMap = new Map<String,MemberMirror>(); | 1011 final memberMap = new Map<String,MemberMirror>(); |
| 1024 final instanceMethods = []; | 1012 final instanceMethods = []; |
| 1025 final instanceOperators = []; | 1013 final instanceOperators = []; |
| 1026 final instanceGetters = new Map<String,MemberMirror>(); | 1014 final instanceGetters = new Map<String,MemberMirror>(); |
| 1027 final instanceSetters = new Map<String,MemberMirror>(); | 1015 final instanceSetters = new Map<String,MemberMirror>(); |
| 1016 final constructors = []; |
| 1028 | 1017 |
| 1029 host.declaredMembers.forEach((_, MemberMirror member) { | 1018 host.declaredMembers.forEach((_, MemberMirror member) { |
| 1030 if (member.isPrivate) return; | 1019 if (!showPrivate && member.isPrivate) return; |
| 1031 if (host is LibraryMirror || member.isStatic) { | 1020 if (host is LibraryMirror || member.isStatic) { |
| 1032 if (member is MethodMirror) { | 1021 if (member is MethodMirror) { |
| 1033 if (member.isGetter) { | 1022 if (member.isGetter) { |
| 1034 staticGetters[member.displayName] = member; | 1023 staticGetters[member.displayName] = member; |
| 1035 } else if (member.isSetter) { | 1024 } else if (member.isSetter) { |
| 1036 staticSetters[member.displayName] = member; | 1025 staticSetters[member.displayName] = member; |
| 1037 } else { | 1026 } else { |
| 1038 staticMethods.add(member); | 1027 staticMethods.add(member); |
| 1039 } | 1028 } |
| 1040 } else if (member is FieldMirror) { | 1029 } else if (member is FieldMirror) { |
| 1041 staticGetters[member.displayName] = member; | 1030 staticGetters[member.displayName] = member; |
| 1042 } | 1031 } |
| 1043 } | 1032 } |
| 1044 }); | 1033 }); |
| 1045 | 1034 |
| 1046 if (host is InterfaceMirror) { | 1035 if (host is InterfaceMirror) { |
| 1047 var iterable = new HierarchyIterable(host, includeType: true); | 1036 var iterable = new HierarchyIterable(host, includeType: true); |
| 1048 for (InterfaceMirror type in iterable) { | 1037 for (InterfaceMirror type in iterable) { |
| 1038 if (!host.isObject && !inheritFromObject && type.isObject) continue; |
| 1039 |
| 1049 type.declaredMembers.forEach((_, MemberMirror member) { | 1040 type.declaredMembers.forEach((_, MemberMirror member) { |
| 1050 if (member.isPrivate) return; | 1041 if (member.isStatic) return; |
| 1051 if (!member.isStatic) { | 1042 if (!showPrivate && member.isPrivate) return; |
| 1052 if (member.isField) { | 1043 |
| 1053 // Fields override both getters and setters. | 1044 bool inherit = true; |
| 1054 memberMap.putIfAbsent(member.simpleName, () => member); | 1045 if (type !== host) { |
| 1055 memberMap.putIfAbsent('${member.simpleName}=', () => member); | 1046 if (member.isPrivate) { |
| 1056 } else { | 1047 // Don't inherit private members. |
| 1057 memberMap.putIfAbsent(member.simpleName, () => member); | 1048 inherit = false; |
| 1058 } | 1049 } |
| 1050 if (member.isConstructor) { |
| 1051 // Don't inherit constructors. |
| 1052 inherit = false; |
| 1053 } |
| 1054 } |
| 1055 if (!inherit) return; |
| 1056 |
| 1057 if (member.isField) { |
| 1058 // Fields override both getters and setters. |
| 1059 memberMap.putIfAbsent(member.simpleName, () => member); |
| 1060 memberMap.putIfAbsent('${member.simpleName}=', () => member); |
| 1061 } else if (member.isConstructor) { |
| 1062 constructors.add(member); |
| 1063 } else { |
| 1064 memberMap.putIfAbsent(member.simpleName, () => member); |
| 1059 } | 1065 } |
| 1060 }); | 1066 }); |
| 1061 } | 1067 } |
| 1062 } | 1068 } |
| 1063 | 1069 |
| 1070 bool allMethodsInherited = true; |
| 1071 bool allPropertiesInherited = true; |
| 1072 bool allOperatorsInherited = true; |
| 1064 memberMap.forEach((_, MemberMirror member) { | 1073 memberMap.forEach((_, MemberMirror member) { |
| 1065 if (member is MethodMirror) { | 1074 if (member is MethodMirror) { |
| 1066 if (member.isGetter) { | 1075 if (member.isGetter) { |
| 1067 instanceGetters[member.displayName] = member; | 1076 instanceGetters[member.displayName] = member; |
| 1077 if (member.surroundingDeclaration == host) { |
| 1078 allPropertiesInherited = false; |
| 1079 } |
| 1068 } else if (member.isSetter) { | 1080 } else if (member.isSetter) { |
| 1069 instanceSetters[member.displayName] = member; | 1081 instanceSetters[member.displayName] = member; |
| 1082 if (member.surroundingDeclaration == host) { |
| 1083 allPropertiesInherited = false; |
| 1084 } |
| 1070 } else if (member.isOperator) { | 1085 } else if (member.isOperator) { |
| 1071 instanceOperators.add(member); | 1086 instanceOperators.add(member); |
| 1087 if (member.surroundingDeclaration == host) { |
| 1088 allOperatorsInherited = false; |
| 1089 } |
| 1072 } else { | 1090 } else { |
| 1073 instanceMethods.add(member); | 1091 instanceMethods.add(member); |
| 1092 if (member.surroundingDeclaration == host) { |
| 1093 allMethodsInherited = false; |
| 1094 } |
| 1074 } | 1095 } |
| 1075 } else if (member is FieldMirror) { | 1096 } else if (member is FieldMirror) { |
| 1076 instanceGetters[member.displayName] = member; | 1097 instanceGetters[member.displayName] = member; |
| 1098 if (member.surroundingDeclaration == host) { |
| 1099 allPropertiesInherited = false; |
| 1100 } |
| 1077 } | 1101 } |
| 1078 }); | 1102 }); |
| 1079 | 1103 |
| 1080 instanceOperators.sort((MethodMirror a, MethodMirror b) { | 1104 instanceOperators.sort((MethodMirror a, MethodMirror b) { |
| 1081 return operatorOrderMap[a.simpleName].compareTo( | 1105 return operatorOrderMap[a.simpleName].compareTo( |
| 1082 operatorOrderMap[b.simpleName]); | 1106 operatorOrderMap[b.simpleName]); |
| 1083 }); | 1107 }); |
| 1084 | 1108 |
| 1085 docProperties(host, | 1109 docProperties(host, |
| 1086 host is LibraryMirror ? 'Properties' : 'Static Properties', | 1110 host is LibraryMirror ? 'Properties' : 'Static Properties', |
| 1087 staticGetters, staticSetters); | 1111 staticGetters, staticSetters, allInherited: false); |
| 1088 docMethods(host, | 1112 docMethods(host, |
| 1089 host is LibraryMirror ? 'Functions' : 'Static Methods', | 1113 host is LibraryMirror ? 'Functions' : 'Static Methods', |
| 1090 staticMethods); | 1114 staticMethods, allInherited: false); |
| 1091 | 1115 |
| 1092 docProperties(host, 'Properties', instanceGetters, instanceSetters); | 1116 docMethods(host, 'Constructors', orderByName(constructors), |
| 1093 docMethods(host, 'Operators', instanceOperators); | 1117 allInherited: false); |
| 1094 docMethods(host, 'Methods', orderByName(instanceMethods)); | 1118 docProperties(host, 'Properties', instanceGetters, instanceSetters, |
| 1119 allInherited: allPropertiesInherited); |
| 1120 docMethods(host, 'Operators', instanceOperators, |
| 1121 allInherited: allOperatorsInherited); |
| 1122 docMethods(host, 'Methods', orderByName(instanceMethods), |
| 1123 allInherited: allMethodsInherited); |
| 1095 } | 1124 } |
| 1096 | 1125 |
| 1097 /** | 1126 /** |
| 1098 * Documents fields, getters, and setters as properties. | 1127 * Documents fields, getters, and setters as properties. |
| 1099 */ | 1128 */ |
| 1100 void docProperties(ObjectMirror host, String title, | 1129 void docProperties(ObjectMirror host, String title, |
| 1101 Map<String,MemberMirror> getters, | 1130 Map<String,MemberMirror> getters, |
| 1102 Map<String,MemberMirror> setters) { | 1131 Map<String,MemberMirror> setters, |
| 1132 {bool allInherited}) { |
| 1103 if (getters.isEmpty() && setters.isEmpty()) return; | 1133 if (getters.isEmpty() && setters.isEmpty()) return; |
| 1104 | 1134 |
| 1105 var nameSet = new Set<String>.from(getters.getKeys()); | 1135 var nameSet = new Set<String>.from(getters.getKeys()); |
| 1106 nameSet.addAll(setters.getKeys()); | 1136 nameSet.addAll(setters.getKeys()); |
| 1107 var nameList = new List<String>.from(nameSet); | 1137 var nameList = new List<String>.from(nameSet); |
| 1108 nameList.sort((String a, String b) { | 1138 nameList.sort((String a, String b) { |
| 1109 return a.toLowerCase().compareTo(b.toLowerCase()); | 1139 return a.toLowerCase().compareTo(b.toLowerCase()); |
| 1110 }); | 1140 }); |
| 1111 | 1141 |
| 1112 writeln('<div>'); | 1142 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
| 1113 writeln('<h3>$title</h3>'); | 1143 writeln('<h3>$title</h3>'); |
| 1114 for (String name in nameList) { | 1144 for (String name in nameList) { |
| 1115 MemberMirror getter = getters[name]; | 1145 MemberMirror getter = getters[name]; |
| 1116 MemberMirror setter = setters[name]; | 1146 MemberMirror setter = setters[name]; |
| 1117 if (setter == null) { | 1147 if (setter == null) { |
| 1118 if (getter is FieldMirror) { | 1148 if (getter is FieldMirror) { |
| 1119 // We have a field. | 1149 // We have a field. |
| 1120 docField(host, getter); | 1150 docField(host, getter); |
| 1121 } else { | 1151 } else { |
| 1122 // We only have a getter. | 1152 // We only have a getter. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1148 } | 1178 } |
| 1149 } else { | 1179 } else { |
| 1150 // Document as field. | 1180 // Document as field. |
| 1151 docProperty(host, getter, setter); | 1181 docProperty(host, getter, setter); |
| 1152 } | 1182 } |
| 1153 } | 1183 } |
| 1154 } | 1184 } |
| 1155 writeln('</div>'); | 1185 writeln('</div>'); |
| 1156 } | 1186 } |
| 1157 | 1187 |
| 1158 void docMethods(ObjectMirror host, String title, List<MethodMirror> methods) { | 1188 void docMethods(ObjectMirror host, String title, List<MethodMirror> methods, |
| 1189 {bool allInherited}) { |
| 1159 if (methods.length > 0) { | 1190 if (methods.length > 0) { |
| 1160 writeln('<div>'); | 1191 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
| 1161 writeln('<h3>$title</h3>'); | 1192 writeln('<h3>$title</h3>'); |
| 1162 for (final method in methods) { | 1193 for (final method in methods) { |
| 1163 docMethod(host, method); | 1194 docMethod(host, method); |
| 1164 } | 1195 } |
| 1165 writeln('</div>'); | 1196 writeln('</div>'); |
| 1166 } | 1197 } |
| 1167 } | 1198 } |
| 1168 | 1199 |
| 1169 /** | 1200 /** |
| 1170 * Documents the [member] declared in [host]. Handles all kinds of members | 1201 * Documents the [member] declared in [host]. Handles all kinds of members |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1817 final InterfaceMirror inheritedFrom; | 1848 final InterfaceMirror inheritedFrom; |
| 1818 | 1849 |
| 1819 DocComment(this.text, [this.inheritedFrom = null]) { | 1850 DocComment(this.text, [this.inheritedFrom = null]) { |
| 1820 assert(text != null && !text.trim().isEmpty()); | 1851 assert(text != null && !text.trim().isEmpty()); |
| 1821 } | 1852 } |
| 1822 | 1853 |
| 1823 String get html => md.markdownToHtml(text); | 1854 String get html => md.markdownToHtml(text); |
| 1824 | 1855 |
| 1825 String toString() => text; | 1856 String toString() => text; |
| 1826 } | 1857 } |
| OLD | NEW |