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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 * [packageRoot] is the packages directory of the directory being analyzed. | 60 * [packageRoot] is the packages directory of the directory being analyzed. |
| 61 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 61 * If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 62 * also be documented. | 62 * also be documented. |
| 63 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 63 * If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 64 * This option is useful when only the SDK libraries are needed. | 64 * This option is useful when only the SDK libraries are needed. |
| 65 * | 65 * |
| 66 * Returns `true` if docgen sucessfuly completes. | 66 * Returns `true` if docgen sucessfuly completes. |
| 67 */ | 67 */ |
| 68 Future<bool> docgen(List<String> files, {String packageRoot, | 68 Future<bool> docgen(List<String> files, {String packageRoot, |
| 69 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 69 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 70 bool parseSdk: false}) { | 70 bool parseSdk: false, bool append: false}) { |
| 71 if (!append) { | |
| 72 var dir = new Directory('docs'); | |
| 73 if (dir.existsSync()) dir.deleteSync(recursive: true); | |
| 74 } | |
| 75 | |
| 71 if (packageRoot == null && !parseSdk) { | 76 if (packageRoot == null && !parseSdk) { |
| 72 // TODO(janicejl): At the moment, if a single file is passed it, it is | 77 // TODO(janicejl): At the moment, if a single file is passed it, it is |
| 73 // assumed that it does not have a package root unless it is passed in by | 78 // assumed that it does not have a package root unless it is passed in by |
| 74 // the user. In future, find a better way to find the packageRoot and also | 79 // the user. In future, find a better way to find the packageRoot and also |
| 75 // fully test finding the packageRoot. | 80 // fully test finding the packageRoot. |
| 76 if (FileSystemEntity.typeSync(files.first) | 81 if (FileSystemEntity.typeSync(files.first) |
| 77 == FileSystemEntityType.DIRECTORY) { | 82 == FileSystemEntityType.DIRECTORY) { |
| 78 packageRoot = _findPackageRoot(files.first); | 83 packageRoot = _findPackageRoot(files.first); |
| 79 } | 84 } |
| 80 } | 85 } |
| 81 logger.info('Package Root: ${packageRoot}'); | 86 logger.info('Package Root: ${packageRoot}'); |
| 82 | 87 |
| 83 linkResolver = (name) => | 88 linkResolver = (name) => |
| 84 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 89 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 85 | 90 |
| 86 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) | 91 return getMirrorSystem(files, packageRoot: packageRoot, parseSdk: parseSdk) |
| 87 .then((MirrorSystem mirrorSystem) { | 92 .then((MirrorSystem mirrorSystem) { |
| 88 if (mirrorSystem.libraries.isEmpty) { | 93 if (mirrorSystem.libraries.isEmpty) { |
| 89 throw new StateError('No library mirrors were created.'); | 94 throw new StateError('No library mirrors were created.'); |
| 90 } | 95 } |
| 91 _documentLibraries(mirrorSystem.libraries.values, | 96 _documentLibraries(mirrorSystem.libraries.values, |
| 92 includeSdk: includeSdk, includePrivate: includePrivate, | 97 includeSdk: includeSdk, includePrivate: includePrivate, |
| 93 outputToYaml: outputToYaml); | 98 outputToYaml: outputToYaml, append: append); |
| 94 | 99 |
| 95 return true; | 100 return true; |
| 96 }); | 101 }); |
| 97 } | 102 } |
| 98 | 103 |
| 99 List<String> _listLibraries(List<String> args) { | 104 List<String> _listLibraries(List<String> args) { |
| 100 // TODO(janicejl): At the moment, only have support to have either one file, | 105 // TODO(janicejl): At the moment, only have support to have either one file, |
| 101 // or one directory. This is because there can only be one package directory | 106 // or one directory. This is because there can only be one package directory |
| 102 // since only one docgen is created per run. | 107 // since only one docgen is created per run. |
| 103 if (args.length != 1) throw new UnsupportedError(USAGE); | 108 if (args.length != 1) throw new UnsupportedError(USAGE); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 // system, and it is not possible to use the stack trace. BUG(#11622) | 194 // system, and it is not possible to use the stack trace. BUG(#11622) |
| 190 // To avoid printing the stack trace. | 195 // To avoid printing the stack trace. |
| 191 exit(1); | 196 exit(1); |
| 192 }); | 197 }); |
| 193 } | 198 } |
| 194 | 199 |
| 195 /** | 200 /** |
| 196 * Creates documentation for filtered libraries. | 201 * Creates documentation for filtered libraries. |
| 197 */ | 202 */ |
| 198 void _documentLibraries(List<LibraryMirror> libraries, | 203 void _documentLibraries(List<LibraryMirror> libraries, |
| 199 {bool includeSdk:false, bool includePrivate:false, bool | 204 {bool includeSdk:false, bool includePrivate:false, |
| 200 outputToYaml:true}) { | 205 bool outputToYaml:true, bool append: false}) { |
|
Bob Nystrom
2013/07/30 16:23:29
Style nit: add spaces after other ":" in param lis
| |
| 201 libraries.forEach((lib) { | 206 libraries.forEach((lib) { |
| 202 // Files belonging to the SDK have a uri that begins with 'dart:'. | 207 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 203 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 208 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 204 var library = generateLibrary(lib, includePrivate: includePrivate); | 209 var library = generateLibrary(lib, includePrivate: includePrivate); |
| 205 _writeLibraryToFile(library, outputToYaml); | 210 _writeLibraryToFile(library, outputToYaml); |
| 206 } | 211 } |
| 207 }); | 212 }); |
| 208 // Outputs a text file with a list of files available after creating all | 213 // Outputs a text file with a list of files available after creating all |
| 209 // the libraries. This will help the viewer know what files are available | 214 // the libraries. This will help the viewer know what files are available |
| 210 // to read in. | 215 // to read in. |
| 211 _writeToFile(listDir('docs').join('\n').replaceAll('docs/', ''), | 216 _writeToFile(listDir('docs').join('\n').replaceAll('docs/', ''), |
| 212 'library_list.txt'); | 217 'library_list.txt', append: append); |
| 213 // Outputs all the qualified names documented. This will help generate search | 218 // Outputs all the qualified names documented. This will help generate search |
| 214 // results. | 219 // results. |
| 215 _writeToFile(qualifiedNameIndex.join('\n'), 'index.txt'); | 220 _writeToFile(qualifiedNameIndex.join('\n'), 'index.txt', append: append); |
| 216 } | 221 } |
| 217 | 222 |
| 218 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, | 223 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, |
| 219 {bool includePrivate:false}) { | 224 {bool includePrivate:false}) { |
| 220 _currentLibrary = library; | 225 _currentLibrary = library; |
| 221 var result = new Library(library.qualifiedName, _getComment(library), | 226 var result = new Library(library.qualifiedName, _getComment(library), |
| 222 _getVariables(library.variables, includePrivate), | 227 _getVariables(library.variables, includePrivate), |
| 223 _getMethods(library.functions, includePrivate), | 228 _getMethods(library.functions, includePrivate), |
| 224 _getClasses(library.classes, includePrivate)); | 229 _getClasses(library.classes, includePrivate)); |
| 225 logger.fine('Generated library for ${result.name}'); | 230 logger.fine('Generated library for ${result.name}'); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 innerList.add(new Type(e.qualifiedName, _typeGenerics(e))); | 441 innerList.add(new Type(e.qualifiedName, _typeGenerics(e))); |
| 437 }); | 442 }); |
| 438 return innerList; | 443 return innerList; |
| 439 } | 444 } |
| 440 return []; | 445 return []; |
| 441 } | 446 } |
| 442 | 447 |
| 443 /** | 448 /** |
| 444 * Writes text to a file in the 'docs' directory. | 449 * Writes text to a file in the 'docs' directory. |
| 445 */ | 450 */ |
| 446 void _writeToFile(String text, String filename) { | 451 void _writeToFile(String text, String filename, {bool append: false}) { |
| 447 Directory dir = new Directory('docs'); | 452 Directory dir = new Directory('docs'); |
| 448 if (!dir.existsSync()) { | 453 if (!dir.existsSync()) { |
| 449 dir.createSync(); | 454 dir.createSync(); |
| 450 } | 455 } |
| 451 File file = new File('docs/$filename'); | 456 File file = new File('docs/$filename'); |
| 452 if (!file.existsSync()) { | 457 if (!file.existsSync()) { |
| 453 file.createSync(); | 458 file.createSync(); |
| 454 } | 459 } |
| 455 file.openSync(); | 460 file.writeAsString(text, mode: append ? FileMode.APPEND : FileMode.WRITE); |
| 456 file.writeAsString(text); | |
| 457 } | 461 } |
| 458 | 462 |
| 459 /** | 463 /** |
| 460 * Transforms the map by calling toMap on each value in it. | 464 * Transforms the map by calling toMap on each value in it. |
| 461 */ | 465 */ |
| 462 Map recurseMap(Map inputMap) { | 466 Map recurseMap(Map inputMap) { |
| 463 var outputMap = {}; | 467 var outputMap = {}; |
| 464 inputMap.forEach((key, value) { | 468 inputMap.forEach((key, value) { |
| 465 if (value is Map) { | 469 if (value is Map) { |
| 466 outputMap[key] = recurseMap(value); | 470 outputMap[key] = recurseMap(value); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 String outer; | 734 String outer; |
| 731 List<Type> inner; | 735 List<Type> inner; |
| 732 | 736 |
| 733 Type(this.outer, this.inner); | 737 Type(this.outer, this.inner); |
| 734 | 738 |
| 735 Map toMap() => { | 739 Map toMap() => { |
| 736 'outer': outer, | 740 'outer': outer, |
| 737 'inner': new List.from(inner.map((e) => e.toMap())) | 741 'inner': new List.from(inner.map((e) => e.toMap())) |
| 738 }; | 742 }; |
| 739 } | 743 } |
| OLD | NEW |