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 * |
| 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) { | |
| 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 var mirrorSystem = getMirrorSystem(files, packageRoot, parseSdk: parseSdk); |
|
Andrei Mouravski
2013/07/02 18:30:18
This isn't what I meant. I meant for docgen() to r
Andrei Mouravski
2013/07/03 07:31:19
Did you forget about this one?
Emily Fortuna
2013/07/03 16:29:40
We couldn't figure out what you meant, so I sugges
| |
| 76 if (mirrorSystem.libraries.values.isEmpty) { | 74 mirrorSystem.then((MirrorSystem mirrorSystem) { |
| 77 throw new StateError('No Library Mirrors.'); | 75 if (mirrorSystem.libraries.isEmpty) { |
| 76 throw new StateError('No Library Mirrors were created.'); | |
|
Andrei Mouravski
2013/07/02 18:30:18
Bad capitalization.
janicejl
2013/07/02 22:06:14
Done.
| |
| 78 } | 77 } |
| 79 _documentLibraries(mirrorSystem.libraries.values); | 78 _documentLibraries(mirrorSystem.libraries.values, |
| 79 includeSdk: includeSdk, includePrivate: includePrivate, | |
| 80 outputToYaml: outputToYaml); | |
| 80 }); | 81 }); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void _setCommandLineArguments(ArgResults argResults) { | |
| 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 } | |
| 96 | |
| 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 args) { | |
|
Andrei Mouravski
2013/07/02 18:30:18
Nit: You should have better parameter names than a
janicejl
2013/07/02 22:06:14
Done.
| |
| 112 var files = listDir(args, recursive: true); | |
| 113 String packageRoot = files.firstWhere((f) => | |
| 114 f.endsWith('/pubspec.yaml'), orElse: () => ''); | |
|
Andrei Mouravski
2013/07/02 18:30:18
What does it mean for this method to return ''?
janicejl
2013/07/02 22:06:14
Return '' means that there was no pubspec.yaml and
Andrei Mouravski
2013/07/03 07:31:19
Okay, well, this is kind of weird, because it's ve
| |
| 115 if (packageRoot != '') { | |
| 116 packageRoot = path.dirname(packageRoot) + '/packages'; | |
| 117 } | |
| 118 return packageRoot; | |
| 119 } | |
| 120 | |
| 130 List<String> _listSdk() { | 121 List<String> _listSdk() { |
| 131 var sdk = new List<String>(); | 122 var sdk = new List<String>(); |
| 132 LIBRARIES.forEach((String name, LibraryInfo info) { | 123 LIBRARIES.forEach((String name, LibraryInfo info) { |
| 133 if (info.documented) { | 124 if (info.documented) { |
| 134 sdk.add('dart:$name'); | 125 sdk.add('dart:$name'); |
| 135 logger.info('Add to SDK: ${sdk.last}'); | 126 logger.info('Add to SDK: ${sdk.last}'); |
| 136 } | 127 } |
| 137 }); | 128 }); |
| 138 return sdk; | 129 return sdk; |
| 139 } | 130 } |
| 140 | 131 |
| 141 /** | 132 /** |
| 142 * Analyzes set of libraries by getting a mirror system and triggers the | 133 * Analyzes set of libraries by getting a mirror system and triggers the |
| 143 * documentation of the libraries. | 134 * documentation of the libraries. |
| 144 */ | 135 */ |
| 145 Future<MirrorSystem> getMirrorSystem(List<String> args) { | 136 Future<MirrorSystem> getMirrorSystem(List<String> args, String packageRoot, |
| 137 {bool parseSdk:false}) { | |
| 146 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); | 138 var libraries = !parseSdk ? _listLibraries(args) : _listSdk(); |
| 147 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 139 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 148 // DART_SDK should be set to the root of the SDK library. | 140 // DART_SDK should be set to the root of the SDK library. |
| 149 var sdkRoot = Platform.environment['DART_SDK']; | 141 var sdkRoot = Platform.environment['DART_SDK']; |
| 150 if (sdkRoot != null) { | 142 if (sdkRoot != null) { |
| 151 logger.info('Using DART_SDK to find SDK at $sdkRoot'); | 143 logger.info('Using DART_SDK to find SDK at $sdkRoot'); |
| 152 } else { | 144 } else { |
| 153 // If DART_SDK is not defined in the environment, | 145 // If DART_SDK is not defined in the environment, |
| 154 // assuming the dart executable is from the Dart SDK folder inside bin. | 146 // assuming the dart executable is from the Dart SDK folder inside bin. |
| 155 sdkRoot = path.dirname(path.dirname(new Options().executable)); | 147 sdkRoot = path.dirname(path.dirname(new Options().executable)); |
| 156 logger.info('SDK Root: ${sdkRoot}'); | 148 logger.info('SDK Root: ${sdkRoot}'); |
| 157 } | 149 } |
| 158 | 150 |
| 159 return _getMirrorSystemHelper(libraries, sdkRoot, packageRoot: packageDir); | 151 return _analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); |
| 160 } | 152 } |
| 161 | 153 |
| 162 // TODO(janicejl): Should make docgen fail gracefully, or output a friendly | 154 // 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. | 155 // 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 | 156 // If there is conflicting library names, should modify it with a hash at the |
| 165 // end of it's library name. | 157 // end of it's library name. |
| 166 /** | 158 /** |
| 167 * Analyzes set of libraries and provides a mirror system which can be used | 159 * Analyzes set of libraries and provides a mirror system which can be used |
| 168 * for static inspection of the source code. | 160 * for static inspection of the source code. |
| 169 */ | 161 */ |
| 170 Future<MirrorSystem> _getMirrorSystemHelper(List<String> libraries, | 162 Future<MirrorSystem> _analyzeLibraries(List<String> libraries, |
| 171 String libraryRoot, {String packageRoot}) { | 163 String libraryRoot, {String packageRoot}) { |
| 172 SourceFileProvider provider = new SourceFileProvider(); | 164 SourceFileProvider provider = new SourceFileProvider(); |
| 173 api.DiagnosticHandler diagnosticHandler = | 165 api.DiagnosticHandler diagnosticHandler = |
| 174 new FormattingDiagnosticHandler(provider).diagnosticHandler; | 166 new FormattingDiagnosticHandler(provider).diagnosticHandler; |
| 175 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); | 167 Uri libraryUri = currentDirectory.resolve(appendSlash('$libraryRoot')); |
| 176 Uri packageUri = null; | 168 Uri packageUri = null; |
| 177 if (packageRoot != null) { | 169 if (packageRoot != null) { |
| 178 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); | 170 packageUri = currentDirectory.resolve(appendSlash('$packageRoot')); |
| 179 } | 171 } |
| 180 List<Uri> librariesUri = <Uri>[]; | 172 List<Uri> librariesUri = <Uri>[]; |
| 181 libraries.forEach((library) { | 173 libraries.forEach((library) { |
| 182 librariesUri.add(currentDirectory.resolve(library)); | 174 librariesUri.add(currentDirectory.resolve(library)); |
| 183 }); | 175 }); |
| 184 return dart2js.analyze(librariesUri, libraryUri, packageUri, | 176 return dart2js.analyze(librariesUri, libraryUri, packageUri, |
| 185 provider.readStringFromUri, diagnosticHandler, | 177 provider.readStringFromUri, diagnosticHandler, |
| 186 ['--preserve-comments', '--categories=Client,Server']) | 178 ['--preserve-comments', '--categories=Client,Server']) |
| 187 ..catchError((error) { | 179 ..catchError((error) { |
| 188 logger.severe('Error: Failed to create mirror system. '); | 180 logger.severe('Error: Failed to create mirror system. '); |
| 189 // TODO(janicejl): Use the stack trace package when bug is resolved. | 181 // TODO(janicejl): Use the stack trace package when bug is resolved. |
| 190 // Currently, a string is thrown when it fails to create a mirror | 182 // 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) | 183 // system, and it is not possible to use the stack trace. BUG(#11622) |
| 192 // To avoid printing the stack trace. | 184 // To avoid printing the stack trace. |
| 193 exit(1); | 185 exit(1); |
| 194 }); | 186 }); |
| 195 } | 187 } |
| 196 | 188 |
| 197 /** | 189 /** |
| 198 * Creates documentation for filtered libraries. | 190 * Creates documentation for filtered libraries. |
| 199 */ | 191 */ |
| 200 void _documentLibraries(List<LibraryMirror> libraries) { | 192 void _documentLibraries(List<LibraryMirror> libraries, |
| 193 {bool includeSdk:false, bool includePrivate:false, bool outputToYaml:true}) { | |
|
Andrei Mouravski
2013/07/02 18:30:18
Well, I guess they don't fit, since you really sho
janicejl
2013/07/02 22:06:14
Done.
| |
| 201 libraries.forEach((lib) { | 194 libraries.forEach((lib) { |
| 202 // Files belonging to the SDK have a uri that begins with 'dart:'. | 195 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 203 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 196 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 204 var library = generateLibrary(lib); | 197 var library = generateLibrary(lib, includePrivate: includePrivate); |
| 205 _outputLibrary(library); | 198 _writeLibraryToFile(library, outputToYaml); |
| 206 } | 199 } |
| 207 }); | 200 }); |
| 208 // Outputs a text file with a list of files available after creating all | 201 // 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 | 202 // the libraries. This will help the viewer know what files are available |
| 210 // to read in. | 203 // to read in. |
| 211 _writeToFile(listDir("docs").join('\n'), 'library_list.txt'); | 204 _writeToFile(listDir("docs").join('\n'), 'library_list.txt'); |
| 212 } | 205 } |
| 213 | 206 |
| 214 Library generateLibrary(dart2js.Dart2JsLibraryMirror library) { | 207 Library generateLibrary(dart2js.Dart2JsLibraryMirror library, |
| 208 {bool includePrivate:false}) { | |
| 215 _currentLibrary = library; | 209 _currentLibrary = library; |
| 216 var result = new Library(library.qualifiedName, _getComment(library), | 210 var result = new Library(library.qualifiedName, _getComment(library), |
| 217 _getVariables(library.variables), _getMethods(library.functions), | 211 _getVariables(library.variables, includePrivate), |
| 218 _getClasses(library.classes)); | 212 _getMethods(library.functions, includePrivate), |
| 213 _getClasses(library.classes, includePrivate)); | |
| 219 logger.fine('Generated library for ${result.name}'); | 214 logger.fine('Generated library for ${result.name}'); |
| 220 return result; | 215 return result; |
| 221 } | 216 } |
| 222 | 217 |
| 223 void _outputLibrary(Library result) { | 218 void _writeLibraryToFile(Library result, bool outputToYaml) { |
| 224 if (outputToJson) { | 219 if (outputToYaml) { |
| 220 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); | |
| 221 } else { | |
| 225 _writeToFile(stringify(result.toMap()), '${result.name}.json'); | 222 _writeToFile(stringify(result.toMap()), '${result.name}.json'); |
| 226 } | 223 } |
| 227 if (outputToYaml) { | 224 |
| 228 _writeToFile(getYamlString(result.toMap()), '${result.name}.yaml'); | |
| 229 } | |
| 230 } | 225 } |
| 231 | 226 |
| 232 /** | 227 /** |
| 233 * Returns a list of meta annotations assocated with a mirror. | 228 * Returns a list of meta annotations assocated with a mirror. |
| 234 */ | 229 */ |
| 235 List<String> _getAnnotations(DeclarationMirror mirror) { | 230 List<String> _getAnnotations(DeclarationMirror mirror) { |
| 236 var annotations = mirror.metadata.where((e) => | 231 var annotations = mirror.metadata.where((e) => |
| 237 e is dart2js.Dart2JsConstructedConstantMirror); | 232 e is dart2js.Dart2JsConstructedConstantMirror); |
| 238 return annotations.map((e) => e.type.qualifiedName).toList(); | 233 return annotations.map((e) => e.type.qualifiedName).toList(); |
| 239 } | 234 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 268 // TODO(tmandel): Create proper links for [_] style markdown based | 263 // TODO(tmandel): Create proper links for [_] style markdown based |
| 269 // on scope once layout of viewer is finished. | 264 // on scope once layout of viewer is finished. |
| 270 markdown.Node fixReference(String name, LibraryMirror currentLibrary, | 265 markdown.Node fixReference(String name, LibraryMirror currentLibrary, |
| 271 ClassMirror currentClass, MemberMirror currentMember) { | 266 ClassMirror currentClass, MemberMirror currentMember) { |
| 272 return new markdown.Element.text('code', name); | 267 return new markdown.Element.text('code', name); |
| 273 } | 268 } |
| 274 | 269 |
| 275 /** | 270 /** |
| 276 * Returns a map of [Variable] objects constructed from inputted mirrors. | 271 * Returns a map of [Variable] objects constructed from inputted mirrors. |
| 277 */ | 272 */ |
| 278 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap) { | 273 Map<String, Variable> _getVariables(Map<String, VariableMirror> mirrorMap, |
| 274 bool includePrivate) { | |
| 279 var data = {}; | 275 var data = {}; |
| 280 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { | 276 mirrorMap.forEach((String mirrorName, VariableMirror mirror) { |
| 281 if (includePrivate || !mirror.isPrivate) { | 277 if (includePrivate || !mirror.isPrivate) { |
| 282 _currentMember = mirror; | 278 _currentMember = mirror; |
| 283 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName, | 279 data[mirrorName] = new Variable(mirrorName, mirror.qualifiedName, |
| 284 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName, | 280 mirror.isFinal, mirror.isStatic, mirror.type.qualifiedName, |
| 285 _getComment(mirror), _getAnnotations(mirror)); | 281 _getComment(mirror), _getAnnotations(mirror)); |
| 286 } | 282 } |
| 287 }); | 283 }); |
| 288 return data; | 284 return data; |
| 289 } | 285 } |
| 290 | 286 |
| 291 /** | 287 /** |
| 292 * Returns a map of [Method] objects constructed from inputted mirrors. | 288 * Returns a map of [Method] objects constructed from inputted mirrors. |
| 293 */ | 289 */ |
| 294 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap) { | 290 Map<String, Method> _getMethods(Map<String, MethodMirror> mirrorMap, |
| 291 bool includePrivate) { | |
| 295 var data = {}; | 292 var data = {}; |
| 296 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { | 293 mirrorMap.forEach((String mirrorName, MethodMirror mirror) { |
| 297 if (includePrivate || !mirror.isPrivate) { | 294 if (includePrivate || !mirror.isPrivate) { |
| 298 _currentMember = mirror; | 295 _currentMember = mirror; |
| 299 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName, | 296 data[mirrorName] = new Method(mirrorName, mirror.qualifiedName, |
| 300 mirror.isSetter, mirror.isGetter, mirror.isConstructor, | 297 mirror.isSetter, mirror.isGetter, mirror.isConstructor, |
| 301 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName, | 298 mirror.isOperator, mirror.isStatic, mirror.returnType.qualifiedName, |
| 302 _getComment(mirror), _getParameters(mirror.parameters), | 299 _getComment(mirror), _getParameters(mirror.parameters), |
| 303 _getAnnotations(mirror)); | 300 _getAnnotations(mirror)); |
| 304 } | 301 } |
| 305 }); | 302 }); |
| 306 return data; | 303 return data; |
| 307 } | 304 } |
| 308 | 305 |
| 309 /** | 306 /** |
| 310 * Returns a map of [Class] objects constructed from inputted mirrors. | 307 * Returns a map of [Class] objects constructed from inputted mirrors. |
| 311 */ | 308 */ |
| 312 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap) { | 309 Map<String, Class> _getClasses(Map<String, ClassMirror> mirrorMap, |
| 310 bool includePrivate) { | |
| 313 var data = {}; | 311 var data = {}; |
| 314 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { | 312 mirrorMap.forEach((String mirrorName, ClassMirror mirror) { |
| 315 if (includePrivate || !mirror.isPrivate) { | 313 if (includePrivate || !mirror.isPrivate) { |
| 316 _currentClass = mirror; | 314 _currentClass = mirror; |
| 317 var superclass = (mirror.superclass != null) ? | 315 var superclass = (mirror.superclass != null) ? |
| 318 mirror.superclass.qualifiedName : ''; | 316 mirror.superclass.qualifiedName : ''; |
| 319 var interfaces = | 317 var interfaces = |
| 320 mirror.superinterfaces.map((interface) => interface.qualifiedName); | 318 mirror.superinterfaces.map((interface) => interface.qualifiedName); |
| 321 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, | 319 data[mirrorName] = new Class(mirrorName, mirror.qualifiedName, |
| 322 superclass, mirror.isAbstract, mirror.isTypedef, | 320 superclass, mirror.isAbstract, mirror.isTypedef, |
| 323 _getComment(mirror), interfaces.toList(), | 321 _getComment(mirror), interfaces.toList(), |
| 324 _getVariables(mirror.variables), _getMethods(mirror.methods), | 322 _getVariables(mirror.variables, includePrivate), |
| 323 _getMethods(mirror.methods, includePrivate), | |
| 325 _getAnnotations(mirror)); | 324 _getAnnotations(mirror)); |
| 326 } | 325 } |
| 327 }); | 326 }); |
| 328 return data; | 327 return data; |
| 329 } | 328 } |
| 330 | 329 |
| 331 /** | 330 /** |
| 332 * Returns a map of [Parameter] objects constructed from inputted mirrors. | 331 * Returns a map of [Parameter] objects constructed from inputted mirrors. |
| 333 */ | 332 */ |
| 334 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { | 333 Map<String, Parameter> _getParameters(List<ParameterMirror> mirrorList) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 parameterMap['qualifiedname'] = qualifiedName; | 554 parameterMap['qualifiedname'] = qualifiedName; |
| 556 parameterMap['optional'] = isOptional.toString(); | 555 parameterMap['optional'] = isOptional.toString(); |
| 557 parameterMap['named'] = isNamed.toString(); | 556 parameterMap['named'] = isNamed.toString(); |
| 558 parameterMap['default'] = hasDefaultValue.toString(); | 557 parameterMap['default'] = hasDefaultValue.toString(); |
| 559 parameterMap['type'] = type; | 558 parameterMap['type'] = type; |
| 560 parameterMap['value'] = defaultValue; | 559 parameterMap['value'] = defaultValue; |
| 561 parameterMap['annotations'] = new List.from(annotations); | 560 parameterMap['annotations'] = new List.from(annotations); |
| 562 return parameterMap; | 561 return parameterMap; |
| 563 } | 562 } |
| 564 } | 563 } |
| OLD | NEW |