Chromium Code Reviews| Index: pkg/docgen/lib/docgen.dart |
| diff --git a/pkg/docgen/lib/docgen.dart b/pkg/docgen/lib/docgen.dart |
| index 5159c05b421e89a71b489771e52f4cb81bb6a850..a90943ada1b299ab296a389aeb6604995b958dfe 100644 |
| --- a/pkg/docgen/lib/docgen.dart |
| +++ b/pkg/docgen/lib/docgen.dart |
| @@ -19,7 +19,6 @@ import 'dart:io'; |
| import 'dart:json'; |
| import 'dart:async'; |
| -import 'package:args/args.dart'; |
| import 'package:logging/logging.dart'; |
| import 'package:markdown/markdown.dart' as markdown; |
| import 'package:pathos/path.dart' as path; |
| @@ -51,47 +50,36 @@ MemberMirror _currentMember; |
| /// Resolves reference links in doc comments. |
| markdown.Resolver linkResolver; |
| -/// Package directory of directory being analyzed. |
| -String packageDir; |
| - |
| -bool outputToYaml; |
| -bool outputToJson; |
| -bool includePrivate; |
| -/// State for whether imported SDK libraries should also be outputted. |
| -bool includeSdk; |
| -/// State for whether all SDK libraries should be outputted. |
| -bool parseSdk; |
| +/// Package directory of directory being analyzed. |
| +String _packageRoot; |
|
Andrei Mouravski
2013/07/02 02:21:44
Just pass this to getMirrorSystem. That's the only
janicejl
2013/07/02 17:18:51
Done.
|
| /** |
| * Docgen constructor initializes the link resolver for markdown parsing. |
| * Also initializes the command line arguments. |
| + * |
| + * [includeSdk] represents if imported SDK libraries should be outputted. |
|
Andrei Mouravski
2013/07/02 02:21:44
That's not much of a sentence. How about:
"If [inc
janicejl
2013/07/02 17:18:51
Done.
|
| + * [parseSdk] represents if all SDK libraries should be outputted. |
| */ |
| -void docgen(ArgResults argResults) { |
| - _setCommandLineArguments(argResults); |
| +void docgen(List<String> files, {String packageRoot, |
|
Andrei Mouravski
2013/07/02 02:21:44
You can pack another parameter here.
janicejl
2013/07/02 17:18:51
Done.
|
| + bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| + bool parseSdk: false}) { |
| + if (packageRoot != null) { |
| + logger.info('Package Root: ${packageRoot}'); |
| + _packageRoot = packageRoot; |
| + } |
| linkResolver = (name) => |
| fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| - getMirrorSystem(argResults.rest).then((MirrorSystem mirrorSystem) { |
| - if (mirrorSystem.libraries.values.isEmpty) { |
| - throw new StateError('No Library Mirrors.'); |
| - } |
| - _documentLibraries(mirrorSystem.libraries.values); |
| - }); |
| -} |
| - |
| -void _setCommandLineArguments(ArgResults argResults) { |
| - outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml'; |
| - outputToJson = argResults['json'] || argResults['output-format'] == 'json'; |
| - if (outputToYaml && outputToJson) { |
| - throw new ArgumentError('Cannot have contradictory output flags.'); |
| - } |
| - outputToYaml = outputToYaml || !outputToJson; |
| - includePrivate = argResults['include-private']; |
| - parseSdk = argResults['parse-sdk']; |
| - includeSdk = parseSdk || argResults['include-sdk']; |
| - packageDir = argResults['package-root']; |
| - if (packageDir != null) logger.info('Package Root: ${packageDir}'); |
| + getMirrorSystem(files, parseSdk: parseSdk) |
|
Andrei Mouravski
2013/07/02 02:21:44
Return a future here.
Maybe it can return whether
janicejl
2013/07/02 17:18:51
Done.
|
| + .then((MirrorSystem mirrorSystem) { |
|
Andrei Mouravski
2013/07/02 02:21:44
.then should be indented only 2 spaces. It's an ex
janicejl
2013/07/02 17:18:51
Done.
|
| + if (mirrorSystem.libraries.values.isEmpty) { |
|
Andrei Mouravski
2013/07/02 02:21:44
You can probably just look at mirrorSystem.librari
janicejl
2013/07/02 17:18:51
Done.
|
| + throw new StateError('No Library Mirrors.'); |
|
Andrei Mouravski
2013/07/02 02:21:44
Better message?
janicejl
2013/07/02 17:18:51
Done.
|
| + } |
| + _documentLibraries(mirrorSystem.libraries.values, |
| + includeSdk: includeSdk, includePrivate: includePrivate, |
| + outputToYaml: outputToYaml); |
| + }); |
| } |
| List<String> _listLibraries(List<String> args) { |
| @@ -113,11 +101,13 @@ List<String> _listLibraries(List<String> args) { |
| List<String> _listDartFromDir(String args) { |
| var files = listDir(args, recursive: true); |
| - if (packageDir == null) { |
| - packageDir = files.firstWhere((f) => |
| + if (_packageRoot == null) { |
|
Andrei Mouravski
2013/07/02 02:21:44
This chunk (104-110) could probably be in it's own
janicejl
2013/07/02 17:18:51
Done.
|
| + _packageRoot = files.firstWhere((f) => |
| f.endsWith('/pubspec.yaml'), orElse: () => ''); |
| - if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; |
| - logger.info('Package Directory: $packageDir'); |
| + if (_packageRoot != '') { |
| + _packageRoot = path.dirname(_packageRoot) + '/packages'; |
| + } |
| + logger.info('Package Directory: $_packageRoot'); |
| } |
| // To avoid anaylzing package files twice, only files with paths not |
| // containing '/packages' will be added. The only exception is if the file to |
| @@ -142,7 +132,7 @@ List<String> _listSdk() { |
| * Analyzes set of libraries by getting a mirror system and triggers the |
| * documentation of the libraries. |
| */ |
| -Future<MirrorSystem> getMirrorSystem(List<String> args) { |
| +Future<MirrorSystem> getMirrorSystem(List<String> args, {bool parseSdk:false}) { |
| var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); |
| if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| // DART_SDK should be set to the root of the SDK library. |
| @@ -156,7 +146,7 @@ Future<MirrorSystem> getMirrorSystem(List<String> args) { |
| logger.info('SDK Root: ${sdkRoot}'); |
| } |
| - return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); |
| + return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: _packageRoot); |
| } |
| // TODO(janicejl): Should make docgen fail gracefully, or output a friendly |
| @@ -197,12 +187,14 @@ Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, |
| /** |
| * Creates documentation for filtered libraries. |
| */ |
| -void _documentLibraries(List<LibraryMirror> libraries) { |
| +void _documentLibraries(List<LibraryMirror> libraries, |
| + {bool includeSdk:false, bool includePrivate:false, |
|
Andrei Mouravski
2013/07/02 02:21:44
Push these arguments back so they all fit on one l
janicejl
2013/07/02 17:18:51
Done.
|
| + bool outputToYaml:true}) { |
| libraries.forEach((lib) { |
| // Files belonging to the SDK have a uri that begins with 'dart:'. |
| if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| - var library = generateLibrary(lib); |
| - _outputLibrary(library); |
| + var library = generateLibrary(lib, includePrivate: includePrivate); |
| + _outputLibrary(library, outputToYaml); |
| } |
| }); |
| // Outputs a text file with a list of files available after creating all |
| @@ -211,22 +203,24 @@ void _documentLibraries(List<LibraryMirror> libraries) { |
| _writeToFile(listDir("docs").join('\n'), 'library_list.txt'); |
| } |
| -Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { |
| +Library generateLibrary(dart2js.Dart2JsLibraryMirror library, |
| + {bool includePrivate:false}) { |
|
Andrei Mouravski
2013/07/02 02:21:44
Push argument back.
janicejl
2013/07/02 17:18:51
Done.
|
| _currentLibrary = library; |
| var result = new Library(library.qualifiedName, _getComment(library), |
| - _getVariables(library.variables), _getMethods(library.functions), |
| - _getClasses(library.classes)); |
| + _getVariables(library.variables, includePrivate), |
| + _getMethods(library.functions, includePrivate), |
| + _getClasses(library.classes, includePrivate)); |
| logger.fine('Generated library for ${result.name}'); |
| return result; |
| } |
| -void _outputLibrary(Library result) { |
| - if (outputToJson) { |
| - _writeToFile(stringify(result.toMap()), '${result.name}.json'); |
| - } |
| +void _outputLibrary(Library result, bool outputToYaml) { |
|
Andrei Mouravski
2013/07/02 02:21:44
How about _writeLibraryToFile
janicejl
2013/07/02 17:18:51
Done.
|
| if (outputToYaml) { |
| _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); |
| - } |
| + } else { |
| + _writeToFile(stringify(result.toMap()), '${result.name}.json'); |
| + } |
| + |
| } |
| /** |
| @@ -275,7 +269,8 @@ markdown.Node fixReference(String name, LibraryMirror currentLibrary, |
| /** |
| * Returns a map of [Variable] objects constructed from inputted mirrors. |
| */ |
| -Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { |
| +Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, |
| + bool includePrivate) { |
| var data = {}; |
| mirrorMap.forEach((String mirrorName, VariableMirror mirror) { |
|
Andrei Mouravski
2013/07/02 02:21:44
Can you use a filter here?
janicejl
2013/07/02 17:18:51
Will do so when there is a map to map function.
Andrei Mouravski
2013/07/02 18:30:18
Add a note in the comments about the bug I sent yo
janicejl
2013/07/02 22:06:14
Done.
|
| if (includePrivate || !mirror.isPrivate) { |
| @@ -291,7 +286,8 @@ Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { |
| /** |
| * Returns a map of [Method] objects constructed from inputted mirrors. |
| */ |
| -Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { |
| +Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap, |
| + bool includePrivate) { |
| var data = {}; |
| mirrorMap.forEach((String mirrorName, MethodMirror mirror) { |
| if (includePrivate || !mirror.isPrivate) { |
| @@ -309,7 +305,8 @@ Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { |
| /** |
| * Returns a map of [Class] objects constructed from inputted mirrors. |
| */ |
| -Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { |
| +Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, |
| + bool includePrivate) { |
| var data = {}; |
| mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
| if (includePrivate || !mirror.isPrivate) { |
| @@ -321,7 +318,8 @@ Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { |
| data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, |
| superclass, mirror.isAbstract, mirror.isTypedef, |
| _getComment(mirror), interfaces.toList(), |
| - _getVariables(mirror.variables), _getMethods(mirror.methods), |
| + _getVariables(mirror.variables, includePrivate), |
| + _getMethods(mirror.methods, includePrivate), |
| _getAnnotations(mirror)); |
| } |
| }); |