| 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.declaredMembers); |
| 603 if (!typeMembers.isEmpty) { | 603 if (!typeMembers.isEmpty) { |
| 604 typeInfo[MEMBERS] = typeMembers; | 604 typeInfo[MEMBERS] = typeMembers; |
| 605 } | 605 } |
| 606 | 606 |
| 607 if (!type.declaration.typeVariables.isEmpty) { | 607 if (!type.originalDeclaration.typeVariables.isEmpty) { |
| 608 final typeVariables = []; | 608 final typeVariables = []; |
| 609 for (final typeVariable in type.declaration.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, ', '); |
| 613 } | 613 } |
| 614 types.add(typeInfo); | 614 types.add(typeInfo); |
| 615 } | 615 } |
| 616 if (!types.isEmpty) { | 616 if (!types.isEmpty) { |
| 617 libraryInfo[TYPES] = types; | 617 libraryInfo[TYPES] = types; |
| 618 } | 618 } |
| 619 | 619 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 typeSpan(supertypes[i]); | 933 typeSpan(supertypes[i]); |
| 934 write(' > '); | 934 write(' > '); |
| 935 } | 935 } |
| 936 | 936 |
| 937 // Write this class. | 937 // Write this class. |
| 938 typeSpan(type); | 938 typeSpan(type); |
| 939 writeln('</p>'); | 939 writeln('</p>'); |
| 940 } | 940 } |
| 941 | 941 |
| 942 listTypes(subtypes, 'Subclasses'); | 942 listTypes(subtypes, 'Subclasses'); |
| 943 listTypes(type.interfaces, 'Implements'); | 943 listTypes(type.superinterfaces, 'Implements'); |
| 944 } else { | 944 } else { |
| 945 // Show the default class. | 945 // Show the default class. |
| 946 if (type.defaultType != null) { | 946 if (type.defaultFactory != null) { |
| 947 listTypes([type.defaultType], 'Default class'); | 947 listTypes([type.defaultFactory], 'Default class'); |
| 948 } | 948 } |
| 949 | 949 |
| 950 // List extended interfaces. | 950 // List extended interfaces. |
| 951 listTypes(type.interfaces, 'Extends'); | 951 listTypes(type.superinterfaces, 'Extends'); |
| 952 | 952 |
| 953 // List subinterfaces and implementing classes. | 953 // List subinterfaces and implementing classes. |
| 954 final subinterfaces = []; | 954 final subinterfaces = []; |
| 955 final implementing = []; | 955 final implementing = []; |
| 956 | 956 |
| 957 for (final subtype in subtypes) { | 957 for (final subtype in subtypes) { |
| 958 if (subtype.isClass) { | 958 if (subtype.isClass) { |
| 959 implementing.add(subtype); | 959 implementing.add(subtype); |
| 960 } else { | 960 } else { |
| 961 subinterfaces.add(subtype); | 961 subinterfaces.add(subtype); |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1611 | 1611 |
| 1612 // Link to the type. | 1612 // Link to the type. |
| 1613 if (shouldLinkToPublicApi(type.library)) { | 1613 if (shouldLinkToPublicApi(type.library)) { |
| 1614 write('<a href="$API_LOCATION${typeUrl(type)}">${type.simpleName}</a>'); | 1614 write('<a href="$API_LOCATION${typeUrl(type)}">${type.simpleName}</a>'); |
| 1615 } else if (shouldIncludeLibrary(type.library)) { | 1615 } else if (shouldIncludeLibrary(type.library)) { |
| 1616 write(a(typeUrl(type), type.simpleName)); | 1616 write(a(typeUrl(type), type.simpleName)); |
| 1617 } else { | 1617 } else { |
| 1618 write(type.simpleName); | 1618 write(type.simpleName); |
| 1619 } | 1619 } |
| 1620 | 1620 |
| 1621 if (type.isDeclaration) { | 1621 if (type.isOriginalDeclaration) { |
| 1622 // Avoid calling [:typeArguments():] on a declaration. | 1622 // Avoid calling [:typeArguments():] on a declaration. |
| 1623 return; | 1623 return; |
| 1624 } | 1624 } |
| 1625 | 1625 |
| 1626 // See if it's an instantiation of a generic type. | 1626 // See if it's an instantiation of a generic type. |
| 1627 final typeArgs = type.typeArguments; | 1627 final typeArgs = type.typeArguments; |
| 1628 if (typeArgs.length > 0) { | 1628 if (typeArgs.length > 0) { |
| 1629 write('<'); | 1629 write('<'); |
| 1630 bool first = true; | 1630 bool first = true; |
| 1631 for (final arg in typeArgs) { | 1631 for (final arg in typeArgs) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1648 typeName(TypeMirror type, {bool showBounds: false}) { | 1648 typeName(TypeMirror type, {bool showBounds: false}) { |
| 1649 if (type.isVoid) { | 1649 if (type.isVoid) { |
| 1650 return 'void'; | 1650 return 'void'; |
| 1651 } | 1651 } |
| 1652 if (type is TypeVariableMirror) { | 1652 if (type is TypeVariableMirror) { |
| 1653 return type.simpleName; | 1653 return type.simpleName; |
| 1654 } | 1654 } |
| 1655 assert(type is ClassMirror); | 1655 assert(type is ClassMirror); |
| 1656 | 1656 |
| 1657 // See if it's a generic type. | 1657 // See if it's a generic type. |
| 1658 if (type.isDeclaration) { | 1658 if (type.isOriginalDeclaration) { |
| 1659 final typeParams = []; | 1659 final typeParams = []; |
| 1660 for (final typeParam in type.declaration.typeVariables) { | 1660 for (final typeParam in type.originalDeclaration.typeVariables) { |
| 1661 if (showBounds && | 1661 if (showBounds && |
| 1662 (typeParam.bound != null) && | 1662 (typeParam.bound != null) && |
| 1663 !typeParam.bound.isObject) { | 1663 !typeParam.bound.isObject) { |
| 1664 final bound = typeName(typeParam.bound, showBounds: true); | 1664 final bound = typeName(typeParam.bound, showBounds: true); |
| 1665 typeParams.add('${typeParam.simpleName} extends $bound'); | 1665 typeParams.add('${typeParam.simpleName} extends $bound'); |
| 1666 } else { | 1666 } else { |
| 1667 typeParams.add(typeParam.simpleName); | 1667 typeParams.add(typeParam.simpleName); |
| 1668 } | 1668 } |
| 1669 } | 1669 } |
| 1670 if (typeParams.isEmpty) { | 1670 if (typeParams.isEmpty) { |
| 1671 return type.simpleName; | 1671 return type.simpleName; |
| 1672 } | 1672 } |
| 1673 final params = Strings.join(typeParams, ', '); | 1673 final params = Strings.join(typeParams, ', '); |
| 1674 return '${type.simpleName}<$params>'; | 1674 return '${type.simpleName}<$params>'; |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 // See if it's an instantiation of a generic type. | 1677 // See if it's an instantiation of a generic type. |
| 1678 final typeArgs = type.typeArguments; | 1678 final typeArgs = type.typeArguments; |
| 1679 if (typeArgs.length > 0) { | 1679 if (typeArgs.length > 0) { |
| 1680 final args = Strings.join(typeArgs.map((arg) => typeName(arg)), ', '); | 1680 final args = Strings.join(typeArgs.map((arg) => typeName(arg)), ', '); |
| 1681 return '${type.declaration.simpleName}<$args>'; | 1681 return '${type.originalDeclaration.simpleName}<$args>'; |
| 1682 } | 1682 } |
| 1683 | 1683 |
| 1684 // Regular type. | 1684 // Regular type. |
| 1685 return type.simpleName; | 1685 return type.simpleName; |
| 1686 } | 1686 } |
| 1687 | 1687 |
| 1688 /** | 1688 /** |
| 1689 * Remove leading indentation to line up with first line. | 1689 * Remove leading indentation to line up with first line. |
| 1690 */ | 1690 */ |
| 1691 unindentCode(SourceLocation span) { | 1691 unindentCode(SourceLocation span) { |
| (...skipping 165 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 |