Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(480)

Side by Side Diff: pkg/dartdoc/lib/dartdoc.dart

Issue 11028138: Fields, getters and setters documented as properties. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, 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
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, 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 const operatorOrder = const <String>[
1001 '[]', '[]=', // Indexing.
1002 '+', Mirror.UNARY_MINUS, '-', '*', '/', '~/', '%', // Arithmetic.
1003 '&', '|', '^', '~', // Bitwise.
1004 '<<', '>>', // Shift.
1005 '<', '<=', '>', '>=', // Relational.
1006 '==', // Equality.
1007 ];
1008
994 void docMembers(ObjectMirror host) { 1009 void docMembers(ObjectMirror host) {
995 // Collect the different kinds of members. 1010 // Collect the different kinds of members.
996 final staticMethods = []; 1011 final staticMethods = [];
997 final staticFields = []; 1012 final staticGetters = new Map<String,MemberMirror>();
Bob Nystrom 2012/10/11 17:04:21 Style nit: there should be spaces after the commas
Lasse Reichstein Nielsen 2012/10/12 09:47:26 I'm getting less and less attached to that space (
Johnni Winther 2012/10/12 11:15:53 I would even vote for a style guide change. Consid
Bob Nystrom 2012/10/12 16:09:02 I personally don't have any trouble reading it wit
1013 final staticSetters = new Map<String,MemberMirror>();
998 final memberMap = new Map<String,MemberMirror>(); 1014 final memberMap = new Map<String,MemberMirror>();
999 final instanceMethods = []; 1015 final instanceMethods = [];
1000 final instanceFields = []; 1016 final instanceOperators = [];
1017 final instanceGetters = new Map<String,MemberMirror>();
1018 final instanceSetters = new Map<String,MemberMirror>();
1001 1019
1002 host.declaredMembers.forEach((_, MemberMirror member) { 1020 host.declaredMembers.forEach((_, MemberMirror member) {
1003 if (member.isPrivate) return; 1021 if (member.isPrivate) return;
1004 if (host is LibraryMirror || member.isStatic) { 1022 if (host is LibraryMirror || member.isStatic) {
1005 if (member.isMethod) { 1023 if (member is MethodMirror) {
1006 staticMethods.add(member); 1024 if (member.isGetter) {
Bob Nystrom 2012/10/11 17:04:21 What happened to the indentation here?
Johnni Winther 2012/10/12 11:15:53 Done.
1007 } else if (member.isField) { 1025 staticGetters[member.displayName] = member;
1008 staticFields.add(member); 1026 } else if (member.isSetter) {
1027 staticSetters[member.displayName] = member;
1028 } else {
1029 staticMethods.add(member);
1030 }
1031 } else if (member is FieldMirror) {
1032 staticGetters[member.displayName] = member;
1009 } 1033 }
1010 } 1034 }
1011 }); 1035 });
1012 1036
1013 if (host is InterfaceMirror) { 1037 if (host is InterfaceMirror) {
1014 var iterable = new HierarchyIterable(host, includeType: true); 1038 var iterable = new HierarchyIterable(host, includeType: true);
1015 for (InterfaceMirror type in iterable) { 1039 for (InterfaceMirror type in iterable) {
1016 type.declaredMembers.forEach((_, MemberMirror member) { 1040 type.declaredMembers.forEach((_, MemberMirror member) {
1017 if (member.isPrivate) return; 1041 if (member.isPrivate) return;
1018 if (!member.isStatic) { 1042 if (!member.isStatic) {
1019 memberMap.putIfAbsent(member.simpleName, () => member); 1043 if (member.isField) {
1044 // Fields override both getters and setters.
1045 memberMap.putIfAbsent(member.simpleName, () => member);
1046 memberMap.putIfAbsent('${member.simpleName}=', () => member);
1047 } else {
1048 memberMap.putIfAbsent(member.simpleName, () => member);
1049 }
1020 } 1050 }
1021 }); 1051 });
1022 } 1052 }
1023 } 1053 }
1024 1054
1025 memberMap.forEach((_, MemberMirror member) { 1055 memberMap.forEach((_, MemberMirror member) {
1026 if (member.isMethod) { 1056 if (member is MethodMirror) {
1027 instanceMethods.add(member); 1057 if (member.isGetter) {
1028 } else if (member.isField) { 1058 instanceGetters[member.displayName] = member;
1029 instanceFields.add(member); 1059 } else if (member.isSetter) {
1060 instanceSetters[member.displayName] = member;
1061 } else if (member.isOperator) {
1062 instanceOperators.add(member);
1063 } else {
1064 instanceMethods.add(member);
1065 }
1066 } else if (member is FieldMirror) {
1067 instanceGetters[member.displayName] = member;
1030 } 1068 }
1031 }); 1069 });
1032 1070
1033 if (staticFields.length > 0) { 1071 instanceOperators.sort((MethodMirror a, MethodMirror b) {
1034 final title = host is LibraryMirror ? 'Variables' : 'Static Fields'; 1072 return operatorOrder.indexOf(a.simpleName).compareTo(
1073 operatorOrder.indexOf(b.simpleName));
Lasse Reichstein Nielsen 2012/10/12 09:47:26 How inefficient. How about making the operatorOrde
Johnni Winther 2012/10/12 11:15:53 Done.
1074 });
1075
1076 docProperties(host,
1077 host is LibraryMirror ? 'Properties' : 'Static Properties',
1078 staticGetters, staticSetters);
1079 docMethods(host,
1080 host is LibraryMirror ? 'Functions' : 'Static Methods',
1081 staticMethods);
1082
1083 docProperties(host, 'Properties', instanceGetters, instanceSetters);
1084 docMethods(host, 'Operators', instanceOperators);
1085 docMethods(host, 'Methods', orderByName(instanceMethods));
1086 }
1087
1088 /**
1089 * Documents fields, getters, and setters as properties.
1090 */
1091 void docProperties(ObjectMirror host, String title,
1092 Map<String,MemberMirror> getters,
1093 Map<String,MemberMirror> setters) {
1094 if (getters.length + setters.length > 0) {
Bob Nystrom 2012/10/11 17:04:21 Do an early return here and lose a level of indent
Lasse Reichstein Nielsen 2012/10/12 09:47:26 Agree violently.
Johnni Winther 2012/10/12 11:15:53 Done.
1095 var nameSet = new Set<String>.from(getters.getKeys());
1096 nameSet.addAll(setters.getKeys());
1097 var nameList = new List<String>.from(nameSet);
1098 nameList.sort((String a, String b) {
1099 return a.toLowerCase().compareTo(b.toLowerCase());
Lasse Reichstein Nielsen 2012/10/12 09:47:26 Seems wasteful to do toLowerCase twice on every ca
1100 });
1101
1035 writeln('<div>'); 1102 writeln('<div>');
1036 writeln('<h3>$title</h3>'); 1103 writeln('<h3>$title</h3>');
1037 for (final field in orderByName(staticFields)) { 1104 for (String name in nameList) {
1038 docField(host, field); 1105 MemberMirror getter = getters[name];
1106 MemberMirror setter = setters[name];
Bob Nystrom 2012/10/11 17:04:21 You can just use var here and elsewhere. Type anno
Lasse Reichstein Nielsen 2012/10/12 09:47:26 I disagree. I can't read the type of 'getter' from
Bob Nystrom 2012/10/12 16:09:02 That's the tool's job! :) Programmers shouldn't ha
Lasse Reichstein Nielsen 2012/10/15 09:16:20 I'm very much in the "must be readable when printe
1107 if (setter == null) {
1108 if (getter is FieldMirror) {
1109 // We have a field.
1110 docField(host, getter);
1111 } else {
1112 // We only have a getter.
1113 assert(getter is MethodMirror);
1114 docProperty(host, getter, null);
1115 }
1116 } else if (getter == null) {
1117 // We only have a setter => Document as a method.
1118 assert(setter is MethodMirror);
1119 docMethod(host, setter);
1120 } else {
1121 DocComment getterComment = getMemberComment(getter);
1122 DocComment setterComment = getMemberComment(setter);
1123 if (getter.surroundingDeclaration !== setter.surroundingDeclaration ||
1124 getterComment != null && setterComment != null) {
1125 // Both have comments or are not declared in the same class
1126 // => Documents separately.
1127 if (getter is FieldMirror) {
1128 // Document field as a getter (setter is inherited).
1129 docField(host, getter, asGetter: true);
1130 } else {
1131 docMethod(host, getter);
1132 }
1133 if (setter is FieldMirror) {
1134 // Document field as a setter (getter is inherited).
1135 docField(host, setter, asSetter: true);
1136 } else {
1137 docMethod(host, setter);
1138 }
1139 } else {
1140 // Document as field.
1141 docProperty(host, getter, setter);
1142 }
1143 }
1039 } 1144 }
1040 writeln('</div>'); 1145 writeln('</div>');
1041 } 1146 }
1147 }
1042 1148
1043 if (staticMethods.length > 0) { 1149 void docMethods(ObjectMirror host, String title, List<MethodMirror> methods) {
1044 final title = host is LibraryMirror ? 'Functions' : 'Static Methods'; 1150 if (methods.length > 0) {
1045 writeln('<div>'); 1151 writeln('<div>');
1046 writeln('<h3>$title</h3>'); 1152 writeln('<h3>$title</h3>');
1047 for (final method in orderByName(staticMethods)) { 1153 for (final method in methods) {
1048 docMethod(host, method); 1154 docMethod(host, method);
1049 } 1155 }
1050 writeln('</div>'); 1156 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 } 1157 }
1070 } 1158 }
1071 1159
1072 /** 1160 /**
1073 * Documents the [method] in type [type]. Handles all kinds of methods 1161 * Documents the [member] in declared in [host]. Handles all kinds of methods
Bob Nystrom 2012/10/11 17:04:21 "in declared" -> "declared" "methods" -> "members"
Johnni Winther 2012/10/12 11:15:53 Done.
1074 * including getters, setters, and constructors. 1162 * including getters, setters, and constructors. If [member] is a
1163 * [FieldMirror] it is documented as a getter or setter depending upon the
1164 * value of [asGetter].
1075 */ 1165 */
1076 void docMethod(ObjectMirror host, MethodMirror method) { 1166 void docMethod(ObjectMirror host, MemberMirror member,
1167 {bool asGetter: false}) {
1077 _totalMembers++; 1168 _totalMembers++;
1078 _currentMember = method; 1169 _currentMember = member;
1079 1170
1080 bool showCode = includeSource && !method.isAbstract; 1171 bool isAbstract = false;
1081 bool inherited = host != method.surroundingDeclaration; 1172 String name = member.displayName;
1173 if (member is FieldMirror) {
1174 if (asGetter) {
1175 // Getter.
1176 name = 'get $name';
1177 } else {
1178 // Setter.
1179 name = 'set $name';
1180 }
1181 } else {
1182 assert(member is MethodMirror);
1183 isAbstract = member.isAbstract;
1184 if (member.isGetter) {
1185 // Getter.
1186 name = 'get $name';
1187 } else if (member.isSetter) {
1188 // Setter.
1189 name = 'set $name';
1190 }
1191 }
1192
1193 bool showCode = includeSource && !isAbstract;
1194 bool inherited = host != member.surroundingDeclaration;
1082 1195
1083 writeln('<div class="method${inherited ? ' inherited': ''}">' 1196 writeln('<div class="method${inherited ? ' inherited': ''}">'
1084 '<h4 id="${memberAnchor(method)}">'); 1197 '<h4 id="${memberAnchor(member)}">');
1085 1198
1086 if (showCode) { 1199 if (showCode) {
1087 writeln('<button class="show-code">Code</button>'); 1200 writeln('<button class="show-code">Code</button>');
1088 } 1201 }
1089 1202
1090 if (method.isConstructor) { 1203 if (member is MethodMirror) {
1091 if (method.isFactory) { 1204 if (member.isConstructor) {
1092 write('factory '); 1205 if (member.isFactory) {
1206 write('factory ');
1207 } else {
1208 write(member.isConst ? 'const ' : 'new ');
1209 }
1210 } else if (member.isAbstract) {
1211 write('abstract ');
1212 }
1213
1214 if (!member.isConstructor) {
1215 annotateType(host, member.returnType);
1216 }
1217 } else {
1218 assert(member is FieldMirror);
1219 if (asGetter) {
1220 annotateType(host, member.type);
1093 } else { 1221 } else {
1094 write(method.isConst ? 'const ' : 'new '); 1222 write('void ');
1095 } 1223 }
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 } 1224 }
1113 1225
1114 write('<strong>$name</strong>'); 1226 write('<strong>$name</strong>');
1115 1227
1116 docParamList(host, method.parameters); 1228 if (member is MethodMirror) {
1229 if (!member.isGetter) {
1230 docParamList(host, member.parameters);
1231 }
1232 } else {
1233 assert(member is FieldMirror);
1234 if (!asGetter) {
1235 write('(');
1236 annotateType(host, member.type);
1237 write(' _)');
Bob Nystrom 2012/10/11 17:04:21 "_" -> "value"?
Lasse Reichstein Nielsen 2012/10/12 09:47:26 Let's do that. C# programmers will be happy.
Johnni Winther 2012/10/12 11:15:53 Done.
Bob Nystrom 2012/10/12 16:09:02 Yay!
1238 }
1239 }
1117 1240
1118 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; 1241 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.';
1119 write(''' <a class="anchor-link" href="#${memberAnchor(method)}" 1242 write(''' <a class="anchor-link" href="#${memberAnchor(member)}"
1120 title="Permalink to $prefix$name">#</a>'''); 1243 title="Permalink to $prefix$name">#</a>''');
1121 writeln('</h4>'); 1244 writeln('</h4>');
1122 1245
1123 if (inherited) { 1246 if (inherited) {
1124 write('<div class="inherited-from">inherited from '); 1247 write('<div class="inherited-from">inherited from ');
1125 annotateType(host, method.surroundingDeclaration); 1248 annotateType(host, member.surroundingDeclaration);
1126 write('</div>'); 1249 write('</div>');
1127 } 1250 }
1128 1251
1129 docCode(host, method.location, getMemberComment(method), showCode: showCode) ; 1252 writeln('<div class="doc">');
1253 docComment(host, getMemberComment(member));
1254 if (showCode) {
1255 docCode(host, member.location);
1256 }
1257 writeln('</div>');
1130 1258
1131 writeln('</div>'); 1259 writeln('</div>');
1132 } 1260 }
1133 1261
1134 /** Documents the field [field] of type [type]. */ 1262 void docField(ObjectMirror host, FieldMirror field,
1135 void docField(ObjectMirror host, FieldMirror field) { 1263 {bool asGetter: false, bool asSetter: false}) {
1264 if (asGetter) {
1265 docMethod(host, field, asGetter: true);
1266 } else if (asSetter) {
1267 docMethod(host, field, asGetter: false);
1268 } else {
1269 docProperty(host, field, null);
1270 }
1271 }
1272
1273 /**
1274 * Documents the property defined by [property] of [type].
1275 *
1276 * If [comment] is not set, the comment on [property] is used for
1277 * documentation. [additionalCodeLocation] is set to generate an additional
1278 * code fragment is case of properties defined in terms of getters and
1279 * setters.
Bob Nystrom 2012/10/11 17:04:21 This comment is out of sync with the method.
Johnni Winther 2012/10/12 11:15:53 Done.
1280 */
1281 void docProperty(ObjectMirror host,
1282 MemberMirror getter, MemberMirror setter) {
1283 assert(getter != null);
Bob Nystrom 2012/10/11 17:04:21 We generally assume all parameters are non-null an
Johnni Winther 2012/10/12 11:15:53 [setter] might be null, but [getter] may not.
1136 _totalMembers++; 1284 _totalMembers++;
1137 _currentMember = field; 1285 _currentMember = getter;
1138 1286
1139 bool inherited = host != field.surroundingDeclaration; 1287 bool inherited = host != getter.surroundingDeclaration;
1140 1288
1141 writeln('<div class="field${inherited ? ' inherited' : ''}">' 1289 writeln('<div class="field${inherited ? ' inherited' : ''}">'
1142 '<h4 id="${memberAnchor(field)}">'); 1290 '<h4 id="${memberAnchor(getter)}">');
1143 1291
1144 if (includeSource) { 1292 if (includeSource) {
1145 writeln('<button class="show-code">Code</button>'); 1293 writeln('<button class="show-code">Code</button>');
1146 } 1294 }
1147 1295
1148 if (field.isFinal) { 1296 bool isConst = false;
1297 bool isFinal;
1298 TypeMirror type;
1299 if (getter is FieldMirror) {
1300 isConst = getter.isConst;
1301 isFinal = getter.isFinal;
1302 type = getter.type;
1303 } else {
1304 assert(getter is MethodMirror);
1305 isFinal = setter == null;
1306 type = getter.returnType;
1307 }
1308
1309 if (isConst) {
1310 write('const ');
1311 } else if (isFinal) {
1149 write('final '); 1312 write('final ');
1150 } else if (field.type.isDynamic) { 1313 } else if (type.isDynamic) {
1151 write('var '); 1314 write('var ');
1152 } 1315 }
1153 1316
1154 annotateType(host, field.type); 1317 annotateType(host, type);
1155 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.'; 1318 var prefix = host is LibraryMirror ? '' : '${typeName(host)}.';
1156 write( 1319 write(
1157 ''' 1320 '''
1158 <strong>${field.simpleName}</strong> <a class="anchor-link" 1321 <strong>${getter.simpleName}</strong> <a class="anchor-link"
1159 href="#${memberAnchor(field)}" 1322 href="#${memberAnchor(getter)}"
1160 title="Permalink to $prefix${field.simpleName}">#</a> 1323 title="Permalink to $prefix${getter.simpleName}">#</a>
1161 </h4> 1324 </h4>
1162 '''); 1325 ''');
1163 1326
1164 if (inherited) { 1327 if (inherited) {
1165 write('<div class="inherited-from">inherited from '); 1328 write('<div class="inherited-from">inherited from ');
1166 annotateType(host, field.surroundingDeclaration); 1329 annotateType(host, getter.surroundingDeclaration);
1167 write('</div>'); 1330 write('</div>');
1168 } 1331 }
1169 1332
1170 docCode(host, field.location, getMemberComment(field), showCode: true); 1333 DocComment comment = getMemberComment(getter);
1334 if (comment == null && setter != null) {
1335 comment = getMemberComment(setter);
1336 }
1337 writeln('<div class="doc">');
1338 docComment(host, comment);
1339 docCode(host, getter.location);
1340 if (setter != null) {
1341 docCode(host, setter.location);
1342 }
1343 writeln('</div>');
1171 1344
1172 writeln('</div>'); 1345 writeln('</div>');
1173 } 1346 }
1174 1347
1175 void docParamList(ObjectMirror enclosingType, 1348 void docParamList(ObjectMirror enclosingType,
1176 List<ParameterMirror> parameters) { 1349 List<ParameterMirror> parameters) {
1177 write('('); 1350 write('(');
1178 bool first = true; 1351 bool first = true;
1179 bool inOptionals = false; 1352 bool inOptionals = false;
1180 for (final parameter in parameters) { 1353 for (final parameter in parameters) {
(...skipping 12 matching lines...) Expand all
1193 write(parameter.defaultValue); 1366 write(parameter.defaultValue);
1194 } 1367 }
1195 1368
1196 first = false; 1369 first = false;
1197 } 1370 }
1198 1371
1199 if (inOptionals) write(']'); 1372 if (inOptionals) write(']');
1200 write(')'); 1373 write(')');
1201 } 1374 }
1202 1375
1203 /** 1376 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) { 1377 if (comment != null) {
1211 if (comment.inheritedFrom !== null) { 1378 if (comment.inheritedFrom !== null) {
1212 writeln('<div class="inherited">'); 1379 writeln('<div class="inherited">');
1213 writeln(comment.html); 1380 writeln(comment.html);
1214 write('<div class="docs-inherited-from">docs inherited from '); 1381 write('<div class="docs-inherited-from">docs inherited from ');
1215 annotateType(host, comment.inheritedFrom); 1382 annotateType(host, comment.inheritedFrom);
1216 write('</div>'); 1383 write('</div>');
1217 writeln('</div>'); 1384 writeln('</div>');
1218 } else { 1385 } else {
1219 writeln(comment.html); 1386 writeln(comment.html);
1220 } 1387 }
1221 } 1388 }
1389 }
1222 1390
1223 if (includeSource && showCode) { 1391 /**
1392 * Documents the code contained within [span] with [comment]. If [showCode]
1393 * is `true` (and [includeSource] is set), also includes the source code.
1394 */
Bob Nystrom 2012/10/11 17:04:21 This comment is out of sync with the method.
Johnni Winther 2012/10/12 11:15:53 Done.
1395 void docCode(ObjectMirror host, Location location) {
1396 if (includeSource) {
1224 writeln('<pre class="source">'); 1397 writeln('<pre class="source">');
1225 writeln(md.escapeHtml(unindentCode(location))); 1398 writeln(md.escapeHtml(unindentCode(location)));
1226 writeln('</pre>'); 1399 writeln('</pre>');
1227 } 1400 }
1228
1229 writeln('</div>');
1230 } 1401 }
1231 1402
1232 DocComment createDocComment(String text, [InterfaceMirror inheritedFrom]) => 1403 DocComment createDocComment(String text, [InterfaceMirror inheritedFrom]) =>
1233 new DocComment(text, inheritedFrom); 1404 new DocComment(text, inheritedFrom);
1234 1405
1235 1406
1236 /** Get the doc comment associated with the given library. */ 1407 /** Get the doc comment associated with the given library. */
1237 DocComment getLibraryComment(LibraryMirror library) { 1408 DocComment getLibraryComment(LibraryMirror library) {
1238 // Look for a comment for the entire library. 1409 // Look for a comment for the entire library.
1239 final comment = _comments.findLibrary(library.location.source); 1410 final comment = _comments.findLibrary(library.location.source);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 final InterfaceMirror inheritedFrom; 1810 final InterfaceMirror inheritedFrom;
1640 1811
1641 DocComment(this.text, [this.inheritedFrom = null]) { 1812 DocComment(this.text, [this.inheritedFrom = null]) {
1642 assert(text != null && !text.trim().isEmpty()); 1813 assert(text != null && !text.trim().isEmpty());
1643 } 1814 }
1644 1815
1645 String get html => md.markdownToHtml(text); 1816 String get html => md.markdownToHtml(text);
1646 1817
1647 String toString() => text; 1818 String toString() => text;
1648 } 1819 }
OLDNEW
« no previous file with comments | « no previous file | pkg/dartdoc/lib/mirrors.dart » ('j') | pkg/dartdoc/lib/src/client/client-shared.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698