Chromium Code Reviews| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 * [packageRoot] is the packages directory of the directory being analyzed. | 72 * [packageRoot] is the packages directory of the directory being analyzed. |
| 73 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 73 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 74 * also be documented. | 74 * also be documented. |
| 75 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 75 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 76 * This option is useful when only the SDK libraries are needed. | 76 * This option is useful when only the SDK libraries are needed. |
| 77 * | 77 * |
| 78 * Returns `true` if docgen sucessfuly completes. | 78 * Returns `true` if docgen sucessfuly completes. |
| 79 */ | 79 */ |
| 80 Future<bool> docgen(List<String> files, {String packageRoot, | 80 Future<bool> docgen(List<String> files, {String packageRoot, |
| 81 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 81 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 82 bool parseSdk: false, bool append: false}) { | 82 bool parseSdk: false, bool append: false, String introduction: ''}) { |
| 83 _includePrivate = includePrivate; | 83 _includePrivate = includePrivate; |
| 84 if (!append) { | 84 if (!append) { |
| 85 var dir = new Directory('docs'); | 85 var dir = new Directory('docs'); |
| 86 if (dir.existsSync()) dir.deleteSync(recursive: true); | 86 if (dir.existsSync()) dir.deleteSync(recursive: true); |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (packageRoot == null && !parseSdk) { | 89 if (packageRoot == null && !parseSdk) { |
| 90 var type = FileSystemEntity.typeSync(files.first); | 90 var type = FileSystemEntity.typeSync(files.first); |
| 91 if (type == FileSystemEntityType.DIRECTORY) { | 91 if (type == FileSystemEntityType.DIRECTORY) { |
| 92 packageRoot = _findPackageRoot(files.first); | 92 packageRoot = _findPackageRoot(files.first); |
| 93 } else if (type == FileSystemEntityType.FILE) { | 93 } else if (type == FileSystemEntityType.FILE) { |
| 94 logger.warning('WARNING: No package root defined. If Docgen fails, try ' | 94 logger.warning('WARNING: No package root defined. If Docgen fails, try ' |
| 95 'again by setting the --package-root option.'); | 95 'again by setting the --package-root option.'); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 logger.info('Package Root: ${packageRoot}'); | 98 logger.info('Package Root: ${packageRoot}'); |
| 99 | 99 |
| 100 linkResolver = (name) => | 100 linkResolver = (name) => |
| 101 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 101 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 102 | 102 |
| 103 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) | 103 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) |
| 104 .then((MirrorSystem mirrorSystem) { | 104 .then((MirrorSystem mirrorSystem) { |
| 105 if (mirrorSystem.libraries.isEmpty) { | 105 if (mirrorSystem.libraries.isEmpty) { |
| 106 throw new StateError('No library mirrors were created.'); | 106 throw new StateError('No library mirrors were created.'); |
| 107 } | 107 } |
| 108 _documentLibraries(mirrorSystem.libraries.values,includeSdk: includeSdk, | 108 _documentLibraries(mirrorSystem.libraries.values,includeSdk: includeSdk, |
| 109 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk); | 109 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, |
| 110 introduction: introduction); | |
| 110 | 111 |
| 111 return true; | 112 return true; |
| 112 }); | 113 }); |
| 113 } | 114 } |
| 114 | 115 |
| 115 List<String> _listLibraries(List<String> args) { | 116 List<String> _listLibraries(List<String> args) { |
| 116 if (args.length != 1) throw new UnsupportedError(USAGE); | 117 if (args.length != 1) throw new UnsupportedError(USAGE); |
| 117 var libraries = new List<String>(); | 118 var libraries = new List<String>(); |
| 118 var type = FileSystemEntity.typeSync(args[0]); | 119 var type = FileSystemEntity.typeSync(args[0]); |
| 119 | 120 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 // system, and it is not possible to use the stack trace. BUG(#11622) | 216 // system, and it is not possible to use the stack trace. BUG(#11622) |
| 216 // To avoid printing the stack trace. | 217 // To avoid printing the stack trace. |
| 217 exit(1); | 218 exit(1); |
| 218 }); | 219 }); |
| 219 } | 220 } |
| 220 | 221 |
| 221 /** | 222 /** |
| 222 * Creates documentation for filtered libraries. | 223 * Creates documentation for filtered libraries. |
| 223 */ | 224 */ |
| 224 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false, | 225 void _documentLibraries(List<LibraryMirror> libs, {bool includeSdk: false, |
| 225 bool outputToYaml: true, bool append: false, bool parseSdk: false}) { | 226 bool outputToYaml: true, bool append: false, bool parseSdk: false, |
| 227 String introduction: ''}) { | |
| 226 libs.forEach((lib) { | 228 libs.forEach((lib) { |
| 227 // Files belonging to the SDK have a uri that begins with 'dart:'. | 229 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 228 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 230 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 229 var library = generateLibrary(lib); | 231 var library = generateLibrary(lib); |
| 230 entityMap[library.qualifiedName] = library; | 232 entityMap[library.qualifiedName] = library; |
| 231 } | 233 } |
| 232 }); | 234 }); |
| 233 // After everything is created, do a pass through all classes to make sure no | 235 // After everything is created, do a pass through all classes to make sure no |
| 234 // intermediate classes created by mixins are included. | 236 // intermediate classes created by mixins are included. |
| 235 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); | 237 entityMap.values.where((e) => e is Class).forEach((c) => c.makeValid()); |
| 236 // Everything is a subclass of Object, therefore empty the list to avoid a | 238 // Everything is a subclass of Object, therefore empty the list to avoid a |
| 237 // giant list of subclasses to be printed out. | 239 // giant list of subclasses to be printed out. |
| 238 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); | 240 if (parseSdk) entityMap['dart.core.Object'].subclasses.clear(); |
| 239 | 241 |
| 240 var filteredEntities = entityMap.values.where(_isVisible); | 242 var filteredEntities = entityMap.values.where(_isVisible); |
| 241 // Output libraries and classes to file after all information is generated. | 243 // Output libraries and classes to file after all information is generated. |
| 242 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 244 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 243 _writeIndexableToFile(output, outputToYaml); | 245 _writeIndexableToFile(output, outputToYaml); |
| 244 }); | 246 }); |
| 247 var intro = introduction == '' ? | |
|
Emily Fortuna
2013/08/15 18:39:35
any reason why you define a new variable here inst
janicejl
2013/08/15 18:45:59
Done. Moved it down to the map instead.
| |
| 248 '' : markdown.markdownToHtml(new File(introduction).readAsStringSync(), | |
| 249 linkResolver: linkResolver, inlineSyntaxes: markdownSyntaxes); | |
| 245 // Outputs a yaml file with all libraries and their preview comments after | 250 // Outputs a yaml file with all libraries and their preview comments after |
| 246 // creating all libraries. This will help the viewer know what libraries are | 251 // creating all libraries. This will help the viewer know what libraries are |
| 247 // available to read in. | 252 // available to read in. |
| 248 var libraryMap = {'libraries' : filteredEntities.where((e) => | 253 var libraryMap = { |
| 249 e is Library).map((e) => e.previewMap).toList()}; | 254 'libraries' : filteredEntities.where((e) => |
| 255 e is Library).map((e) => e.previewMap).toList(), | |
| 256 'introduction' : intro | |
| 257 }; | |
| 250 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', append: append); | 258 _writeToFile(getYamlString(libraryMap), 'library_list.yaml', append: append); |
| 251 // Outputs all the qualified names documented with their type. | 259 // Outputs all the qualified names documented with their type. |
| 252 // This will help generate search results. | 260 // This will help generate search results. |
| 253 _writeToFile(filteredEntities.map((e) => | 261 _writeToFile(filteredEntities.map((e) => |
| 254 '${e.qualifiedName} ${e.typeName}').join('\n'), | 262 '${e.qualifiedName} ${e.typeName}').join('\n'), |
| 255 'index.txt', append: append); | 263 'index.txt', append: append); |
| 256 } | 264 } |
| 257 | 265 |
| 258 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 266 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| 259 _currentLibrary = library; | 267 _currentLibrary = library; |
| (...skipping 827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 String qualifiedName; | 1095 String qualifiedName; |
| 1088 List<String> parameters; | 1096 List<String> parameters; |
| 1089 | 1097 |
| 1090 Annotation(this.qualifiedName, this.parameters); | 1098 Annotation(this.qualifiedName, this.parameters); |
| 1091 | 1099 |
| 1092 Map toMap() => { | 1100 Map toMap() => { |
| 1093 'name': qualifiedName, | 1101 'name': qualifiedName, |
| 1094 'parameters': parameters | 1102 'parameters': parameters |
| 1095 }; | 1103 }; |
| 1096 } | 1104 } |
| OLD | NEW |