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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 328 } |
329 | 329 |
330 void documentLibraries(List<Path> libraryList, Path libPath, Path pkgPath) { | 330 void documentLibraries(List<Path> libraryList, Path libPath, Path pkgPath) { |
331 final compilation = new Compilation.library(libraryList, libPath, pkgPath); | 331 final compilation = new Compilation.library(libraryList, libPath, pkgPath); |
332 _document(compilation); | 332 _document(compilation); |
333 } | 333 } |
334 | 334 |
335 void _document(Compilation compilation) { | 335 void _document(Compilation compilation) { |
336 // Sort the libraries by name (not key). | 336 // Sort the libraries by name (not key). |
337 _sortedLibraries = new List<LibraryMirror>.from( | 337 _sortedLibraries = new List<LibraryMirror>.from( |
338 compilation.mirrors.libraries.getValues().filter( | 338 compilation.mirrors.libraries.values.filter( |
339 shouldIncludeLibrary)); | 339 shouldIncludeLibrary)); |
340 _sortedLibraries.sort((x, y) { | 340 _sortedLibraries.sort((x, y) { |
341 return displayName(x).toUpperCase().compareTo( | 341 return displayName(x).toUpperCase().compareTo( |
342 displayName(y).toUpperCase()); | 342 displayName(y).toUpperCase()); |
343 }); | 343 }); |
344 | 344 |
345 // Generate the docs. | 345 // Generate the docs. |
346 if (mode == MODE_LIVE_NAV) { | 346 if (mode == MODE_LIVE_NAV) { |
347 docNavigationJson(); | 347 docNavigationJson(); |
348 } else { | 348 } else { |
(...skipping 230 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 (InterfaceMirror type in orderByName(library.types.getValues())) { | 589 for (InterfaceMirror type in orderByName(library.types.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 15 matching lines...) Expand all Loading... |
615 } | 615 } |
616 if (!types.isEmpty) { | 616 if (!types.isEmpty) { |
617 libraryInfo[TYPES] = types; | 617 libraryInfo[TYPES] = types; |
618 } | 618 } |
619 | 619 |
620 libraryList.add(libraryInfo); | 620 libraryList.add(libraryInfo); |
621 } | 621 } |
622 | 622 |
623 List docMembersJson(Map<Object,MemberMirror> memberMap) { | 623 List docMembersJson(Map<Object,MemberMirror> memberMap) { |
624 final members = []; | 624 final members = []; |
625 for (MemberMirror member in orderByName(memberMap.getValues())) { | 625 for (MemberMirror member in orderByName(memberMap.values)) { |
626 if (!showPrivate && member.isPrivate) continue; | 626 if (!showPrivate && member.isPrivate) continue; |
627 | 627 |
628 var memberInfo = {}; | 628 var memberInfo = {}; |
629 if (member.isField) { | 629 if (member.isField) { |
630 memberInfo[KIND] = FIELD; | 630 memberInfo[KIND] = FIELD; |
631 } else { | 631 } else { |
632 MethodMirror method = member; | 632 MethodMirror method = member; |
633 if (method.isConstructor) { | 633 if (method.isConstructor) { |
634 memberInfo[KIND] = CONSTRUCTOR; | 634 memberInfo[KIND] = CONSTRUCTOR; |
635 } else if (method.isSetter) { | 635 } else if (method.isSetter) { |
(...skipping 41 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 = <InterfaceMirror>[]; | 684 final types = <InterfaceMirror>[]; |
685 final exceptions = <InterfaceMirror>[]; | 685 final exceptions = <InterfaceMirror>[]; |
686 | 686 |
687 for (InterfaceMirror type in orderByName(library.types.getValues())) { | 687 for (InterfaceMirror type in orderByName(library.types.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 = <InterfaceMirror>[]; | 748 final classes = <InterfaceMirror>[]; |
749 final interfaces = <InterfaceMirror>[]; | 749 final interfaces = <InterfaceMirror>[]; |
750 final typedefs = <TypedefMirror>[]; | 750 final typedefs = <TypedefMirror>[]; |
751 final exceptions = <InterfaceMirror>[]; | 751 final exceptions = <InterfaceMirror>[]; |
752 | 752 |
753 for (InterfaceMirror type in orderByName(library.types.getValues())) { | 753 for (InterfaceMirror type in orderByName(library.types.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.getValues()) { | 777 for (final type in library.types.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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(ObjectMirror 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.getKeys()); | 1144 var nameSet = new Set<String>.from(getters.keys); |
1145 nameSet.addAll(setters.getKeys()); | 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()); |
1149 }); | 1149 }); |
1150 | 1150 |
1151 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); | 1151 writeln('<div${allInherited ? ' class="inherited"' : ''}>'); |
1152 writeln('<h3>$title</h3>'); | 1152 writeln('<h3>$title</h3>'); |
1153 for (String name in nameList) { | 1153 for (String name in nameList) { |
1154 MemberMirror getter = getters[name]; | 1154 MemberMirror getter = getters[name]; |
1155 MemberMirror setter = setters[name]; | 1155 MemberMirror setter = setters[name]; |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 final InterfaceMirror inheritedFrom; | 1857 final InterfaceMirror 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 |