| 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 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 final List typeMembers = docMembersJson(type.members); | 684 final List typeMembers = docMembersJson(type.members); |
| 685 if (!typeMembers.isEmpty) { | 685 if (!typeMembers.isEmpty) { |
| 686 typeInfo[MEMBERS] = typeMembers; | 686 typeInfo[MEMBERS] = typeMembers; |
| 687 } | 687 } |
| 688 | 688 |
| 689 if (!type.originalDeclaration.typeVariables.isEmpty) { | 689 if (!type.originalDeclaration.typeVariables.isEmpty) { |
| 690 final typeVariables = []; | 690 final typeVariables = []; |
| 691 for (final typeVariable in type.originalDeclaration.typeVariables) { | 691 for (final typeVariable in type.originalDeclaration.typeVariables) { |
| 692 typeVariables.add(typeVariable.displayName); | 692 typeVariables.add(typeVariable.displayName); |
| 693 } | 693 } |
| 694 typeInfo[ARGS] = Strings.join(typeVariables, ', '); | 694 typeInfo[ARGS] = typeVariables.join(', '); |
| 695 } | 695 } |
| 696 types.add(typeInfo); | 696 types.add(typeInfo); |
| 697 } | 697 } |
| 698 if (!types.isEmpty) { | 698 if (!types.isEmpty) { |
| 699 libraryInfo[TYPES] = types; | 699 libraryInfo[TYPES] = types; |
| 700 } | 700 } |
| 701 | 701 |
| 702 libraryList.add(libraryInfo); | 702 libraryList.add(libraryInfo); |
| 703 } | 703 } |
| 704 | 704 |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1759 !typeParam.upperBound.isObject) { | 1759 !typeParam.upperBound.isObject) { |
| 1760 final bound = typeName(typeParam.upperBound, showBounds: true); | 1760 final bound = typeName(typeParam.upperBound, showBounds: true); |
| 1761 typeParams.add('${typeParam.simpleName} extends $bound'); | 1761 typeParams.add('${typeParam.simpleName} extends $bound'); |
| 1762 } else { | 1762 } else { |
| 1763 typeParams.add(typeParam.simpleName); | 1763 typeParams.add(typeParam.simpleName); |
| 1764 } | 1764 } |
| 1765 } | 1765 } |
| 1766 if (typeParams.isEmpty) { | 1766 if (typeParams.isEmpty) { |
| 1767 return type.simpleName; | 1767 return type.simpleName; |
| 1768 } | 1768 } |
| 1769 final params = Strings.join(typeParams, ', '); | 1769 final params = typeParams.join(', '); |
| 1770 return '${type.simpleName}<$params>'; | 1770 return '${type.simpleName}<$params>'; |
| 1771 } | 1771 } |
| 1772 | 1772 |
| 1773 // See if it's an instantiation of a generic type. | 1773 // See if it's an instantiation of a generic type. |
| 1774 final typeArgs = type.typeArguments; | 1774 final typeArgs = type.typeArguments; |
| 1775 if (typeArgs.length > 0) { | 1775 if (typeArgs.length > 0) { |
| 1776 final args = | 1776 final args = typeArgs.map((arg) => typeName(arg)).join(', '); |
| 1777 Strings.join(typeArgs.map((arg) => typeName(arg)), ', '); | |
| 1778 return '${type.originalDeclaration.simpleName}<$args>'; | 1777 return '${type.originalDeclaration.simpleName}<$args>'; |
| 1779 } | 1778 } |
| 1780 | 1779 |
| 1781 // Regular type. | 1780 // Regular type. |
| 1782 return type.simpleName; | 1781 return type.simpleName; |
| 1783 } | 1782 } |
| 1784 | 1783 |
| 1785 /** | 1784 /** |
| 1786 * Remove leading indentation to line up with first line. | 1785 * Remove leading indentation to line up with first line. |
| 1787 */ | 1786 */ |
| 1788 unindentCode(SourceLocation span) { | 1787 unindentCode(SourceLocation span) { |
| 1789 final column = span.column; | 1788 final column = span.column; |
| 1790 final lines = span.text.split('\n'); | 1789 final lines = span.text.split('\n'); |
| 1791 // TODO(rnystrom): Dirty hack. | 1790 // TODO(rnystrom): Dirty hack. |
| 1792 for (var i = 1; i < lines.length; i++) { | 1791 for (var i = 1; i < lines.length; i++) { |
| 1793 lines[i] = unindent(lines[i], column); | 1792 lines[i] = unindent(lines[i], column); |
| 1794 } | 1793 } |
| 1795 | 1794 |
| 1796 final code = Strings.join(lines, '\n'); | 1795 final code = lines.join('\n'); |
| 1797 return code; | 1796 return code; |
| 1798 } | 1797 } |
| 1799 | 1798 |
| 1800 /** | 1799 /** |
| 1801 * Takes a string of Dart code and turns it into sanitized HTML. | 1800 * Takes a string of Dart code and turns it into sanitized HTML. |
| 1802 */ | 1801 */ |
| 1803 formatCode(SourceLocation span) { | 1802 formatCode(SourceLocation span) { |
| 1804 final code = unindentCode(span); | 1803 final code = unindentCode(span); |
| 1805 | 1804 |
| 1806 // Syntax highlight. | 1805 // Syntax highlight. |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 return ''' | 2003 return ''' |
| 2005 <div class="mdn"> | 2004 <div class="mdn"> |
| 2006 $mdnComment | 2005 $mdnComment |
| 2007 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> | 2006 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> |
| 2008 </div> | 2007 </div> |
| 2009 '''; | 2008 '''; |
| 2010 } | 2009 } |
| 2011 | 2010 |
| 2012 String toString() => mdnComment; | 2011 String toString() => mdnComment; |
| 2013 } | 2012 } |
| OLD | NEW |