| 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 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 typeName(type), typeUrl(type)]); | 812 typeName(type), typeUrl(type)]); |
| 813 writeln( | 813 writeln( |
| 814 ''' | 814 ''' |
| 815 <h2><strong>${typeName(type, showBounds: true)}</strong> | 815 <h2><strong>${typeName(type, showBounds: true)}</strong> |
| 816 $kind | 816 $kind |
| 817 </h2> | 817 </h2> |
| 818 '''); | 818 '''); |
| 819 writeln('<button id="show-inherited" class="show-inherited">' | 819 writeln('<button id="show-inherited" class="show-inherited">' |
| 820 'Hide inherited</button>'); | 820 'Hide inherited</button>'); |
| 821 | 821 |
| 822 docCode(type, type.location, getTypeComment(type)); | 822 writeln('<div class="doc">'); |
| 823 docComment(type, getTypeComment(type)); |
| 824 docCode(type.location); |
| 825 writeln('</div>'); |
| 826 |
| 823 docInheritance(type); | 827 docInheritance(type); |
| 824 docTypedef(type); | 828 docTypedef(type); |
| 825 | 829 |
| 826 docConstructors(type); | 830 docConstructors(type); |
| 827 docMembers(type); | 831 docMembers(type); |
| 828 | 832 |
| 829 writeTypeFooter(); | 833 writeTypeFooter(); |
| 830 writeFooter(); | 834 writeFooter(); |
| 831 endFile(); | 835 endFile(); |
| 832 } | 836 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 writeln('<button class="show-code">Code</button>'); | 961 writeln('<button class="show-code">Code</button>'); |
| 958 } | 962 } |
| 959 | 963 |
| 960 write('typedef '); | 964 write('typedef '); |
| 961 annotateType(type, type.definition, type.simpleName); | 965 annotateType(type, type.definition, type.simpleName); |
| 962 | 966 |
| 963 write(''' <a class="anchor-link" href="#${type.simpleName}" | 967 write(''' <a class="anchor-link" href="#${type.simpleName}" |
| 964 title="Permalink to ${type.simpleName}">#</a>'''); | 968 title="Permalink to ${type.simpleName}">#</a>'''); |
| 965 writeln('</h4>'); | 969 writeln('</h4>'); |
| 966 | 970 |
| 967 docCode(type, type.location, null, showCode: true); | 971 writeln('<div class="doc">'); |
| 972 docCode(type.location); |
| 973 writeln('</div>'); |
| 968 | 974 |
| 969 writeln('</div>'); | 975 writeln('</div>'); |
| 970 } | 976 } |
| 971 | 977 |
| 972 /** Document the constructors for [Type], if any. */ | 978 /** Document the constructors for [Type], if any. */ |
| 973 void docConstructors(InterfaceMirror type) { | 979 void docConstructors(InterfaceMirror type) { |
| 974 final constructors = <MethodMirror>[]; | 980 final constructors = <MethodMirror>[]; |
| 975 for (var constructor in type.constructors.getValues()) { | 981 for (var constructor in type.constructors.getValues()) { |
| 976 if (!constructor.isPrivate) { | 982 if (!constructor.isPrivate) { |
| 977 constructors.add(constructor); | 983 constructors.add(constructor); |
| 978 } | 984 } |
| 979 } | 985 } |
| 980 | 986 |
| 981 if (constructors.length > 0) { | 987 if (constructors.length > 0) { |
| 982 writeln('<div>'); | 988 writeln('<div>'); |
| 983 writeln('<h3>Constructors</h3>'); | 989 writeln('<h3>Constructors</h3>'); |
| 984 constructors.sort((x, y) => x.constructorName.toUpperCase().compareTo( | 990 constructors.sort((x, y) => x.constructorName.toUpperCase().compareTo( |
| 985 y.constructorName.toUpperCase())); | 991 y.constructorName.toUpperCase())); |
| 986 | 992 |
| 987 for (final constructor in constructors) { | 993 for (final constructor in constructors) { |
| 988 docMethod(type, constructor); | 994 docMethod(type, constructor); |
| 989 } | 995 } |
| 990 writeln('</div>'); | 996 writeln('</div>'); |
| 991 } | 997 } |
| 992 } | 998 } |
| 993 | 999 |
| 1000 static const operatorOrder = const <String>[ |
| 1001 '[]', '[]=', // Indexing. |
| 1002 '+', Mirror.UNARY_MINUS, '-', '*', '/', '~/', '%', // Arithmetic. |
| 1003 '&', '|', '^', '~', // Bitwise. |
| 1004 '<<', '>>', // Shift. |
| 1005 '<', '<=', '>', '>=', // Relational. |
| 1006 '==', // Equality. |
| 1007 ]; |
| 1008 |
| 1009 static final Map<String, int> operatorOrderMap = (){ |
| 1010 var map = new Map<String, int>(); |
| 1011 var index = 0; |
| 1012 for (String operator in operatorOrder) { |
| 1013 map[operator] = index++; |
| 1014 } |
| 1015 return map; |
| 1016 }(); |
| 1017 |
| 994 void docMembers(ObjectMirror host) { | 1018 void docMembers(ObjectMirror host) { |
| 995 // Collect the different kinds of members. | 1019 // Collect the different kinds of members. |
| 996 final staticMethods = []; | 1020 final staticMethods = []; |
| 997 final staticFields = []; | 1021 final staticGetters = new Map<String,MemberMirror>(); |
| 1022 final staticSetters = new Map<String,MemberMirror>(); |
| 998 final memberMap = new Map<String,MemberMirror>(); | 1023 final memberMap = new Map<String,MemberMirror>(); |
| 999 final instanceMethods = []; | 1024 final instanceMethods = []; |
| 1000 final instanceFields = []; | 1025 final instanceOperators = []; |
| 1026 final instanceGetters = new Map<String,MemberMirror>(); |
| 1027 final instanceSetters = new Map<String,MemberMirror>(); |
| 1001 | 1028 |
| 1002 host.declaredMembers.forEach((_, MemberMirror member) { | 1029 host.declaredMembers.forEach((_, MemberMirror member) { |
| 1003 if (member.isPrivate) return; | 1030 if (member.isPrivate) return; |
| 1004 if (host is LibraryMirror || member.isStatic) { | 1031 if (host is LibraryMirror || member.isStatic) { |
| 1005 if (member.isMethod) { | 1032 if (member is MethodMirror) { |
| 1006 staticMethods.add(member); | 1033 if (member.isGetter) { |
| 1007 } else if (member.isField) { | 1034 staticGetters[member.displayName] = member; |
| 1008 staticFields.add(member); | 1035 } else if (member.isSetter) { |
| 1036 staticSetters[member.displayName] = member; |
| 1037 } else { |
| 1038 staticMethods.add(member); |
| 1039 } |
| 1040 } else if (member is FieldMirror) { |
| 1041 staticGetters[member.displayName] = member; |
| 1009 } | 1042 } |
| 1010 } | 1043 } |
| 1011 }); | 1044 }); |
| 1012 | 1045 |
| 1013 if (host is InterfaceMirror) { | 1046 if (host is InterfaceMirror) { |
| 1014 var iterable = new HierarchyIterable(host, includeType: true); | 1047 var iterable = new HierarchyIterable(host, includeType: true); |
| 1015 for (InterfaceMirror type in iterable) { | 1048 for (InterfaceMirror type in iterable) { |
| 1016 type.declaredMembers.forEach((_, MemberMirror member) { | 1049 type.declaredMembers.forEach((_, MemberMirror member) { |
| 1017 if (member.isPrivate) return; | 1050 if (member.isPrivate) return; |
| 1018 if (!member.isStatic) { | 1051 if (!member.isStatic) { |
| 1019 memberMap.putIfAbsent(member.simpleName, () => member); | 1052 if (member.isField) { |
| 1053 // Fields override both getters and setters. |
| 1054 memberMap.putIfAbsent(member.simpleName, () => member); |
| 1055 memberMap.putIfAbsent('${member.simpleName}=', () => member); |
| 1056 } else { |
| 1057 memberMap.putIfAbsent(member.simpleName, () => member); |
| 1058 } |
| 1020 } | 1059 } |
| 1021 }); | 1060 }); |
| 1022 } | 1061 } |
| 1023 } | 1062 } |
| 1024 | 1063 |
| 1025 memberMap.forEach((_, MemberMirror member) { | 1064 memberMap.forEach((_, MemberMirror member) { |
| 1026 if (member.isMethod) { | 1065 if (member is MethodMirror) { |
| 1027 instanceMethods.add(member); | 1066 if (member.isGetter) { |
| 1028 } else if (member.isField) { | 1067 instanceGetters[member.displayName] = member; |
| 1029 instanceFields.add(member); | 1068 } else if (member.isSetter) { |
| 1069 instanceSetters[member.displayName] = member; |
| 1070 } else if (member.isOperator) { |
| 1071 instanceOperators.add(member); |
| 1072 } else { |
| 1073 instanceMethods.add(member); |
| 1074 } |
| 1075 } else if (member is FieldMirror) { |
| 1076 instanceGetters[member.displayName] = member; |
| 1030 } | 1077 } |
| 1031 }); | 1078 }); |
| 1032 | 1079 |
| 1033 if (staticFields.length > 0) { | 1080 instanceOperators.sort((MethodMirror a, MethodMirror b) { |
| 1034 final title = host is LibraryMirror ? 'Variables' : 'Static Fields'; | 1081 return operatorOrderMap[a.simpleName].compareTo( |
| 1082 operatorOrderMap[b.simpleName]); |
| 1083 }); |
| 1084 |
| 1085 docProperties(host, |
| 1086 host is LibraryMirror ? 'Properties' : 'Static Properties', |
| 1087 staticGetters, staticSetters); |
| 1088 docMethods(host, |
| 1089 host is LibraryMirror ? 'Functions' : 'Static Methods', |
| 1090 staticMethods); |
| 1091 |
| 1092 docProperties(host, 'Properties', instanceGetters, instanceSetters); |
| 1093 docMethods(host, 'Operators', instanceOperators); |
| 1094 docMethods(host, 'Methods', orderByName(instanceMethods)); |
| 1095 } |
| 1096 |
| 1097 /** |
| 1098 * Documents fields, getters, and setters as properties. |
| 1099 */ |
| 1100 void docProperties(ObjectMirror host, String title, |
| 1101 Map<String,MemberMirror> getters, |
| 1102 Map<String,MemberMirror> setters) { |
| 1103 if (getters.isEmpty() && setters.isEmpty()) return; |
| 1104 |
| 1105 var nameSet = new Set<String>.from(getters.getKeys()); |
| 1106 nameSet.addAll(setters.getKeys()); |
| 1107 var nameList = new List<String>.from(nameSet); |
| 1108 nameList.sort((String a, String b) { |
| 1109 return a.toLowerCase().compareTo(b.toLowerCase()); |
| 1110 }); |
| 1111 |
| 1112 writeln('<div>'); |
| 1113 writeln('<h3>$title</h3>'); |
| 1114 for (String name in nameList) { |
| 1115 MemberMirror getter = getters[name]; |
| 1116 MemberMirror setter = setters[name]; |
| 1117 if (setter == null) { |
| 1118 if (getter is FieldMirror) { |
| 1119 // We have a field. |
| 1120 docField(host, getter); |
| 1121 } else { |
| 1122 // We only have a getter. |
| 1123 assert(getter is MethodMirror); |
| 1124 docProperty(host, getter, null); |
| 1125 } |
| 1126 } else if (getter == null) { |
| 1127 // We only have a setter => Document as a method. |
| 1128 assert(setter is MethodMirror); |
| 1129 docMethod(host, setter); |
| 1130 } else { |
| 1131 DocComment getterComment = getMemberComment(getter); |
| 1132 DocComment setterComment = getMemberComment(setter); |
| 1133 if (getter.surroundingDeclaration !== setter.surroundingDeclaration || |
| 1134 getterComment != null && setterComment != null) { |
| 1135 // Both have comments or are not declared in the same class |
| 1136 // => Documents separately. |
| 1137 if (getter is FieldMirror) { |
| 1138 // Document field as a getter (setter is inherited). |
| 1139 docField(host, getter, asGetter: true); |
| 1140 } else { |
| 1141 docMethod(host, getter); |
| 1142 } |
| 1143 if (setter is FieldMirror) { |
| 1144 // Document field as a setter (getter is inherited). |
| 1145 docField(host, setter, asSetter: true); |
| 1146 } else { |
| 1147 docMethod(host, setter); |
| 1148 } |
| 1149 } else { |
| 1150 // Document as field. |
| 1151 docProperty(host, getter, setter); |
| 1152 } |
| 1153 } |
| 1154 } |
| 1155 writeln('</div>'); |
| 1156 } |
| 1157 |
| 1158 void docMethods(ObjectMirror host, String title, List<MethodMirror> methods) { |
| 1159 if (methods.length > 0) { |
| 1035 writeln('<div>'); | 1160 writeln('<div>'); |
| 1036 writeln('<h3>$title</h3>'); | 1161 writeln('<h3>$title</h3>'); |
| 1037 for (final field in orderByName(staticFields)) { | 1162 for (final method in methods) { |
| 1038 docField(host, field); | |
| 1039 } | |
| 1040 writeln('</div>'); | |
| 1041 } | |
| 1042 | |
| 1043 if (staticMethods.length > 0) { | |
| 1044 final title = host is LibraryMirror ? 'Functions' : 'Static Methods'; | |
| 1045 writeln('<div>'); | |
| 1046 writeln('<h3>$title</h3>'); | |
| 1047 for (final method in orderByName(staticMethods)) { | |
| 1048 docMethod(host, method); | 1163 docMethod(host, method); |
| 1049 } | 1164 } |
| 1050 writeln('</div>'); | 1165 writeln('</div>'); |
| 1051 } | |
| 1052 | |
| 1053 if (instanceFields.length > 0) { | |
| 1054 writeln('<div>'); | |
| 1055 writeln('<h3>Fields</h3>'); | |
| 1056 for (final field in orderByName(instanceFields)) { | |
| 1057 docField(host, field); | |
| 1058 } | |
| 1059 writeln('</div>'); | |
| 1060 } | |
| 1061 | |
| 1062 if (instanceMethods.length > 0) { | |
| 1063 writeln('<div>'); | |
| 1064 writeln('<h3>Methods</h3>'); | |
| 1065 for (final method in orderByName(instanceMethods)) { | |
| 1066 docMethod(host, method); | |
| 1067 } | |
| 1068 writeln('</div>'); | |
| 1069 } | 1166 } |
| 1070 } | 1167 } |
| 1071 | 1168 |
| 1072 /** | 1169 /** |
| 1073 * Documents the [method] in type [type]. Handles all kinds of methods | 1170 * Documents the [member] declared in [host]. Handles all kinds of members |
| 1074 * including getters, setters, and constructors. | 1171 * including getters, setters, and constructors. If [member] is a |
| 1172 * [FieldMirror] it is documented as a getter or setter depending upon the |
| 1173 * value of [asGetter]. |
| 1075 */ | 1174 */ |
| 1076 void docMethod(ObjectMirror host, MethodMirror method) { | 1175 void docMethod(ObjectMirror host, MemberMirror member, |
| 1176 {bool asGetter: false}) { |
| 1077 _totalMembers++; | 1177 _totalMembers++; |
| 1078 _currentMember = method; | 1178 _currentMember = member; |
| 1079 | 1179 |
| 1080 bool showCode = includeSource && !method.isAbstract; | 1180 bool isAbstract = false; |
| 1081 bool inherited = host != method.surroundingDeclaration; | 1181 String name = member.displayName; |
| 1182 if (member is FieldMirror) { |
| 1183 if (asGetter) { |
| 1184 // Getter. |
| 1185 name = 'get $name'; |
| 1186 } else { |
| 1187 // Setter. |
| 1188 name = 'set $name'; |
| 1189 } |
| 1190 } else { |
| 1191 assert(member is MethodMirror); |
| 1192 isAbstract = member.isAbstract; |
| 1193 if (member.isGetter) { |
| 1194 // Getter. |
| 1195 name = 'get $name'; |
| 1196 } else if (member.isSetter) { |
| 1197 // Setter. |
| 1198 name = 'set $name'; |
| 1199 } |
| 1200 } |
| 1201 |
| 1202 bool showCode = includeSource && !isAbstract; |
| 1203 bool inherited = host != member.surroundingDeclaration; |
| 1082 | 1204 |
| 1083 writeln('<div class="method${inherited ? ' inherited': ''}">' | 1205 writeln('<div class="method${inherited ? ' inherited': ''}">' |
| 1084 '<h4 id="${memberAnchor(method)}">'); | 1206 '<h4 id="${memberAnchor(member)}">'); |
| 1085 | 1207 |
| 1086 if (showCode) { | 1208 if (showCode) { |
| 1087 writeln('<button class="show-code">Code</button>'); | 1209 writeln('<button class="show-code">Code</button>'); |
| 1088 } | 1210 } |
| 1089 | 1211 |
| 1090 if (method.isConstructor) { | 1212 if (member is MethodMirror) { |
| 1091 if (method.isFactory) { | 1213 if (member.isConstructor) { |
| 1092 write('factory '); | 1214 if (member.isFactory) { |
| 1215 write('factory '); |
| 1216 } else { |
| 1217 write(member.isConst ? 'const ' : 'new '); |
| 1218 } |
| 1219 } else if (member.isAbstract) { |
| 1220 write('abstract '); |
| 1221 } |
| 1222 |
| 1223 if (!member.isConstructor) { |
| 1224 annotateType(host, member.returnType); |
| 1225 } |
| 1226 } else { |
| 1227 assert(member is FieldMirror); |
| 1228 if (asGetter) { |
| 1229 annotateType(host, member.type); |
| 1093 } else { | 1230 } else { |
| 1094 write(method.isConst ? 'const ' : 'new '); | 1231 write('void '); |
| 1095 } | 1232 } |
| 1096 } else if (method.isAbstract) { | |
| 1097 write('abstract '); | |
| 1098 } | |
| 1099 | |
| 1100 if (!method.isConstructor) { | |
| 1101 annotateType(host, method.returnType); | |
| 1102 } | |
| 1103 | |
| 1104 var name = method.displayName; | |
| 1105 // Translate specially-named methods: getters, setters, operators. | |
| 1106 if (method.isGetter) { | |
| 1107 // Getter. | |
| 1108 name = 'get $name'; | |
| 1109 } else if (method.isSetter) { | |
| 1110 // Setter. | |
| 1111 name = 'set $name'; | |
| 1112 } | 1233 } |
| 1113 | 1234 |
| 1114 write('<strong>$name</strong>'); | 1235 write('<strong>$name</strong>'); |
| 1115 | 1236 |
| 1116 docParamList(host, method.parameters); | 1237 if (member is MethodMirror) { |
| 1238 if (!member.isGetter) { |
| 1239 docParamList(host, member.parameters); |
| 1240 } |
| 1241 } else { |
| 1242 assert(member is FieldMirror); |
| 1243 if (!asGetter) { |
| 1244 write('('); |
| 1245 annotateType(host, member.type); |
| 1246 write(' value)'); |
| 1247 } |
| 1248 } |
| 1117 | 1249 |
| 1118 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; | 1250 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; |
| 1119 write(''' <a class="anchor-link" href="#${memberAnchor(method)}" | 1251 write(''' <a class="anchor-link" href="#${memberAnchor(member)}" |
| 1120 title="Permalink to $prefix$name">#</a>'''); | 1252 title="Permalink to $prefix$name">#</a>'''); |
| 1121 writeln('</h4>'); | 1253 writeln('</h4>'); |
| 1122 | 1254 |
| 1123 if (inherited) { | 1255 if (inherited) { |
| 1124 write('<div class="inherited-from">inherited from '); | 1256 write('<div class="inherited-from">inherited from '); |
| 1125 annotateType(host, method.surroundingDeclaration); | 1257 annotateType(host, member.surroundingDeclaration); |
| 1126 write('</div>'); | 1258 write('</div>'); |
| 1127 } | 1259 } |
| 1128 | 1260 |
| 1129 docCode(host, method.location, getMemberComment(method), showCode: showCode)
; | 1261 writeln('<div class="doc">'); |
| 1262 docComment(host, getMemberComment(member)); |
| 1263 if (showCode) { |
| 1264 docCode(member.location); |
| 1265 } |
| 1266 writeln('</div>'); |
| 1130 | 1267 |
| 1131 writeln('</div>'); | 1268 writeln('</div>'); |
| 1132 } | 1269 } |
| 1133 | 1270 |
| 1134 /** Documents the field [field] of type [type]. */ | 1271 void docField(ObjectMirror host, FieldMirror field, |
| 1135 void docField(ObjectMirror host, FieldMirror field) { | 1272 {bool asGetter: false, bool asSetter: false}) { |
| 1273 if (asGetter) { |
| 1274 docMethod(host, field, asGetter: true); |
| 1275 } else if (asSetter) { |
| 1276 docMethod(host, field, asGetter: false); |
| 1277 } else { |
| 1278 docProperty(host, field, null); |
| 1279 } |
| 1280 } |
| 1281 |
| 1282 /** |
| 1283 * Documents the property defined by [getter] and [setter] of declared in |
| 1284 * [host]. If [getter] is a [FieldMirror], [setter] must be [:null:]. |
| 1285 * Otherwise, if [getter] is a [MethodMirror], the property is considered |
| 1286 * final if [setter] is [:null:]. |
| 1287 */ |
| 1288 void docProperty(ObjectMirror host, |
| 1289 MemberMirror getter, MemberMirror setter) { |
| 1290 assert(getter != null); |
| 1136 _totalMembers++; | 1291 _totalMembers++; |
| 1137 _currentMember = field; | 1292 _currentMember = getter; |
| 1138 | 1293 |
| 1139 bool inherited = host != field.surroundingDeclaration; | 1294 bool inherited = host != getter.surroundingDeclaration; |
| 1140 | 1295 |
| 1141 writeln('<div class="field${inherited ? ' inherited' : ''}">' | 1296 writeln('<div class="field${inherited ? ' inherited' : ''}">' |
| 1142 '<h4 id="${memberAnchor(field)}">'); | 1297 '<h4 id="${memberAnchor(getter)}">'); |
| 1143 | 1298 |
| 1144 if (includeSource) { | 1299 if (includeSource) { |
| 1145 writeln('<button class="show-code">Code</button>'); | 1300 writeln('<button class="show-code">Code</button>'); |
| 1146 } | 1301 } |
| 1147 | 1302 |
| 1148 if (field.isFinal) { | 1303 bool isConst = false; |
| 1304 bool isFinal; |
| 1305 TypeMirror type; |
| 1306 if (getter is FieldMirror) { |
| 1307 assert(setter == null); |
| 1308 isConst = getter.isConst; |
| 1309 isFinal = getter.isFinal; |
| 1310 type = getter.type; |
| 1311 } else { |
| 1312 assert(getter is MethodMirror); |
| 1313 isFinal = setter == null; |
| 1314 type = getter.returnType; |
| 1315 } |
| 1316 |
| 1317 if (isConst) { |
| 1318 write('const '); |
| 1319 } else if (isFinal) { |
| 1149 write('final '); | 1320 write('final '); |
| 1150 } else if (field.type.isDynamic) { | 1321 } else if (type.isDynamic) { |
| 1151 write('var '); | 1322 write('var '); |
| 1152 } | 1323 } |
| 1153 | 1324 |
| 1154 annotateType(host, field.type); | 1325 annotateType(host, type); |
| 1155 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; | 1326 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; |
| 1156 write( | 1327 write( |
| 1157 ''' | 1328 ''' |
| 1158 <strong>${field.simpleName}</strong> <a class="anchor-link" | 1329 <strong>${getter.simpleName}</strong> <a class="anchor-link" |
| 1159 href="#${memberAnchor(field)}" | 1330 href="#${memberAnchor(getter)}" |
| 1160 title="Permalink to $prefix${field.simpleName}">#</a> | 1331 title="Permalink to $prefix${getter.simpleName}">#</a> |
| 1161 </h4> | 1332 </h4> |
| 1162 '''); | 1333 '''); |
| 1163 | 1334 |
| 1164 if (inherited) { | 1335 if (inherited) { |
| 1165 write('<div class="inherited-from">inherited from '); | 1336 write('<div class="inherited-from">inherited from '); |
| 1166 annotateType(host, field.surroundingDeclaration); | 1337 annotateType(host, getter.surroundingDeclaration); |
| 1167 write('</div>'); | 1338 write('</div>'); |
| 1168 } | 1339 } |
| 1169 | 1340 |
| 1170 docCode(host, field.location, getMemberComment(field), showCode: true); | 1341 DocComment comment = getMemberComment(getter); |
| 1342 if (comment == null && setter != null) { |
| 1343 comment = getMemberComment(setter); |
| 1344 } |
| 1345 writeln('<div class="doc">'); |
| 1346 docComment(host, comment); |
| 1347 docCode(getter.location); |
| 1348 if (setter != null) { |
| 1349 docCode(setter.location); |
| 1350 } |
| 1351 writeln('</div>'); |
| 1171 | 1352 |
| 1172 writeln('</div>'); | 1353 writeln('</div>'); |
| 1173 } | 1354 } |
| 1174 | 1355 |
| 1175 void docParamList(ObjectMirror enclosingType, | 1356 void docParamList(ObjectMirror enclosingType, |
| 1176 List<ParameterMirror> parameters) { | 1357 List<ParameterMirror> parameters) { |
| 1177 write('('); | 1358 write('('); |
| 1178 bool first = true; | 1359 bool first = true; |
| 1179 bool inOptionals = false; | 1360 bool inOptionals = false; |
| 1180 for (final parameter in parameters) { | 1361 for (final parameter in parameters) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1193 write(parameter.defaultValue); | 1374 write(parameter.defaultValue); |
| 1194 } | 1375 } |
| 1195 | 1376 |
| 1196 first = false; | 1377 first = false; |
| 1197 } | 1378 } |
| 1198 | 1379 |
| 1199 if (inOptionals) write(']'); | 1380 if (inOptionals) write(']'); |
| 1200 write(')'); | 1381 write(')'); |
| 1201 } | 1382 } |
| 1202 | 1383 |
| 1203 /** | 1384 void docComment(ObjectMirror host, DocComment comment) { |
| 1204 * Documents the code contained within [span] with [comment]. If [showCode] | |
| 1205 * is `true` (and [includeSource] is set), also includes the source code. | |
| 1206 */ | |
| 1207 void docCode(ObjectMirror host, Location location, DocComment comment, | |
| 1208 [bool showCode = false]) { | |
| 1209 writeln('<div class="doc">'); | |
| 1210 if (comment != null) { | 1385 if (comment != null) { |
| 1211 if (comment.inheritedFrom !== null) { | 1386 if (comment.inheritedFrom !== null) { |
| 1212 writeln('<div class="inherited">'); | 1387 writeln('<div class="inherited">'); |
| 1213 writeln(comment.html); | 1388 writeln(comment.html); |
| 1214 write('<div class="docs-inherited-from">docs inherited from '); | 1389 write('<div class="docs-inherited-from">docs inherited from '); |
| 1215 annotateType(host, comment.inheritedFrom); | 1390 annotateType(host, comment.inheritedFrom); |
| 1216 write('</div>'); | 1391 write('</div>'); |
| 1217 writeln('</div>'); | 1392 writeln('</div>'); |
| 1218 } else { | 1393 } else { |
| 1219 writeln(comment.html); | 1394 writeln(comment.html); |
| 1220 } | 1395 } |
| 1221 } | 1396 } |
| 1397 } |
| 1222 | 1398 |
| 1223 if (includeSource && showCode) { | 1399 /** |
| 1400 * Documents the source code contained within [location]. |
| 1401 */ |
| 1402 void docCode(Location location) { |
| 1403 if (includeSource) { |
| 1224 writeln('<pre class="source">'); | 1404 writeln('<pre class="source">'); |
| 1225 writeln(md.escapeHtml(unindentCode(location))); | 1405 writeln(md.escapeHtml(unindentCode(location))); |
| 1226 writeln('</pre>'); | 1406 writeln('</pre>'); |
| 1227 } | 1407 } |
| 1228 | |
| 1229 writeln('</div>'); | |
| 1230 } | 1408 } |
| 1231 | 1409 |
| 1232 DocComment createDocComment(String text, [InterfaceMirror inheritedFrom]) => | 1410 DocComment createDocComment(String text, [InterfaceMirror inheritedFrom]) => |
| 1233 new DocComment(text, inheritedFrom); | 1411 new DocComment(text, inheritedFrom); |
| 1234 | 1412 |
| 1235 | 1413 |
| 1236 /** Get the doc comment associated with the given library. */ | 1414 /** Get the doc comment associated with the given library. */ |
| 1237 DocComment getLibraryComment(LibraryMirror library) { | 1415 DocComment getLibraryComment(LibraryMirror library) { |
| 1238 // Look for a comment for the entire library. | 1416 // Look for a comment for the entire library. |
| 1239 final comment = _comments.findLibrary(library.location.source); | 1417 final comment = _comments.findLibrary(library.location.source); |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 final InterfaceMirror inheritedFrom; | 1817 final InterfaceMirror inheritedFrom; |
| 1640 | 1818 |
| 1641 DocComment(this.text, [this.inheritedFrom = null]) { | 1819 DocComment(this.text, [this.inheritedFrom = null]) { |
| 1642 assert(text != null && !text.trim().isEmpty()); | 1820 assert(text != null && !text.trim().isEmpty()); |
| 1643 } | 1821 } |
| 1644 | 1822 |
| 1645 String get html => md.markdownToHtml(text); | 1823 String get html => md.markdownToHtml(text); |
| 1646 | 1824 |
| 1647 String toString() => text; | 1825 String toString() => text; |
| 1648 } | 1826 } |
| OLD | NEW |