| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 * **docgen** is a tool for creating machine readable representations of Dart | 6 * **docgen** is a tool for creating machine readable representations of Dart |
| 7 * code metadata, including: classes, members, comments and annotations. | 7 * code metadata, including: classes, members, comments and annotations. |
| 8 * | 8 * |
| 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. | 9 * docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 10 * | 10 * |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); | 217 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); |
| 218 // Everything is a subclass of Object, therefore empty the list to avoid a | 218 // Everything is a subclass of Object, therefore empty the list to avoid a |
| 219 // giant list of subclasses to be printed out. | 219 // giant list of subclasses to be printed out. |
| 220 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); | 220 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); |
| 221 | 221 |
| 222 var filteredEntities = entityMap.values.where(_isVisible); | 222 var filteredEntities = entityMap.values.where(_isVisible); |
| 223 // Output libraries and classes to file after all information is generated. | 223 // Output libraries and classes to file after all information is generated. |
| 224 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 224 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 225 _writeIndexableToFile(output, outputToYaml); | 225 _writeIndexableToFile(output, outputToYaml); |
| 226 }); | 226 }); |
| 227 // Outputs a text file with a list of libraries available after creating all | 227 // Outputs a yaml file with all libraries and their preview comments after |
| 228 // the libraries. This will help the viewer know what libraries are available | 228 // creating all libraries. This will help the viewer know what libraries are |
| 229 // to read in. | 229 // available to read in. |
| 230 _writeToFile(filteredEntities.where((e) => e is Library) | 230 var libraryMap = {'libraries' : filteredEntities.where((e) => |
| 231 .map((e) => e.qualifiedName).join('\n'), 'library_list.txt', | 231 e is Library).map((e) => e.previewMap).toList()}; |
| 232 append: append); | 232 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', append: append); |
| 233 // Outputs all the qualified names documented with their type. | 233 // Outputs all the qualified names documented with their type. |
| 234 // This will help generate search results. | 234 // This will help generate search results. |
| 235 _writeToFile(filteredEntities.map((e) => | 235 _writeToFile(filteredEntities.map((e) => |
| 236 '${e.qualifiedName} ${e.typeName}').join('\n'), | 236 '${e.qualifiedName} ${e.typeName}').join('\n'), |
| 237 'index.txt', append: append); | 237 'index.txt', append: append); |
| 238 } | 238 } |
| 239 | 239 |
| 240 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 240 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| 241 _currentLibrary = library; | 241 _currentLibrary = library; |
| 242 var result = new Library(library.qualifiedName, _commentToHtml(library), | 242 var result = new Library(library.qualifiedName, _commentToHtml(library), |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 | 515 |
| 516 /// Qualified Name of the owner of this Indexable Item. | 516 /// Qualified Name of the owner of this Indexable Item. |
| 517 /// For Library, owner will be ""; | 517 /// For Library, owner will be ""; |
| 518 String owner; | 518 String owner; |
| 519 | 519 |
| 520 Indexable(this.name, this.comment, this.qualifiedName, this.isPrivate, | 520 Indexable(this.name, this.comment, this.qualifiedName, this.isPrivate, |
| 521 this.owner); | 521 this.owner); |
| 522 | 522 |
| 523 /// The type of this member to be used in index.txt. | 523 /// The type of this member to be used in index.txt. |
| 524 String get typeName => ''; | 524 String get typeName => ''; |
| 525 |
| 526 /** |
| 527 * Creates a [Map] with this [Indexable]'s name and a preview comment. |
| 528 */ |
| 529 Map get previewMap { |
| 530 var finalMap = { 'name' : qualifiedName }; |
| 531 if (comment != '') { |
| 532 var index = comment.indexOf('</p>'); |
| 533 finalMap['preview'] = '${comment.substring(0, index)}</p>'; |
| 534 } |
| 535 return finalMap; |
| 536 } |
| 525 } | 537 } |
| 526 | 538 |
| 527 /** | 539 /** |
| 528 * A class containing contents of a Dart library. | 540 * A class containing contents of a Dart library. |
| 529 */ | 541 */ |
| 530 class Library extends Indexable { | 542 class Library extends Indexable { |
| 531 | 543 |
| 532 /// Top-level variables in the library. | 544 /// Top-level variables in the library. |
| 533 Map<String, Variable> variables; | 545 Map<String, Variable> variables; |
| 534 | 546 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 throw new ArgumentError('${mirror.simpleName} - no class type match. '); | 756 throw new ArgumentError('${mirror.simpleName} - no class type match. '); |
| 745 } | 757 } |
| 746 } | 758 } |
| 747 | 759 |
| 748 /** | 760 /** |
| 749 * Checks if the given name is a key for any of the Class Maps. | 761 * Checks if the given name is a key for any of the Class Maps. |
| 750 */ | 762 */ |
| 751 bool containsKey(String name) { | 763 bool containsKey(String name) { |
| 752 return classes.containsKey(name) || errors.containsKey(name); | 764 return classes.containsKey(name) || errors.containsKey(name); |
| 753 } | 765 } |
| 754 | |
| 755 /** | |
| 756 * Creates a [Map] with [Class] names and a preview comment. | |
| 757 */ | |
| 758 Map classMap(Class clazz) { | |
| 759 var finalMap = { 'name' : clazz.qualifiedName }; | |
| 760 if (clazz.comment != '') { | |
| 761 var index = clazz.comment.indexOf('</p>'); | |
| 762 finalMap['preview'] = '${clazz.comment.substring(0, index)}</p>'; | |
| 763 } | |
| 764 return finalMap; | |
| 765 } | |
| 766 | 766 |
| 767 Map toMap() => { | 767 Map toMap() => { |
| 768 'class': classes.values.where(_isVisible) | 768 'class': classes.values.where(_isVisible) |
| 769 .map((e) => classMap(e)).toList(), | 769 .map((e) => e.previewMap).toList(), |
| 770 'typedef': recurseMap(typedefs), | 770 'typedef': recurseMap(typedefs), |
| 771 'error': errors.values.where(_isVisible) | 771 'error': errors.values.where(_isVisible) |
| 772 .map((e) => classMap(e)).toList() | 772 .map((e) => e.previewMap).toList() |
| 773 }; | 773 }; |
| 774 } | 774 } |
| 775 | 775 |
| 776 class Typedef extends Indexable { | 776 class Typedef extends Indexable { |
| 777 String returnType; | 777 String returnType; |
| 778 | 778 |
| 779 Map<String, Parameter> parameters; | 779 Map<String, Parameter> parameters; |
| 780 | 780 |
| 781 /// Generic information about the typedef. | 781 /// Generic information about the typedef. |
| 782 Map<String, Generic> generics; | 782 Map<String, Generic> generics; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 String qualifiedName; | 1061 String qualifiedName; |
| 1062 List<String> parameters; | 1062 List<String> parameters; |
| 1063 | 1063 |
| 1064 Annotation(this.qualifiedName, this.parameters); | 1064 Annotation(this.qualifiedName, this.parameters); |
| 1065 | 1065 |
| 1066 Map toMap() => { | 1066 Map toMap() => { |
| 1067 'name': qualifiedName, | 1067 'name': qualifiedName, |
| 1068 'parameters': parameters | 1068 'parameters': parameters |
| 1069 }; | 1069 }; |
| 1070 } | 1070 } |
| OLD | NEW |