| 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 * |
| 11 * $ dart docgen.dart [OPTIONS] [FILE/DIR] | 11 * $ dart docgen.dart [OPTIONS] [FILE/DIR] |
| 12 * | 12 * |
| 13 * This creates files called `docs/<library_name>.yaml` in your current | 13 * This creates files called `docs/<library_name>.yaml` in your current |
| 14 * working directory. | 14 * working directory. |
| 15 */ | 15 */ |
| 16 library docgen; | 16 library docgen; |
| 17 | 17 |
| 18 import 'dart:io'; | 18 import 'dart:io'; |
| 19 import 'dart:json'; | 19 import 'dart:json'; |
| 20 import 'dart:async'; | 20 import 'dart:async'; |
| 21 | 21 |
| 22 import 'package:args/args.dart'; | |
| 23 import 'package:logging/logging.dart'; | 22 import 'package:logging/logging.dart'; |
| 24 import 'package:markdown/markdown.dart' as markdown; | 23 import 'package:markdown/markdown.dart' as markdown; |
| 25 import 'package:pathos/path.dart' as path; | 24 import 'package:pathos/path.dart' as path; |
| 26 | 25 |
| 27 import 'dart2yaml.dart'; | 26 import 'dart2yaml.dart'; |
| 28 import 'src/io.dart'; | 27 import 'src/io.dart'; |
| 29 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 28 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 30 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 29 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 31 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
r.dart' | 30 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
r.dart' |
| 32 as dart2js; | 31 as dart2js; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 44 | 43 |
| 45 /// Current class being documented to be used for comment links. | 44 /// Current class being documented to be used for comment links. |
| 46 ClassMirror _currentClass; | 45 ClassMirror _currentClass; |
| 47 | 46 |
| 48 /// Current member being documented to be used for comment links. | 47 /// Current member being documented to be used for comment links. |
| 49 MemberMirror _currentMember; | 48 MemberMirror _currentMember; |
| 50 | 49 |
| 51 /// Resolves reference links in doc comments. | 50 /// Resolves reference links in doc comments. |
| 52 markdown.Resolver linkResolver; | 51 markdown.Resolver linkResolver; |
| 53 | 52 |
| 54 /// Package directory of directory being analyzed. | |
| 55 String packageDir; | |
| 56 | |
| 57 bool outputToYaml; | |
| 58 bool outputToJson; | |
| 59 bool includePrivate; | |
| 60 /// State for whether imported SDK libraries should also be outputted. | |
| 61 bool includeSdk; | |
| 62 /// State for whether all SDK libraries should be outputted. | |
| 63 bool parseSdk; | |
| 64 | |
| 65 /** | 53 /** |
| 66 * Docgen constructor initializes the link resolver for markdown parsing. | 54 * Docgen constructor initializes the link resolver for markdown parsing. |
| 67 * Also initializes the command line arguments. | 55 * Also initializes the command line arguments. |
| 56 * |
| 57 * [packageRoot] is the packages directory of the directory being analyzed. |
| 58 * If [includeSdk] is 'true', then any SDK libraries explicitly imported will |
| 59 * also be documented. |
| 60 * If [parseSdk] is 'true', then all Dart SDK libraries will be documented. |
| 61 * This option is useful when only the SDK libraries are needed. |
| 68 */ | 62 */ |
| 69 void docgen(ArgResults argResults) { | 63 void docgen(List<String> files, {String packageRoot, bool outputToYaml: true, |
| 70 _setCommandLineArguments(argResults); | 64 bool includePrivate: false, bool includeSdk: false, bool parseSdk: false}) { |
| 65 if (packageRoot == null && !parseSdk) { |
| 66 packageRoot = _findPackageRoot(files.first); |
| 67 } |
| 68 logger.info('Package Root: ${packageRoot}'); |
| 71 | 69 |
| 72 linkResolver = (name) => | 70 linkResolver = (name) => |
| 73 fixReference(name, _currentLibrary, _currentClass, _currentMember); | 71 fixReference(name, _currentLibrary, _currentClass, _currentMember); |
| 74 | 72 |
| 75 getMirrorSystem(argResults.rest).then((MirrorSystem mirrorSystem) { | 73 getMirrorSystem(files, packageRoot, parseSdk: parseSdk) |
| 76 if (mirrorSystem.libraries.values.isEmpty) { | 74 .then((MirrorSystem mirrorSystem) { |
| 77 throw new StateError('No Library Mirrors.'); | 75 if (mirrorSystem.libraries.isEmpty) { |
| 78 } | 76 throw new StateError('No library mirrors were created.'); |
| 79 _documentLibraries(mirrorSystem.libraries.values); | 77 } |
| 80 }); | 78 _documentLibraries(mirrorSystem.libraries.values, |
| 81 } | 79 includeSdk: includeSdk, includePrivate: includePrivate, |
| 82 | 80 outputToYaml: outputToYaml); |
| 83 void _setCommandLineArguments(ArgResults argResults) { | 81 }); |
| 84 outputToYaml = argResults['yaml'] || argResults['output-format'] == 'yaml'; | |
| 85 outputToJson = argResults['json'] || argResults['output-format'] == 'json'; | |
| 86 if (outputToYaml && outputToJson) { | |
| 87 throw new ArgumentError('Cannot have contradictory output flags.'); | |
| 88 } | |
| 89 outputToYaml = outputToYaml || !outputToJson; | |
| 90 includePrivate = argResults['include-private']; | |
| 91 parseSdk = argResults['parse-sdk']; | |
| 92 includeSdk = parseSdk || argResults['include-sdk']; | |
| 93 packageDir = argResults['package-root']; | |
| 94 if (packageDir != null) logger.info('Package Root: ${packageDir}'); | |
| 95 } | 82 } |
| 96 | 83 |
| 97 List<String> _listLibraries(List<String> args) { | 84 List<String> _listLibraries(List<String> args) { |
| 98 // TODO(janicejl): At the moment, only have support to have either one file, | 85 // TODO(janicejl): At the moment, only have support to have either one file, |
| 99 // or one directory. This is because there can only be one package directory | 86 // or one directory. This is because there can only be one package directory |
| 100 // since only one docgen is created per run. | 87 // since only one docgen is created per run. |
| 101 if (args.length != 1) throw new UnsupportedError(USAGE); | 88 if (args.length != 1) throw new UnsupportedError(USAGE); |
| 102 var libraries = new List<String>(); | 89 var libraries = new List<String>(); |
| 103 var type = FileSystemEntity.typeSync(args[0]); | 90 var type = FileSystemEntity.typeSync(args[0]); |
| 104 | 91 |
| 105 if (type == FileSystemEntityType.FILE) { | 92 if (type == FileSystemEntityType.FILE) { |
| 106 libraries.add(path.absolute(args[0])); | 93 libraries.add(path.absolute(args[0])); |
| 107 logger.info('Added to libraries: ${libraries.last}'); | 94 logger.info('Added to libraries: ${libraries.last}'); |
| 108 } else { | 95 } else { |
| 109 libraries.addAll(_listDartFromDir(args[0])); | 96 libraries.addAll(_listDartFromDir(args[0])); |
| 110 } | 97 } |
| 111 return libraries; | 98 return libraries; |
| 112 } | 99 } |
| 113 | 100 |
| 114 List<String> _listDartFromDir(String args) { | 101 List<String> _listDartFromDir(String args) { |
| 115 var files = listDir(args, recursive: true); | 102 var files = listDir(args, recursive: true); |
| 116 if (packageDir == null) { | |
| 117 packageDir = files.firstWhere((f) => | |
| 118 f.endsWith('/pubspec.yaml'), orElse: () => ''); | |
| 119 if (packageDir != '') packageDir = path.dirname(packageDir) + '/packages'; | |
| 120 logger.info('Package Directory: $packageDir'); | |
| 121 } | |
| 122 // To avoid anaylzing package files twice, only files with paths not | 103 // To avoid anaylzing package files twice, only files with paths not |
| 123 // containing '/packages' will be added. The only exception is if the file to | 104 // containing '/packages' will be added. The only exception is if the file to |
| 124 // analyze already has a '/package' in its path. | 105 // analyze already has a '/package' in its path. |
| 125 return files.where((f) => f.endsWith('.dart') && | 106 return files.where((f) => f.endsWith('.dart') && |
| 126 (!f.contains('/packages') || args.contains('/packages'))).toList() | 107 (!f.contains('/packages') || args.contains('/packages'))).toList() |
| 127 ..forEach((lib) => logger.info('Added to libraries: $lib')); | 108 ..forEach((lib) => logger.info('Added to libraries: $lib')); |
| 128 } | 109 } |
| 129 | 110 |
| 111 String _findPackageRoot(String directory) { |
| 112 var files = listDir(directory, recursive: true); |
| 113 // Return '' means that there was no pubspec.yaml and therefor no packageRoot.
|
| 114 String packageRoot = files.firstWhere((f) => |
| 115 f.endsWith('/pubspec.yaml'), orElse: () => ''); |
| 116 if (packageRoot != '') { |
| 117 packageRoot = path.dirname(packageRoot) + '/packages'; |
| 118 } |
| 119 return packageRoot; |
| 120 } |
| 121 |
| 130 List<String> _listSdk() { | 122 List<String> _listSdk() { |
| 131 var sdk = new List<String>(); | 123 var sdk = new List<String>(); |
| 132 LIBRARIES.forEach((String name, LibraryInfo info) { | 124 LIBRARIES.forEach((String name, LibraryInfo info) { |
| 133 if (info.documented) { | 125 if (info.documented) { |
| 134 sdk.add('dart:$name'); | 126 sdk.add('dart:$name'); |
| 135 logger.info('Add to SDK: ${sdk.last}'); | 127 logger.info('Add to SDK: ${sdk.last}'); |
| 136 } | 128 } |
| 137 }); | 129 }); |
| 138 return sdk; | 130 return sdk; |
| 139 } | 131 } |
| 140 | 132 |
| 141 /** | 133 /** |
| 142 * Analyzes set of libraries by getting a mirror system and triggers the | 134 * Analyzes set of libraries by getting a mirror system and triggers the |
| 143 * documentation of the libraries. | 135 * documentation of the libraries. |
| 144 */ | 136 */ |
| 145 Future<MirrorSystem> getMirrorSystem(List<String> args) { | 137 Future<MirrorSystem> getMirrorSystem(List<String> args, String packageRoot, |
| 138 {bool parseSdk:false}) { |
| 146 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); | 139 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); |
| 147 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 140 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 148 // DART_SDK should be set to the root of the SDK library. | 141 // DART_SDK should be set to the root of the SDK library. |
| 149 var sdkRoot = Platform.environment['DART_SDK']; | 142 var sdkRoot = Platform.environment['DART_SDK']; |
| 150 if (sdkRoot != null) { | 143 if (sdkRoot != null) { |
| 151 logger.info('Using DART_SDK to find SDK at $sdkRoot'); | 144 logger.info('Using DART_SDK to find SDK at $sdkRoot'); |
| 152 } else { | 145 } else { |
| 153 // If DART_SDK is not defined in the environment, | 146 // If DART_SDK is not defined in the environment, |
| 154 // assuming the dart executable is from the Dart SDK folder inside bin. | 147 // assuming the dart executable is from the Dart SDK folder inside bin. |
| 155 sdkRoot = path.dirname(path.dirname(new Options().executable)); | 148 sdkRoot = path.dirname(path.dirname(new Options().executable)); |
| 156 logger.info('SDK Root: ${sdkRoot}'); | 149 logger.info('SDK Root: ${sdkRoot}'); |
| 157 } | 150 } |
| 158 | 151 |
| 159 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); | 152 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); |
| 160 } | 153 } |
| 161 | 154 |
| 162 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly | 155 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly |
| 163 // error message letting them know why it is failing to create a mirror system. | 156 // error message letting them know why it is failing to create a mirror system. |
| 164 // If there is conflicting library names, should modify it with a hash at the | 157 // If there is conflicting library names, should modify it with a hash at the |
| 165 // end of it's library name. | 158 // end of it's library name. |
| 166 /** | 159 /** |
| 167 * Analyzes set of libraries and provides a mirror system which can be used | 160 * Analyzes set of libraries and provides a mirror system which can be used |
| 168 * for static inspection of the source code. | 161 * for static inspection of the source code. |
| 169 */ | 162 */ |
| 170 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, | 163 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, |
| 171 String libraryRoot, {String packageRoot}) { | 164 String libraryRoot, {String packageRoot}) { |
| 172 SourceFileProvider provider = new SourceFileProvider(); | 165 SourceFileProvider provider = new SourceFileProvider(); |
| 173 api.DiagnosticHandler diagnosticHandler = | 166 api.DiagnosticHandler diagnosticHandler = |
| 174 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 167 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
| 175 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); | 168 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); |
| 176 Uri packageUri = null; | 169 Uri packageUri = null; |
| 177 if (packageRoot != null) { | 170 if (packageRoot != null) { |
| 178 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); | 171 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); |
| 179 } | 172 } |
| 180 List<Uri> librariesUri = <Uri>[]; | 173 List<Uri> librariesUri = <Uri>[]; |
| 181 libraries.forEach((library) { | 174 libraries.forEach((library) { |
| 182 librariesUri.add(currentDirectory.resolve(library)); | 175 librariesUri.add(currentDirectory.resolve(library)); |
| 183 }); | 176 }); |
| 184 return dart2js.analyze(librariesUri, libraryUri, packageUri, | 177 return dart2js.analyze(librariesUri, libraryUri, packageUri, |
| 185 provider.readStringFromUri, diagnosticHandler, | 178 provider.readStringFromUri, diagnosticHandler, |
| 186 ['--preserve-comments', '--categories=Client,Server']) | 179 ['--preserve-comments', '--categories=Client,Server']) |
| 187 ..catchError((error) { | 180 ..catchError((error) { |
| 188 logger.severe('Error: Failed to create mirror system. '); | 181 logger.severe('Error: Failed to create mirror system. '); |
| 189 // TODO(janicejl): Use the stack trace package when bug is resolved. | 182 // TODO(janicejl): Use the stack trace package when bug is resolved. |
| 190 // Currently, a string is thrown when it fails to create a mirror | 183 // Currently, a string is thrown when it fails to create a mirror |
| 191 // system, and it is not possible to use the stack trace. BUG(#11622) | 184 // system, and it is not possible to use the stack trace. BUG(#11622) |
| 192 // To avoid printing the stack trace. | 185 // To avoid printing the stack trace. |
| 193 exit(1); | 186 exit(1); |
| 194 }); | 187 }); |
| 195 } | 188 } |
| 196 | 189 |
| 197 /** | 190 /** |
| 198 * Creates documentation for filtered libraries. | 191 * Creates documentation for filtered libraries. |
| 199 */ | 192 */ |
| 200 void _documentLibraries(List<LibraryMirror> libraries) { | 193 void _documentLibraries(List<LibraryMirror> libraries, |
| 194 {bool includeSdk:false, bool includePrivate:false, bool |
| 195 outputToYaml:true}) { |
| 201 libraries.forEach((lib) { | 196 libraries.forEach((lib) { |
| 202 // Files belonging to the SDK have a uri that begins with 'dart:'. | 197 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 203 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 198 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 204 var library = generateLibrary(lib); | 199 var library = generateLibrary(lib, includePrivate: includePrivate); |
| 205 _outputLibrary(library); | 200 _writeLibraryToFile(library, outputToYaml); |
| 206 } | 201 } |
| 207 }); | 202 }); |
| 208 // Outputs a text file with a list of files available after creating all | 203 // 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 | 204 // the libraries. This will help the viewer know what files are available |
| 210 // to read in. | 205 // to read in. |
| 211 _writeToFile(listDir("docs").join('\n'), 'library_list.txt'); | 206 _writeToFile(listDir("docs").join('\n'), 'library_list.txt'); |
| 212 } | 207 } |
| 213 | 208 |
| 214 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 209 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, |
| 210 {bool includePrivate:false}) { |
| 215 _currentLibrary = library; | 211 _currentLibrary = library; |
| 216 var result = new Library(library.qualifiedName, _getComment(library), | 212 var result = new Library(library.qualifiedName, _getComment(library), |
| 217 _getVariables(library.variables), _getMethods(library.functions), | 213 _getVariables(library.variables, includePrivate), |
| 218 _getClasses(library.classes)); | 214 _getMethods(library.functions, includePrivate), |
| 215 _getClasses(library.classes, includePrivate)); |
| 219 logger.fine('Generated library for ${result.name}'); | 216 logger.fine('Generated library for ${result.name}'); |
| 220 return result; | 217 return result; |
| 221 } | 218 } |
| 222 | 219 |
| 223 void _outputLibrary(Library result) { | 220 void _writeLibraryToFile(Library result, bool outputToYaml) { |
| 224 if (outputToJson) { | 221 if (outputToYaml) { |
| 222 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); |
| 223 } else { |
| 225 _writeToFile(stringify(result.toMap()), '${result.name}.json'); | 224 _writeToFile(stringify(result.toMap()), '${result.name}.json'); |
| 226 } | 225 } |
| 227 if (outputToYaml) { | 226 |
| 228 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); | |
| 229 } | |
| 230 } | 227 } |
| 231 | 228 |
| 232 /** | 229 /** |
| 233 * Returns a list of meta annotations assocated with a mirror. | 230 * Returns a list of meta annotations assocated with a mirror. |
| 234 */ | 231 */ |
| 235 List<String> _getAnnotations(DeclarationMirror mirror) { | 232 List<String> _getAnnotations(DeclarationMirror mirror) { |
| 236 var annotations = mirror.metadata.where((e) => | 233 var annotations = mirror.metadata.where((e) => |
| 237 e is dart2js.Dart2JsConstructedConstantMirror); | 234 e is dart2js.Dart2JsConstructedConstantMirror); |
| 238 return annotations.map((e) => e.type.qualifiedName).toList(); | 235 return annotations.map((e) => e.type.qualifiedName).toList(); |
| 239 } | 236 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 268 // TODO(tmandel): Create proper links for [_] style markdown based | 265 // TODO(tmandel): Create proper links for [_] style markdown based |
| 269 // on scope once layout of viewer is finished. | 266 // on scope once layout of viewer is finished. |
| 270 markdown.Node fixReference(String name, LibraryMirror currentLibrary, | 267 markdown.Node fixReference(String name, LibraryMirror currentLibrary, |
| 271 ClassMirror currentClass, MemberMirror currentMember) { | 268 ClassMirror currentClass, MemberMirror currentMember) { |
| 272 return new markdown.Element.text('code', name); | 269 return new markdown.Element.text('code', name); |
| 273 } | 270 } |
| 274 | 271 |
| 275 /** | 272 /** |
| 276 * Returns a map of [Variable] objects constructed from inputted mirrors. | 273 * Returns a map of [Variable] objects constructed from inputted mirrors. |
| 277 */ | 274 */ |
| 278 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { | 275 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, |
| 276 bool includePrivate) { |
| 279 var data = {}; | 277 var data = {}; |
| 278 // TODO(janicejl): When map to map feature is created, replace the below with |
| 279 // a filter. Issue(#9590). |
| 280 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { | 280 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { |
| 281 if (includePrivate || !mirror.isPrivate) { | 281 if (includePrivate || !mirror.isPrivate) { |
| 282 _currentMember = mirror; | 282 _currentMember = mirror; |
| 283 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName, | 283 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName, |
| 284 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName, | 284 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName, |
| 285 _getComment(mirror), _getAnnotations(mirror)); | 285 _getComment(mirror), _getAnnotations(mirror)); |
| 286 } | 286 } |
| 287 }); | 287 }); |
| 288 return data; | 288 return data; |
| 289 } | 289 } |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * Returns a map of [Method] objects constructed from inputted mirrors. | 292 * Returns a map of [Method] objects constructed from inputted mirrors. |
| 293 */ | 293 */ |
| 294 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { | 294 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap, |
| 295 bool includePrivate) { |
| 295 var data = {}; | 296 var data = {}; |
| 296 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { | 297 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { |
| 297 if (includePrivate || !mirror.isPrivate) { | 298 if (includePrivate || !mirror.isPrivate) { |
| 298 _currentMember = mirror; | 299 _currentMember = mirror; |
| 299 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName, | 300 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName, |
| 300 mirror.isSetter, mirror.isGetter, mirror.isConstructor, | 301 mirror.isSetter, mirror.isGetter, mirror.isConstructor, |
| 301 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName, | 302 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName, |
| 302 _getComment(mirror), _getParameters(mirror.parameters), | 303 _getComment(mirror), _getParameters(mirror.parameters), |
| 303 _getAnnotations(mirror)); | 304 _getAnnotations(mirror)); |
| 304 } | 305 } |
| 305 }); | 306 }); |
| 306 return data; | 307 return data; |
| 307 } | 308 } |
| 308 | 309 |
| 309 /** | 310 /** |
| 310 * Returns a map of [Class] objects constructed from inputted mirrors. | 311 * Returns a map of [Class] objects constructed from inputted mirrors. |
| 311 */ | 312 */ |
| 312 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { | 313 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, |
| 314 bool includePrivate) { |
| 313 var data = {}; | 315 var data = {}; |
| 314 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { | 316 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
| 315 if (includePrivate || !mirror.isPrivate) { | 317 if (includePrivate || !mirror.isPrivate) { |
| 316 _currentClass = mirror; | 318 _currentClass = mirror; |
| 317 var superclass = (mirror.superclass != null) ? | 319 var superclass = (mirror.superclass != null) ? |
| 318 mirror.superclass.qualifiedName : ''; | 320 mirror.superclass.qualifiedName : ''; |
| 319 var interfaces = | 321 var interfaces = |
| 320 mirror.superinterfaces.map((interface) => interface.qualifiedName); | 322 mirror.superinterfaces.map((interface) => interface.qualifiedName); |
| 321 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, | 323 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, |
| 322 superclass, mirror.isAbstract, mirror.isTypedef, | 324 superclass, mirror.isAbstract, mirror.isTypedef, |
| 323 _getComment(mirror), interfaces.toList(), | 325 _getComment(mirror), interfaces.toList(), |
| 324 _getVariables(mirror.variables), _getMethods(mirror.methods), | 326 _getVariables(mirror.variables, includePrivate), |
| 327 _getMethods(mirror.methods, includePrivate), |
| 325 _getAnnotations(mirror)); | 328 _getAnnotations(mirror)); |
| 326 } | 329 } |
| 327 }); | 330 }); |
| 328 return data; | 331 return data; |
| 329 } | 332 } |
| 330 | 333 |
| 331 /** | 334 /** |
| 332 * Returns a map of [Parameter] objects constructed from inputted mirrors. | 335 * Returns a map of [Parameter] objects constructed from inputted mirrors. |
| 333 */ | 336 */ |
| 334 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { | 337 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 parameterMap['qualifiedname'] = qualifiedName; | 558 parameterMap['qualifiedname'] = qualifiedName; |
| 556 parameterMap['optional'] = isOptional.toString(); | 559 parameterMap['optional'] = isOptional.toString(); |
| 557 parameterMap['named'] = isNamed.toString(); | 560 parameterMap['named'] = isNamed.toString(); |
| 558 parameterMap['default'] = hasDefaultValue.toString(); | 561 parameterMap['default'] = hasDefaultValue.toString(); |
| 559 parameterMap['type'] = type; | 562 parameterMap['type'] = type; |
| 560 parameterMap['value'] = defaultValue; | 563 parameterMap['value'] = defaultValue; |
| 561 parameterMap['annotations'] = new List.from(annotations); | 564 parameterMap['annotations'] = new List.from(annotations); |
| 562 return parameterMap; | 565 return parameterMap; |
| 563 } | 566 } |
| 564 } | 567 } |
| OLD | NEW |