| 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 /// **docgen** is a tool for creating machine readable representations of Dart | 5 /// **docgen** is a tool for creating machine readable representations of Dart |
| 6 /// code metadata, including: classes, members, comments and annotations. | 6 /// code metadata, including: classes, members, comments and annotations. |
| 7 /// | 7 /// |
| 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. | 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. |
| 9 /// | 9 /// |
| 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] | 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 111 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 112 /// also be documented. | 112 /// also be documented. |
| 113 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 113 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 114 /// This option is useful when only the SDK libraries are needed. | 114 /// This option is useful when only the SDK libraries are needed. |
| 115 /// | 115 /// |
| 116 /// Returned Future completes with true if document generation is successful. | 116 /// Returned Future completes with true if document generation is successful. |
| 117 Future<bool> docgen(List<String> files, {String packageRoot, | 117 Future<bool> docgen(List<String> files, {String packageRoot, |
| 118 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 118 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 119 bool parseSdk: false, bool append: false, String introFileName: '', | 119 bool parseSdk: false, bool append: false, String introFileName: '', |
| 120 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], | 120 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], |
| 121 bool includeDependentPackages: false}) { | 121 bool includeDependentPackages: false, startPage}) { |
| 122 return _Generator.generateDocumentation(files, packageRoot: packageRoot, | 122 return _Generator.generateDocumentation(files, packageRoot: packageRoot, |
| 123 outputToYaml: outputToYaml, includePrivate: includePrivate, | 123 outputToYaml: outputToYaml, includePrivate: includePrivate, |
| 124 includeSdk: includeSdk, parseSdk: parseSdk, append: append, | 124 includeSdk: includeSdk, parseSdk: parseSdk, append: append, |
| 125 introFileName: introFileName, out: out, | 125 introFileName: introFileName, out: out, |
| 126 excludeLibraries: excludeLibraries, | 126 excludeLibraries: excludeLibraries, |
| 127 includeDependentPackages: includeDependentPackages); | 127 includeDependentPackages: includeDependentPackages, |
| 128 startPage: startPage); |
| 128 } | 129 } |
| 129 | 130 |
| 130 /// Analyzes set of libraries by getting a mirror system and triggers the | 131 /// Analyzes set of libraries by getting a mirror system and triggers the |
| 131 /// documentation of the libraries. | 132 /// documentation of the libraries. |
| 132 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, | 133 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, |
| 133 {String packageRoot, bool parseSdk: false}) { | 134 {String packageRoot, bool parseSdk: false}) { |
| 134 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 135 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 135 | 136 |
| 136 // Finds the root of SDK library based off the location of docgen. | 137 // Finds the root of SDK library based off the location of docgen. |
| 137 var root = _Generator._rootDirectory; | 138 var root = _Generator._rootDirectory; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 /// also be documented. | 233 /// also be documented. |
| 233 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 234 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 234 /// This option is useful when only the SDK libraries are needed. | 235 /// This option is useful when only the SDK libraries are needed. |
| 235 /// | 236 /// |
| 236 /// Returned Future completes with true if document generation is successful. | 237 /// Returned Future completes with true if document generation is successful. |
| 237 static Future<bool> generateDocumentation(List<String> files, | 238 static Future<bool> generateDocumentation(List<String> files, |
| 238 {String packageRoot, bool outputToYaml: true, bool includePrivate: false, | 239 {String packageRoot, bool outputToYaml: true, bool includePrivate: false, |
| 239 bool includeSdk: false, bool parseSdk: false, bool append: false, | 240 bool includeSdk: false, bool parseSdk: false, bool append: false, |
| 240 String introFileName: '', out: _DEFAULT_OUTPUT_DIRECTORY, | 241 String introFileName: '', out: _DEFAULT_OUTPUT_DIRECTORY, |
| 241 List<String> excludeLibraries : const [], | 242 List<String> excludeLibraries : const [], |
| 242 bool includeDependentPackages: false}) { | 243 bool includeDependentPackages: false, startPage}) { |
| 243 _excluded = excludeLibraries; | 244 _excluded = excludeLibraries; |
| 244 _includePrivate = includePrivate; | 245 _includePrivate = includePrivate; |
| 245 logger.onRecord.listen((record) => print(record.message)); | 246 logger.onRecord.listen((record) => print(record.message)); |
| 246 | 247 |
| 247 _ensureOutputDirectory(out, append); | 248 _ensureOutputDirectory(out, append); |
| 248 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); | 249 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); |
| 249 | 250 |
| 250 var requestedLibraries = _findLibrariesToDocument(files, | 251 var requestedLibraries = _findLibrariesToDocument(files, |
| 251 includeDependentPackages); | 252 includeDependentPackages); |
| 252 | 253 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 270 availableLibraries); | 271 availableLibraries); |
| 271 var librariesToDocument = requestedLibraries.map( | 272 var librariesToDocument = requestedLibraries.map( |
| 272 (each) => availableLibrariesByPath.putIfAbsent(each, | 273 (each) => availableLibrariesByPath.putIfAbsent(each, |
| 273 () => throw "Missing library $each")).toList(); | 274 () => throw "Missing library $each")).toList(); |
| 274 librariesToDocument.addAll( | 275 librariesToDocument.addAll( |
| 275 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); | 276 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); |
| 276 librariesToDocument.removeWhere( | 277 librariesToDocument.removeWhere( |
| 277 (x) => _excluded.contains(dart2js_util.nameOf(x))); | 278 (x) => _excluded.contains(dart2js_util.nameOf(x))); |
| 278 _documentLibraries(librariesToDocument, includeSdk: includeSdk, | 279 _documentLibraries(librariesToDocument, includeSdk: includeSdk, |
| 279 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, | 280 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, |
| 280 introFileName: introFileName); | 281 introFileName: introFileName, startPage: startPage); |
| 281 return true; | 282 return true; |
| 282 }); | 283 }); |
| 283 } | 284 } |
| 284 | 285 |
| 285 /// Writes [text] to a file in the output directory. | 286 /// Writes [text] to a file in the output directory. |
| 286 static void _writeToFile(String text, String filename, {bool append: false}) { | 287 static void _writeToFile(String text, String filename, {bool append: false}) { |
| 287 if (text == null) return; | 288 if (text == null) return; |
| 288 Directory dir = new Directory(_outputDirectory); | 289 Directory dir = new Directory(_outputDirectory); |
| 289 if (!dir.existsSync()) { | 290 if (!dir.existsSync()) { |
| 290 dir.createSync(); | 291 dir.createSync(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 303 } | 304 } |
| 304 } | 305 } |
| 305 File file = new File(path.join(_outputDirectory, filename)); | 306 File file = new File(path.join(_outputDirectory, filename)); |
| 306 file.writeAsStringSync(text, | 307 file.writeAsStringSync(text, |
| 307 mode: append ? FileMode.APPEND : FileMode.WRITE); | 308 mode: append ? FileMode.APPEND : FileMode.WRITE); |
| 308 } | 309 } |
| 309 | 310 |
| 310 /// Creates documentation for filtered libraries. | 311 /// Creates documentation for filtered libraries. |
| 311 static void _documentLibraries(List<LibraryMirror> libs, | 312 static void _documentLibraries(List<LibraryMirror> libs, |
| 312 {bool includeSdk: false, bool outputToYaml: true, bool append: false, | 313 {bool includeSdk: false, bool outputToYaml: true, bool append: false, |
| 313 bool parseSdk: false, String introFileName: ''}) { | 314 bool parseSdk: false, String introFileName: '', startPage}) { |
| 314 libs.forEach((lib) { | 315 libs.forEach((lib) { |
| 315 // Files belonging to the SDK have a uri that begins with 'dart:'. | 316 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 316 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 317 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 317 var library = generateLibrary(lib); | 318 var library = generateLibrary(lib); |
| 318 entityMap[library.name] = library; | 319 entityMap[library.name] = library; |
| 319 } | 320 } |
| 320 }); | 321 }); |
| 321 | 322 |
| 322 var filteredEntities = entityMap.values.where(_isFullChainVisible); | 323 var filteredEntities = entityMap.values.where(_isFullChainVisible); |
| 323 | 324 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 "$intro$spacing${readIntroductionFile(introFileName, includeSdk)}"; | 376 "$intro$spacing${readIntroductionFile(introFileName, includeSdk)}"; |
| 376 outputToYaml = libraryMap['filetype'] == 'yaml'; | 377 outputToYaml = libraryMap['filetype'] == 'yaml'; |
| 377 } else { | 378 } else { |
| 378 libraryMap = { | 379 libraryMap = { |
| 379 'libraries' : filteredEntities.where((e) => | 380 'libraries' : filteredEntities.where((e) => |
| 380 e is Library).map((e) => e.previewMap).toList(), | 381 e is Library).map((e) => e.previewMap).toList(), |
| 381 'introduction' : readIntroductionFile(introFileName, includeSdk), | 382 'introduction' : readIntroductionFile(introFileName, includeSdk), |
| 382 'filetype' : outputToYaml ? 'yaml' : 'json' | 383 'filetype' : outputToYaml ? 'yaml' : 'json' |
| 383 }; | 384 }; |
| 384 } | 385 } |
| 386 if (startPage != null) libraryMap['startPage'] = startPage; |
| 385 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); | 387 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); |
| 386 | 388 |
| 387 // Output libraries and classes to file after all information is generated. | 389 // Output libraries and classes to file after all information is generated. |
| 388 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 390 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 389 _writeIndexableToFile(output, outputToYaml); | 391 _writeIndexableToFile(output, outputToYaml); |
| 390 }); | 392 }); |
| 391 | 393 |
| 392 // Outputs all the qualified names documented with their type. | 394 // Outputs all the qualified names documented with their type. |
| 393 // This will help generate search results. | 395 // This will help generate search results. |
| 394 _writeToFile(filteredEntities.map((e) => | 396 _writeToFile(filteredEntities.map((e) => |
| (...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1993 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 1995 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 1994 .where((e) => e != null) | 1996 .where((e) => e != null) |
| 1995 .toList(); | 1997 .toList(); |
| 1996 } | 1998 } |
| 1997 | 1999 |
| 1998 Map toMap() => { | 2000 Map toMap() => { |
| 1999 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, | 2001 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, |
| 2000 'parameters': parameters | 2002 'parameters': parameters |
| 2001 }; | 2003 }; |
| 2002 } | 2004 } |
| OLD | NEW |