| 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 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 final libraryList = []; | 573 final libraryList = []; |
| 574 for (final library in _sortedLibraries) { | 574 for (final library in _sortedLibraries) { |
| 575 docLibraryNavigationJson(library, libraryList); | 575 docLibraryNavigationJson(library, libraryList); |
| 576 } | 576 } |
| 577 return libraryList; | 577 return libraryList; |
| 578 } | 578 } |
| 579 | 579 |
| 580 void docLibraryNavigationJson(LibraryMirror library, List libraryList) { | 580 void docLibraryNavigationJson(LibraryMirror library, List libraryList) { |
| 581 var libraryInfo = {}; | 581 var libraryInfo = {}; |
| 582 libraryInfo[NAME] = displayName(library); | 582 libraryInfo[NAME] = displayName(library); |
| 583 final List members = docMembersJson(library.declaredMembers); | 583 final List members = docMembersJson(library.members); |
| 584 if (!members.isEmpty) { | 584 if (!members.isEmpty) { |
| 585 libraryInfo[MEMBERS] = members; | 585 libraryInfo[MEMBERS] = members; |
| 586 } | 586 } |
| 587 | 587 |
| 588 final types = []; | 588 final types = []; |
| 589 for (ClassMirror type in orderByName(library.classes.values)) { | 589 for (ClassMirror type in orderByName(library.classes.values)) { |
| 590 if (!showPrivate && type.isPrivate) continue; | 590 if (!showPrivate && type.isPrivate) continue; |
| 591 | 591 |
| 592 var typeInfo = {}; | 592 var typeInfo = {}; |
| 593 typeInfo[NAME] = type.displayName; | 593 typeInfo[NAME] = type.displayName; |
| 594 if (type.isClass) { | 594 if (type.isClass) { |
| 595 typeInfo[KIND] = CLASS; | 595 typeInfo[KIND] = CLASS; |
| 596 } else if (type.isInterface) { | 596 } else if (type.isInterface) { |
| 597 typeInfo[KIND] = INTERFACE; | 597 typeInfo[KIND] = INTERFACE; |
| 598 } else { | 598 } else { |
| 599 assert(type.isTypedef); | 599 assert(type.isTypedef); |
| 600 typeInfo[KIND] = TYPEDEF; | 600 typeInfo[KIND] = TYPEDEF; |
| 601 } | 601 } |
| 602 final List typeMembers = docMembersJson(type.declaredMembers); | 602 final List typeMembers = docMembersJson(type.members); |
| 603 if (!typeMembers.isEmpty) { | 603 if (!typeMembers.isEmpty) { |
| 604 typeInfo[MEMBERS] = typeMembers; | 604 typeInfo[MEMBERS] = typeMembers; |
| 605 } | 605 } |
| 606 | 606 |
| 607 if (!type.originalDeclaration.typeVariables.isEmpty) { | 607 if (!type.originalDeclaration.typeVariables.isEmpty) { |
| 608 final typeVariables = []; | 608 final typeVariables = []; |
| 609 for (final typeVariable in type.originalDeclaration.typeVariables) { | 609 for (final typeVariable in type.originalDeclaration.typeVariables) { |
| 610 typeVariables.add(typeVariable.displayName); | 610 typeVariables.add(typeVariable.displayName); |
| 611 } | 611 } |
| 612 typeInfo[ARGS] = Strings.join(typeVariables, ', '); | 612 typeInfo[ARGS] = Strings.join(typeVariables, ', '); |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 | 1005 |
| 1006 static final Map<String, int> operatorOrderMap = (){ | 1006 static final Map<String, int> operatorOrderMap = (){ |
| 1007 var map = new Map<String, int>(); | 1007 var map = new Map<String, int>(); |
| 1008 var index = 0; | 1008 var index = 0; |
| 1009 for (String operator in operatorOrder) { | 1009 for (String operator in operatorOrder) { |
| 1010 map[operator] = index++; | 1010 map[operator] = index++; |
| 1011 } | 1011 } |
| 1012 return map; | 1012 return map; |
| 1013 }(); | 1013 }(); |
| 1014 | 1014 |
| 1015 void docMembers(ObjectMirror host) { | 1015 void docMembers(ContainerMirror host) { |
| 1016 // Collect the different kinds of members. | 1016 // Collect the different kinds of members. |
| 1017 final staticMethods = []; | 1017 final staticMethods = []; |
| 1018 final staticGetters = new Map<String,MemberMirror>(); | 1018 final staticGetters = new Map<String,MemberMirror>(); |
| 1019 final staticSetters = new Map<String,MemberMirror>(); | 1019 final staticSetters = new Map<String,MemberMirror>(); |
| 1020 final memberMap = new Map<String,MemberMirror>(); | 1020 final memberMap = new Map<String,MemberMirror>(); |
| 1021 final instanceMethods = []; | 1021 final instanceMethods = []; |
| 1022 final instanceOperators = []; | 1022 final instanceOperators = []; |
| 1023 final instanceGetters = new Map<String,MemberMirror>(); | 1023 final instanceGetters = new Map<String,MemberMirror>(); |
| 1024 final instanceSetters = new Map<String,MemberMirror>(); | 1024 final instanceSetters = new Map<String,MemberMirror>(); |
| 1025 final constructors = []; | 1025 final constructors = []; |
| 1026 | 1026 |
| 1027 host.declaredMembers.forEach((_, MemberMirror member) { | 1027 host.members.forEach((_, MemberMirror member) { |
| 1028 if (!showPrivate && member.isPrivate) return; | 1028 if (!showPrivate && member.isPrivate) return; |
| 1029 if (host is LibraryMirror || member.isStatic) { | 1029 if (host is LibraryMirror || member.isStatic) { |
| 1030 if (member is MethodMirror) { | 1030 if (member is MethodMirror) { |
| 1031 if (member.isGetter) { | 1031 if (member.isGetter) { |
| 1032 staticGetters[member.displayName] = member; | 1032 staticGetters[member.displayName] = member; |
| 1033 } else if (member.isSetter) { | 1033 } else if (member.isSetter) { |
| 1034 staticSetters[member.displayName] = member; | 1034 staticSetters[member.displayName] = member; |
| 1035 } else { | 1035 } else { |
| 1036 staticMethods.add(member); | 1036 staticMethods.add(member); |
| 1037 } | 1037 } |
| 1038 } else if (member is VariableMirror) { | 1038 } else if (member is VariableMirror) { |
| 1039 staticGetters[member.displayName] = member; | 1039 staticGetters[member.displayName] = member; |
| 1040 } | 1040 } |
| 1041 } | 1041 } |
| 1042 }); | 1042 }); |
| 1043 | 1043 |
| 1044 if (host is ClassMirror) { | 1044 if (host is ClassMirror) { |
| 1045 var iterable = new HierarchyIterable(host, includeType: true); | 1045 var iterable = new HierarchyIterable(host, includeType: true); |
| 1046 for (ClassMirror type in iterable) { | 1046 for (ClassMirror type in iterable) { |
| 1047 if (!host.isObject && !inheritFromObject && type.isObject) continue; | 1047 if (!host.isObject && !inheritFromObject && type.isObject) continue; |
| 1048 | 1048 |
| 1049 type.declaredMembers.forEach((_, MemberMirror member) { | 1049 type.members.forEach((_, MemberMirror member) { |
| 1050 if (member.isStatic) return; | 1050 if (member.isStatic) return; |
| 1051 if (!showPrivate && member.isPrivate) return; | 1051 if (!showPrivate && member.isPrivate) return; |
| 1052 | 1052 |
| 1053 bool inherit = true; | 1053 bool inherit = true; |
| 1054 if (type !== host) { | 1054 if (type !== host) { |
| 1055 if (member.isPrivate) { | 1055 if (member.isPrivate) { |
| 1056 // Don't inherit private members. | 1056 // Don't inherit private members. |
| 1057 inherit = false; | 1057 inherit = false; |
| 1058 } | 1058 } |
| 1059 if (member.isConstructor) { | 1059 if (member.isConstructor) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 allInherited: allPropertiesInherited); | 1128 allInherited: allPropertiesInherited); |
| 1129 docMethods(host, 'Operators', instanceOperators, | 1129 docMethods(host, 'Operators', instanceOperators, |
| 1130 allInherited: allOperatorsInherited); | 1130 allInherited: allOperatorsInherited); |
| 1131 docMethods(host, 'Methods', orderByName(instanceMethods), | 1131 docMethods(host, 'Methods', orderByName(instanceMethods), |
| 1132 allInherited: allMethodsInherited); | 1132 allInherited: allMethodsInherited); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 /** | 1135 /** |
| 1136 * Documents fields, getters, and setters as properties. | 1136 * Documents fields, getters, and setters as properties. |
| 1137 */ | 1137 */ |
| 1138 void docProperties(ObjectMirror host, String title, | 1138 void docProperties(ContainerMirror host, String title, |
| 1139 Map<String,MemberMirror> getters, | 1139 Map<String,MemberMirror> getters, |
| 1140 Map<String,MemberMirror> setters, | 1140 Map<String,MemberMirror> setters, |
| 1141 {bool allInherited}) { | 1141 {bool allInherited}) { |
| 1142 if (getters.isEmpty && setters.isEmpty) return; | 1142 if (getters.isEmpty && setters.isEmpty) return; |
| 1143 | 1143 |
| 1144 var nameSet = new Set<String>.from(getters.keys); | 1144 var nameSet = new Set<String>.from(getters.keys); |
| 1145 nameSet.addAll(setters.keys); | 1145 nameSet.addAll(setters.keys); |
| 1146 var nameList = new List<String>.from(nameSet); | 1146 var nameList = new List<String>.from(nameSet); |
| 1147 nameList.sort((String a, String b) { | 1147 nameList.sort((String a, String b) { |
| 1148 return a.toLowerCase().compareTo(b.toLowerCase()); | 1148 return a.toLowerCase().compareTo(b.toLowerCase()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 } | 1187 } |
| 1188 } else { | 1188 } else { |
| 1189 // Document as field. | 1189 // Document as field. |
| 1190 docProperty(host, getter, setter); | 1190 docProperty(host, getter, setter); |
| 1191 } | 1191 } |
| 1192 } | 1192 } |
| 1193 } | 1193 } |
| 1194 writeln('</div>'); | 1194 writeln('</div>'); |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 void docMethods(ObjectMirror host, String title, List<MethodMirror> methods, | 1197 void docMethods(ContainerMirror host, String title, List<MethodMirror> methods
, |
| 1198 {bool allInherited}) { | 1198 {bool allInherited}) { |
| 1199 if (methods.length > 0) { | 1199 if (methods.length > 0) { |
| 1200 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); | 1200 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
| 1201 writeln('<h3>$title</h3>'); | 1201 writeln('<h3>$title</h3>'); |
| 1202 for (final method in methods) { | 1202 for (final method in methods) { |
| 1203 docMethod(host, method); | 1203 docMethod(host, method); |
| 1204 } | 1204 } |
| 1205 writeln('</div>'); | 1205 writeln('</div>'); |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 /** | 1209 /** |
| 1210 * Documents the [member] declared in [host]. Handles all kinds of members | 1210 * Documents the [member] declared in [host]. Handles all kinds of members |
| 1211 * including getters, setters, and constructors. If [member] is a | 1211 * including getters, setters, and constructors. If [member] is a |
| 1212 * [FieldMirror] it is documented as a getter or setter depending upon the | 1212 * [FieldMirror] it is documented as a getter or setter depending upon the |
| 1213 * value of [asGetter]. | 1213 * value of [asGetter]. |
| 1214 */ | 1214 */ |
| 1215 void docMethod(ObjectMirror host, MemberMirror member, | 1215 void docMethod(ContainerMirror host, MemberMirror member, |
| 1216 {bool asGetter: false}) { | 1216 {bool asGetter: false}) { |
| 1217 _totalMembers++; | 1217 _totalMembers++; |
| 1218 _currentMember = member; | 1218 _currentMember = member; |
| 1219 | 1219 |
| 1220 bool isAbstract = false; | 1220 bool isAbstract = false; |
| 1221 String name = member.displayName; | 1221 String name = member.displayName; |
| 1222 if (member is VariableMirror) { | 1222 if (member is VariableMirror) { |
| 1223 if (asGetter) { | 1223 if (asGetter) { |
| 1224 // Getter. | 1224 // Getter. |
| 1225 name = 'get $name'; | 1225 name = 'get $name'; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 writeln('<div class="doc">'); | 1301 writeln('<div class="doc">'); |
| 1302 docComment(host, getMemberComment(member)); | 1302 docComment(host, getMemberComment(member)); |
| 1303 if (showCode) { | 1303 if (showCode) { |
| 1304 docCode(member.location); | 1304 docCode(member.location); |
| 1305 } | 1305 } |
| 1306 writeln('</div>'); | 1306 writeln('</div>'); |
| 1307 | 1307 |
| 1308 writeln('</div>'); | 1308 writeln('</div>'); |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 void docField(ObjectMirror host, VariableMirror field, | 1311 void docField(ContainerMirror host, VariableMirror field, |
| 1312 {bool asGetter: false, bool asSetter: false}) { | 1312 {bool asGetter: false, bool asSetter: false}) { |
| 1313 if (asGetter) { | 1313 if (asGetter) { |
| 1314 docMethod(host, field, asGetter: true); | 1314 docMethod(host, field, asGetter: true); |
| 1315 } else if (asSetter) { | 1315 } else if (asSetter) { |
| 1316 docMethod(host, field, asGetter: false); | 1316 docMethod(host, field, asGetter: false); |
| 1317 } else { | 1317 } else { |
| 1318 docProperty(host, field, null); | 1318 docProperty(host, field, null); |
| 1319 } | 1319 } |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 /** | 1322 /** |
| 1323 * Documents the property defined by [getter] and [setter] of declared in | 1323 * Documents the property defined by [getter] and [setter] of declared in |
| 1324 * [host]. If [getter] is a [FieldMirror], [setter] must be [:null:]. | 1324 * [host]. If [getter] is a [FieldMirror], [setter] must be [:null:]. |
| 1325 * Otherwise, if [getter] is a [MethodMirror], the property is considered | 1325 * Otherwise, if [getter] is a [MethodMirror], the property is considered |
| 1326 * final if [setter] is [:null:]. | 1326 * final if [setter] is [:null:]. |
| 1327 */ | 1327 */ |
| 1328 void docProperty(ObjectMirror host, | 1328 void docProperty(ContainerMirror host, |
| 1329 MemberMirror getter, MemberMirror setter) { | 1329 MemberMirror getter, MemberMirror setter) { |
| 1330 assert(getter != null); | 1330 assert(getter != null); |
| 1331 _totalMembers++; | 1331 _totalMembers++; |
| 1332 _currentMember = getter; | 1332 _currentMember = getter; |
| 1333 | 1333 |
| 1334 bool inherited = host != getter.owner; | 1334 bool inherited = host != getter.owner; |
| 1335 | 1335 |
| 1336 writeln('<div class="field${inherited ? ' inherited' : ''}">' | 1336 writeln('<div class="field${inherited ? ' inherited' : ''}">' |
| 1337 '<h4 id="${memberAnchor(getter)}">'); | 1337 '<h4 id="${memberAnchor(getter)}">'); |
| 1338 | 1338 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 docComment(host, comment); | 1386 docComment(host, comment); |
| 1387 docCode(getter.location); | 1387 docCode(getter.location); |
| 1388 if (setter != null) { | 1388 if (setter != null) { |
| 1389 docCode(setter.location); | 1389 docCode(setter.location); |
| 1390 } | 1390 } |
| 1391 writeln('</div>'); | 1391 writeln('</div>'); |
| 1392 | 1392 |
| 1393 writeln('</div>'); | 1393 writeln('</div>'); |
| 1394 } | 1394 } |
| 1395 | 1395 |
| 1396 void docParamList(ObjectMirror enclosingType, | 1396 void docParamList(ContainerMirror enclosingType, |
| 1397 List<ParameterMirror> parameters) { | 1397 List<ParameterMirror> parameters) { |
| 1398 write('('); | 1398 write('('); |
| 1399 bool first = true; | 1399 bool first = true; |
| 1400 bool inOptionals = false; | 1400 bool inOptionals = false; |
| 1401 for (final parameter in parameters) { | 1401 for (final parameter in parameters) { |
| 1402 if (!first) write(', '); | 1402 if (!first) write(', '); |
| 1403 | 1403 |
| 1404 if (!inOptionals && parameter.isOptional) { | 1404 if (!inOptionals && parameter.isOptional) { |
| 1405 write('['); | 1405 write('['); |
| 1406 inOptionals = true; | 1406 inOptionals = true; |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 annotateType(enclosingType, parameter.type, parameter.simpleName); | 1409 annotateType(enclosingType, parameter.type, parameter.simpleName); |
| 1410 | 1410 |
| 1411 // Show the default value for named optional parameters. | 1411 // Show the default value for named optional parameters. |
| 1412 if (parameter.isOptional && parameter.hasDefaultValue) { | 1412 if (parameter.isOptional && parameter.hasDefaultValue) { |
| 1413 write(' = '); | 1413 write(' = '); |
| 1414 write(parameter.defaultValue); | 1414 write(parameter.defaultValue); |
| 1415 } | 1415 } |
| 1416 | 1416 |
| 1417 first = false; | 1417 first = false; |
| 1418 } | 1418 } |
| 1419 | 1419 |
| 1420 if (inOptionals) write(']'); | 1420 if (inOptionals) write(']'); |
| 1421 write(')'); | 1421 write(')'); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 void docComment(ObjectMirror host, DocComment comment) { | 1424 void docComment(ContainerMirror host, DocComment comment) { |
| 1425 if (comment != null) { | 1425 if (comment != null) { |
| 1426 if (comment.inheritedFrom !== null) { | 1426 if (comment.inheritedFrom !== null) { |
| 1427 writeln('<div class="inherited">'); | 1427 writeln('<div class="inherited">'); |
| 1428 writeln(comment.html); | 1428 writeln(comment.html); |
| 1429 write('<div class="docs-inherited-from">docs inherited from '); | 1429 write('<div class="docs-inherited-from">docs inherited from '); |
| 1430 annotateType(host, comment.inheritedFrom); | 1430 annotateType(host, comment.inheritedFrom); |
| 1431 write('</div>'); | 1431 write('</div>'); |
| 1432 writeln('</div>'); | 1432 writeln('</div>'); |
| 1433 } else { | 1433 } else { |
| 1434 writeln(comment.html); | 1434 writeln(comment.html); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 */ | 1475 */ |
| 1476 DocComment getMemberComment(MemberMirror member) { | 1476 DocComment getMemberComment(MemberMirror member) { |
| 1477 String comment = _comments.find(member.location); | 1477 String comment = _comments.find(member.location); |
| 1478 ClassMirror inheritedFrom = null; | 1478 ClassMirror inheritedFrom = null; |
| 1479 if (comment == null) { | 1479 if (comment == null) { |
| 1480 if (member.owner is ClassMirror) { | 1480 if (member.owner is ClassMirror) { |
| 1481 var iterable = | 1481 var iterable = |
| 1482 new HierarchyIterable(member.owner, | 1482 new HierarchyIterable(member.owner, |
| 1483 includeType: false); | 1483 includeType: false); |
| 1484 for (ClassMirror type in iterable) { | 1484 for (ClassMirror type in iterable) { |
| 1485 var inheritedMember = type.declaredMembers[member.simpleName]; | 1485 var inheritedMember = type.members[member.simpleName]; |
| 1486 if (inheritedMember is MemberMirror) { | 1486 if (inheritedMember is MemberMirror) { |
| 1487 comment = _comments.find(inheritedMember.location); | 1487 comment = _comments.find(inheritedMember.location); |
| 1488 if (comment != null) { | 1488 if (comment != null) { |
| 1489 inheritedFrom = type; | 1489 inheritedFrom = type; |
| 1490 break; | 1490 break; |
| 1491 } | 1491 } |
| 1492 } | 1492 } |
| 1493 } | 1493 } |
| 1494 } | 1494 } |
| 1495 } | 1495 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1518 // a scheme to be relative. | 1518 // a scheme to be relative. |
| 1519 return const RegExp(r'^\w+:').hasMatch(url); | 1519 return const RegExp(r'^\w+:').hasMatch(url); |
| 1520 } | 1520 } |
| 1521 | 1521 |
| 1522 /** Gets the URL to the documentation for [library]. */ | 1522 /** Gets the URL to the documentation for [library]. */ |
| 1523 String libraryUrl(LibraryMirror library) { | 1523 String libraryUrl(LibraryMirror library) { |
| 1524 return '${sanitize(displayName(library))}.html'; | 1524 return '${sanitize(displayName(library))}.html'; |
| 1525 } | 1525 } |
| 1526 | 1526 |
| 1527 /** Gets the URL for the documentation for [type]. */ | 1527 /** Gets the URL for the documentation for [type]. */ |
| 1528 String typeUrl(ObjectMirror type) { | 1528 String typeUrl(ContainerMirror type) { |
| 1529 if (type is LibraryMirror) { | 1529 if (type is LibraryMirror) { |
| 1530 return '${sanitize(type.simpleName)}.html'; | 1530 return '${sanitize(type.simpleName)}.html'; |
| 1531 } | 1531 } |
| 1532 assert (type is TypeMirror); | 1532 assert (type is TypeMirror); |
| 1533 // Always get the generic type to strip off any type parameters or | 1533 // Always get the generic type to strip off any type parameters or |
| 1534 // arguments. If the type isn't generic, genericType returns `this`, so it | 1534 // arguments. If the type isn't generic, genericType returns `this`, so it |
| 1535 // works for non-generic types too. | 1535 // works for non-generic types too. |
| 1536 return '${sanitize(displayName(type.library))}/' | 1536 return '${sanitize(displayName(type.library))}/' |
| 1537 '${type.originalDeclaration.simpleName}.html'; | 1537 '${type.originalDeclaration.simpleName}.html'; |
| 1538 } | 1538 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1555 String a(String href, String contents, [String css]) { | 1555 String a(String href, String contents, [String css]) { |
| 1556 // Mark outgoing external links, mainly so we can style them. | 1556 // Mark outgoing external links, mainly so we can style them. |
| 1557 final rel = isAbsolute(href) ? ' ref="external"' : ''; | 1557 final rel = isAbsolute(href) ? ' ref="external"' : ''; |
| 1558 final cssClass = css == null ? '' : ' class="$css"'; | 1558 final cssClass = css == null ? '' : ' class="$css"'; |
| 1559 return '<a href="${relativePath(href)}"$cssClass$rel>$contents</a>'; | 1559 return '<a href="${relativePath(href)}"$cssClass$rel>$contents</a>'; |
| 1560 } | 1560 } |
| 1561 | 1561 |
| 1562 /** | 1562 /** |
| 1563 * Writes a type annotation for the given type and (optional) parameter name. | 1563 * Writes a type annotation for the given type and (optional) parameter name. |
| 1564 */ | 1564 */ |
| 1565 annotateType(ObjectMirror enclosingType, | 1565 annotateType(ContainerMirror enclosingType, |
| 1566 TypeMirror type, | 1566 TypeMirror type, |
| 1567 [String paramName = null]) { | 1567 [String paramName = null]) { |
| 1568 // Don't bother explicitly displaying Dynamic. | 1568 // Don't bother explicitly displaying Dynamic. |
| 1569 if (type.isDynamic) { | 1569 if (type.isDynamic) { |
| 1570 if (paramName !== null) write(paramName); | 1570 if (paramName !== null) write(paramName); |
| 1571 return; | 1571 return; |
| 1572 } | 1572 } |
| 1573 | 1573 |
| 1574 // For parameters, handle non-typedefed function types. | 1574 // For parameters, handle non-typedefed function types. |
| 1575 if (paramName !== null && type is FunctionTypeMirror) { | 1575 if (paramName !== null && type is FunctionTypeMirror) { |
| 1576 annotateType(enclosingType, type.returnType); | 1576 annotateType(enclosingType, type.returnType); |
| 1577 write(paramName); | 1577 write(paramName); |
| 1578 | 1578 |
| 1579 docParamList(enclosingType, type.parameters); | 1579 docParamList(enclosingType, type.parameters); |
| 1580 return; | 1580 return; |
| 1581 } | 1581 } |
| 1582 | 1582 |
| 1583 linkToType(enclosingType, type); | 1583 linkToType(enclosingType, type); |
| 1584 | 1584 |
| 1585 write(' '); | 1585 write(' '); |
| 1586 if (paramName !== null) write(paramName); | 1586 if (paramName !== null) write(paramName); |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 /** Writes a link to a human-friendly string representation for a type. */ | 1589 /** Writes a link to a human-friendly string representation for a type. */ |
| 1590 linkToType(ObjectMirror enclosingType, TypeMirror type) { | 1590 linkToType(ContainerMirror enclosingType, TypeMirror type) { |
| 1591 if (type.isVoid) { | 1591 if (type.isVoid) { |
| 1592 // Do not generate links for void. | 1592 // Do not generate links for void. |
| 1593 // TODO(johnniwinter): Generate span for specific style? | 1593 // TODO(johnniwinter): Generate span for specific style? |
| 1594 write('void'); | 1594 write('void'); |
| 1595 return; | 1595 return; |
| 1596 } | 1596 } |
| 1597 if (type.isDynamic) { | 1597 if (type.isDynamic) { |
| 1598 // Do not generate links for Dynamic. | 1598 // Do not generate links for Dynamic. |
| 1599 write('Dynamic'); | 1599 write('Dynamic'); |
| 1600 return; | 1600 return; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1710 return classifySource(code); | 1710 return classifySource(code); |
| 1711 } | 1711 } |
| 1712 | 1712 |
| 1713 /** | 1713 /** |
| 1714 * This will be called whenever a doc comment hits a `[name]` in square | 1714 * This will be called whenever a doc comment hits a `[name]` in square |
| 1715 * brackets. It will try to figure out what the name refers to and link or | 1715 * brackets. It will try to figure out what the name refers to and link or |
| 1716 * style it appropriately. | 1716 * style it appropriately. |
| 1717 */ | 1717 */ |
| 1718 md.Node resolveNameReference(String name, | 1718 md.Node resolveNameReference(String name, |
| 1719 {MemberMirror currentMember, | 1719 {MemberMirror currentMember, |
| 1720 ObjectMirror currentType, | 1720 ContainerMirror currentType, |
| 1721 LibraryMirror currentLibrary}) { | 1721 LibraryMirror currentLibrary}) { |
| 1722 makeLink(String href) { | 1722 makeLink(String href) { |
| 1723 final anchor = new md.Element.text('a', name); | 1723 final anchor = new md.Element.text('a', name); |
| 1724 anchor.attributes['href'] = relativePath(href); | 1724 anchor.attributes['href'] = relativePath(href); |
| 1725 anchor.attributes['class'] = 'crossref'; | 1725 anchor.attributes['class'] = 'crossref'; |
| 1726 return anchor; | 1726 return anchor; |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 // See if it's a parameter of the current method. | 1729 // See if it's a parameter of the current method. |
| 1730 if (currentMember is MethodMirror) { | 1730 if (currentMember is MethodMirror) { |
| 1731 for (final parameter in currentMember.parameters) { | 1731 for (final parameter in currentMember.parameters) { |
| 1732 if (parameter.simpleName == name) { | 1732 if (parameter.simpleName == name) { |
| 1733 final element = new md.Element.text('span', name); | 1733 final element = new md.Element.text('span', name); |
| 1734 element.attributes['class'] = 'param'; | 1734 element.attributes['class'] = 'param'; |
| 1735 return element; | 1735 return element; |
| 1736 } | 1736 } |
| 1737 } | 1737 } |
| 1738 } | 1738 } |
| 1739 | 1739 |
| 1740 // See if it's another member of the current type. | 1740 // See if it's another member of the current type. |
| 1741 if (currentType != null) { | 1741 if (currentType != null) { |
| 1742 final foundMember = currentType.declaredMembers[name]; | 1742 final foundMember = currentType.members[name]; |
| 1743 if (foundMember != null) { | 1743 if (foundMember != null) { |
| 1744 return makeLink(memberUrl(foundMember)); | 1744 return makeLink(memberUrl(foundMember)); |
| 1745 } | 1745 } |
| 1746 } | 1746 } |
| 1747 | 1747 |
| 1748 // See if it's another type or a member of another type in the current | 1748 // See if it's another type or a member of another type in the current |
| 1749 // library. | 1749 // library. |
| 1750 if (currentLibrary != null) { | 1750 if (currentLibrary != null) { |
| 1751 // See if it's a constructor | 1751 // See if it's a constructor |
| 1752 final constructorLink = (() { | 1752 final constructorLink = (() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1764 return makeLink(memberUrl(constructor)); | 1764 return makeLink(memberUrl(constructor)); |
| 1765 })(); | 1765 })(); |
| 1766 if (constructorLink != null) return constructorLink; | 1766 if (constructorLink != null) return constructorLink; |
| 1767 | 1767 |
| 1768 // See if it's a member of another type | 1768 // See if it's a member of another type |
| 1769 final foreignMemberLink = (() { | 1769 final foreignMemberLink = (() { |
| 1770 final match = new RegExp(r'([\w$]+)\.([\w$]+)').firstMatch(name); | 1770 final match = new RegExp(r'([\w$]+)\.([\w$]+)').firstMatch(name); |
| 1771 if (match == null) return; | 1771 if (match == null) return; |
| 1772 ClassMirror foundtype = currentLibrary.classes[match[1]]; | 1772 ClassMirror foundtype = currentLibrary.classes[match[1]]; |
| 1773 if (foundtype == null) return; | 1773 if (foundtype == null) return; |
| 1774 MemberMirror foundMember = foundtype.declaredMembers[match[2]]; | 1774 MemberMirror foundMember = foundtype.members[match[2]]; |
| 1775 if (foundMember == null) return; | 1775 if (foundMember == null) return; |
| 1776 return makeLink(memberUrl(foundMember)); | 1776 return makeLink(memberUrl(foundMember)); |
| 1777 })(); | 1777 })(); |
| 1778 if (foreignMemberLink != null) return foreignMemberLink; | 1778 if (foreignMemberLink != null) return foreignMemberLink; |
| 1779 | 1779 |
| 1780 ClassMirror foundType = currentLibrary.classes[name]; | 1780 ClassMirror foundType = currentLibrary.classes[name]; |
| 1781 if (foundType != null) { | 1781 if (foundType != null) { |
| 1782 return makeLink(typeUrl(foundType)); | 1782 return makeLink(typeUrl(foundType)); |
| 1783 } | 1783 } |
| 1784 | 1784 |
| 1785 // See if it's a top-level member in the current library. | 1785 // See if it's a top-level member in the current library. |
| 1786 MemberMirror foundMember = currentLibrary.declaredMembers[name]; | 1786 MemberMirror foundMember = currentLibrary.members[name]; |
| 1787 if (foundMember != null) { | 1787 if (foundMember != null) { |
| 1788 return makeLink(memberUrl(foundMember)); | 1788 return makeLink(memberUrl(foundMember)); |
| 1789 } | 1789 } |
| 1790 } | 1790 } |
| 1791 | 1791 |
| 1792 // TODO(rnystrom): Should also consider: | 1792 // TODO(rnystrom): Should also consider: |
| 1793 // * Names imported by libraries this library imports. | 1793 // * Names imported by libraries this library imports. |
| 1794 // * Type parameters of the enclosing type. | 1794 // * Type parameters of the enclosing type. |
| 1795 | 1795 |
| 1796 return new md.Element.text('code', name); | 1796 return new md.Element.text('code', name); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 final ClassMirror inheritedFrom; | 1857 final ClassMirror inheritedFrom; |
| 1858 | 1858 |
| 1859 DocComment(this.text, [this.inheritedFrom = null]) { | 1859 DocComment(this.text, [this.inheritedFrom = null]) { |
| 1860 assert(text != null && !text.trim().isEmpty); | 1860 assert(text != null && !text.trim().isEmpty); |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 String get html => md.markdownToHtml(text); | 1863 String get html => md.markdownToHtml(text); |
| 1864 | 1864 |
| 1865 String toString() => text; | 1865 String toString() => text; |
| 1866 } | 1866 } |
| OLD | NEW |