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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.declaredMembers); |
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.types.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); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 | 677 |
678 writeln('</div>'); | 678 writeln('</div>'); |
679 } | 679 } |
680 | 680 |
681 /** Writes the navigation for the types contained by the given library. */ | 681 /** Writes the navigation for the types contained by the given library. */ |
682 void docLibraryNavigation(LibraryMirror library) { | 682 void docLibraryNavigation(LibraryMirror library) { |
683 // Show the exception types separately. | 683 // Show the exception types separately. |
684 final types = <ClassMirror>[]; | 684 final types = <ClassMirror>[]; |
685 final exceptions = <ClassMirror>[]; | 685 final exceptions = <ClassMirror>[]; |
686 | 686 |
687 for (ClassMirror type in orderByName(library.types.values)) { | 687 for (ClassMirror type in orderByName(library.classes.values)) { |
688 if (!showPrivate && type.isPrivate) continue; | 688 if (!showPrivate && type.isPrivate) continue; |
689 | 689 |
690 if (isException(type)) { | 690 if (isException(type)) { |
691 exceptions.add(type); | 691 exceptions.add(type); |
692 } else { | 692 } else { |
693 types.add(type); | 693 types.add(type); |
694 } | 694 } |
695 } | 695 } |
696 | 696 |
697 if ((types.length == 0) && (exceptions.length == 0)) return; | 697 if ((types.length == 0) && (exceptions.length == 0)) return; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 | 743 |
744 // Document the top-level members. | 744 // Document the top-level members. |
745 docMembers(library); | 745 docMembers(library); |
746 | 746 |
747 // Document the types. | 747 // Document the types. |
748 final classes = <ClassMirror>[]; | 748 final classes = <ClassMirror>[]; |
749 final interfaces = <ClassMirror>[]; | 749 final interfaces = <ClassMirror>[]; |
750 final typedefs = <TypedefMirror>[]; | 750 final typedefs = <TypedefMirror>[]; |
751 final exceptions = <ClassMirror>[]; | 751 final exceptions = <ClassMirror>[]; |
752 | 752 |
753 for (ClassMirror type in orderByName(library.types.values)) { | 753 for (ClassMirror type in orderByName(library.classes.values)) { |
754 if (!showPrivate && type.isPrivate) continue; | 754 if (!showPrivate && type.isPrivate) continue; |
755 | 755 |
756 if (isException(type)) { | 756 if (isException(type)) { |
757 exceptions.add(type); | 757 exceptions.add(type); |
758 } else if (type.isClass) { | 758 } else if (type.isClass) { |
759 classes.add(type); | 759 classes.add(type); |
760 } else if (type.isInterface){ | 760 } else if (type.isInterface){ |
761 interfaces.add(type); | 761 interfaces.add(type); |
762 } else if (type is TypedefMirror) { | 762 } else if (type is TypedefMirror) { |
763 typedefs.add(type); | 763 typedefs.add(type); |
764 } else { | 764 } else { |
765 throw new InternalError("internal error: unknown type $type."); | 765 throw new InternalError("internal error: unknown type $type."); |
766 } | 766 } |
767 } | 767 } |
768 | 768 |
769 docTypes(classes, 'Classes'); | 769 docTypes(classes, 'Classes'); |
770 docTypes(interfaces, 'Interfaces'); | 770 docTypes(interfaces, 'Interfaces'); |
771 docTypes(typedefs, 'Typedefs'); | 771 docTypes(typedefs, 'Typedefs'); |
772 docTypes(exceptions, 'Exceptions'); | 772 docTypes(exceptions, 'Exceptions'); |
773 | 773 |
774 writeFooter(); | 774 writeFooter(); |
775 endFile(); | 775 endFile(); |
776 | 776 |
777 for (final type in library.types.values) { | 777 for (final type in library.classes.values) { |
778 if (!showPrivate && type.isPrivate) continue; | 778 if (!showPrivate && type.isPrivate) continue; |
779 | 779 |
780 docType(type); | 780 docType(type); |
781 } | 781 } |
782 } | 782 } |
783 | 783 |
784 void docTypes(List types, String header) { | 784 void docTypes(List types, String header) { |
785 if (types.length == 0) return; | 785 if (types.length == 0) return; |
786 | 786 |
787 writeln('<div>'); | 787 writeln('<div>'); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 = (() { |
1753 final match = | 1753 final match = |
1754 new RegExp(r'new ([\w$]+)(?:\.([\w$]+))?').firstMatch(name); | 1754 new RegExp(r'new ([\w$]+)(?:\.([\w$]+))?').firstMatch(name); |
1755 if (match == null) return; | 1755 if (match == null) return; |
1756 String typeName = match[1]; | 1756 String typeName = match[1]; |
1757 ClassMirror foundtype = currentLibrary.types[typeName]; | 1757 ClassMirror foundtype = currentLibrary.classes[typeName]; |
1758 if (foundtype == null) return; | 1758 if (foundtype == null) return; |
1759 String constructorName = | 1759 String constructorName = |
1760 (match[2] == null) ? typeName : '$typeName.${match[2]}'; | 1760 (match[2] == null) ? typeName : '$typeName.${match[2]}'; |
1761 final constructor = | 1761 final constructor = |
1762 foundtype.constructors[constructorName]; | 1762 foundtype.constructors[constructorName]; |
1763 if (constructor == null) return; | 1763 if (constructor == null) return; |
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.types[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.declaredMembers[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.types[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.declaredMembers[name]; |
1787 if (foundMember != null) { | 1787 if (foundMember != null) { |
1788 return makeLink(memberUrl(foundMember)); | 1788 return makeLink(memberUrl(foundMember)); |
1789 } | 1789 } |
1790 } | 1790 } |
(...skipping 66 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 |