| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 /// Annotations that we do not display in the viewer. | 39 /// Annotations that we do not display in the viewer. |
| 40 const List<String> _SKIPPED_ANNOTATIONS = const [ | 40 const List<String> _SKIPPED_ANNOTATIONS = const [ |
| 41 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates', | 41 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates', |
| 42 '_js_helper.Returns']; | 42 '_js_helper.Returns']; |
| 43 | 43 |
| 44 /// Support for [:foo:]-style code comments to the markdown parser. | 44 /// Support for [:foo:]-style code comments to the markdown parser. |
| 45 List<markdown.InlineSyntax> _MARKDOWN_SYNTAXES = | 45 List<markdown.InlineSyntax> _MARKDOWN_SYNTAXES = |
| 46 [new markdown.CodeSyntax(r'\[:\s?((?:.|\n)*?)\s?:\]')]; | 46 [new markdown.CodeSyntax(r'\[:\s?((?:.|\n)*?)\s?:\]')]; |
| 47 | 47 |
| 48 /// If we can't find the SDK introduction text, which will happen if running |
| 49 /// from a snapshot and using --parse-sdk or --include-sdk, then use this |
| 50 /// hard-coded version. This should be updated to be consistent with the text |
| 51 /// in docgen/doc/sdk-introduction.md |
| 52 const DEFAULT_SDK_INTRODUCTION = """ |
| 53 Welcome to the Dart API reference documentation, |
| 54 covering the official Dart API libraries. |
| 55 Some of the most fundamental Dart libraries include: |
| 56 |
| 57 * [dart:core](#dart:core): |
| 58 Core functionality such as strings, numbers, collections, errors, |
| 59 dates, and URIs. |
| 60 * [dart:html](#dart:html): |
| 61 DOM manipulation for web apps. |
| 62 * [dart:io](#dart:io): |
| 63 I/O for command-line apps. |
| 64 |
| 65 Except for dart:core, you must import a library before you can use it. |
| 66 Here's an example of importing dart:html, dart:math, and a |
| 67 third popular library called |
| 68 [polymer.dart](http://www.dartlang.org/polymer-dart/): |
| 69 |
| 70 import 'dart:html'; |
| 71 import 'dart:math'; |
| 72 import 'package:polymer/polymer.dart'; |
| 73 |
| 74 Polymer.dart is an example of a library that isn't |
| 75 included in the Dart download, |
| 76 but is easy to get and update using the _pub package manager_. |
| 77 For information on finding, using, and publishing libraries (and more) |
| 78 with pub, see |
| 79 [pub.dartlang.org](http://pub.dartlang.org). |
| 80 |
| 81 The main site for learning and using Dart is |
| 82 [www.dartlang.org](http://www.dartlang.org). |
| 83 Check out these pages: |
| 84 |
| 85 * [Dart homepage](http://www.dartlang.org) |
| 86 * [Tutorials](http://www.dartlang.org/docs/tutorials/) |
| 87 * [Programmer's Guide](http://www.dartlang.org/docs/) |
| 88 * [Samples](http://www.dartlang.org/samples/) |
| 89 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn |
| 90 ing/contents/ch03.html) |
| 91 |
| 92 This API reference is automatically generated from the source code in the |
| 93 [Dart project](https://code.google.com/p/dart/). |
| 94 If you'd like to contribute to this documentation, see |
| 95 [Contributing](https://code.google.com/p/dart/wiki/Contributing) |
| 96 and |
| 97 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume |
| 98 ntation). |
| 99 """; |
| 100 |
| 48 // TODO(efortuna): The use of this field is odd (this is based on how it was | 101 // TODO(efortuna): The use of this field is odd (this is based on how it was |
| 49 // originally used. Try to cleanup. | 102 // originally used. Try to cleanup. |
| 50 /// Index of all indexable items. This also ensures that no class is | 103 /// Index of all indexable items. This also ensures that no class is |
| 51 /// created more than once. | 104 /// created more than once. |
| 52 Map<String, Indexable> entityMap = new Map<String, Indexable>(); | 105 Map<String, Indexable> entityMap = new Map<String, Indexable>(); |
| 53 | 106 |
| 54 /// Index of all the dart2js mirrors examined to corresponding MirrorBased | 107 /// Index of all the dart2js mirrors examined to corresponding MirrorBased |
| 55 /// docgen objects. | 108 /// docgen objects. |
| 56 /// | 109 /// |
| 57 /// Used for lookup because of the dart2js mirrors exports | 110 /// Used for lookup because of the dart2js mirrors exports |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (mirrorOwner == null) return mirror.qualifiedName; | 183 if (mirrorOwner == null) return mirror.qualifiedName; |
| 131 var simpleName = mirror.simpleName; | 184 var simpleName = mirror.simpleName; |
| 132 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { | 185 if (mirror is MethodMirror && (mirror as MethodMirror).isConstructor) { |
| 133 // We name constructors specially -- including the class name again and a | 186 // We name constructors specially -- including the class name again and a |
| 134 // "-" to separate the constructor from its name (if any). | 187 // "-" to separate the constructor from its name (if any). |
| 135 simpleName = '${mirrorOwner.simpleName}-$simpleName'; | 188 simpleName = '${mirrorOwner.simpleName}-$simpleName'; |
| 136 } | 189 } |
| 137 return getDocgenObject(mirrorOwner, owner).docName + '.' + simpleName; | 190 return getDocgenObject(mirrorOwner, owner).docName + '.' + simpleName; |
| 138 } | 191 } |
| 139 List<Annotation> _createAnnotations(DeclarationMirror mirror, | 192 List<Annotation> _createAnnotations(DeclarationMirror mirror, |
| 140 MirrorBased owner) => null; | 193 Library owningLibrary) => null; |
| 141 | 194 |
| 142 bool get isPrivate => mirror == null? false : mirror.isPrivate; | 195 bool get isPrivate => mirror == null? false : mirror.isPrivate; |
| 143 } | 196 } |
| 144 | 197 |
| 145 abstract class MirrorBased { | 198 abstract class MirrorBased { |
| 146 DeclarationMirror get mirror; | 199 DeclarationMirror get mirror; |
| 147 MirrorBased owner; | 200 MirrorBased owner; |
| 148 | 201 |
| 149 /// Returns this object's qualified name, but following the conventions | 202 /// Returns this object's qualified name, but following the conventions |
| 150 /// we're using in Dartdoc, which is that library names with dots in them | 203 /// we're using in Dartdoc, which is that library names with dots in them |
| 151 /// have them replaced with hyphens. | 204 /// have them replaced with hyphens. |
| 152 String get docName => owner.docName + '.' + mirror.simpleName; | 205 String get docName => owner.docName + '.' + mirror.simpleName; |
| 153 | 206 |
| 154 /// Returns a list of meta annotations assocated with a mirror. | 207 /// Returns a list of meta annotations assocated with a mirror. |
| 155 List<Annotation> _createAnnotations(DeclarationMirror mirror, | 208 List<Annotation> _createAnnotations(DeclarationMirror mirror, |
| 156 MirrorBased owner) { | 209 Library owningLibrary) { |
| 157 var annotationMirrors = mirror.metadata.where((e) => | 210 var annotationMirrors = mirror.metadata.where((e) => |
| 158 e is dart2js.Dart2JsConstructedConstantMirror); | 211 e is dart2js.Dart2JsConstructedConstantMirror); |
| 159 var annotations = []; | 212 var annotations = []; |
| 160 annotationMirrors.forEach((annotation) { | 213 annotationMirrors.forEach((annotation) { |
| 161 var docgenAnnotation = new Annotation(annotation, owner); | 214 var docgenAnnotation = new Annotation(annotation, owningLibrary); |
| 162 if (!_SKIPPED_ANNOTATIONS.contains( | 215 if (!_SKIPPED_ANNOTATIONS.contains( |
| 163 docgenAnnotation.mirror.qualifiedName)) { | 216 docgenAnnotation.mirror.qualifiedName)) { |
| 164 annotations.add(docgenAnnotation); | 217 annotations.add(docgenAnnotation); |
| 165 } | 218 } |
| 166 }); | 219 }); |
| 167 return annotations; | 220 return annotations; |
| 168 } | 221 } |
| 169 | 222 |
| 170 bool get isPrivate => false; | 223 bool get isPrivate => false; |
| 171 } | 224 } |
| 172 | 225 |
| 173 /// Docgen constructor initializes the link resolver for markdown parsing. | 226 /// Docgen constructor initializes the link resolver for markdown parsing. |
| 174 /// Also initializes the command line arguments. | 227 /// Also initializes the command line arguments. |
| 175 /// | 228 /// |
| 176 /// [packageRoot] is the packages directory of the directory being analyzed. | 229 /// [packageRoot] is the packages directory of the directory being analyzed. |
| 177 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 230 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 178 /// also be documented. | 231 /// also be documented. |
| 179 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 232 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 180 /// This option is useful when only the SDK libraries are needed. | 233 /// This option is useful when only the SDK libraries are needed. |
| 181 /// | 234 /// |
| 182 /// Returned Future completes with true if document generation is successful. | 235 /// Returned Future completes with true if document generation is successful. |
| 183 Future<bool> docgen(List<String> files, {String packageRoot, | 236 Future<bool> docgen(List<String> files, {String packageRoot, |
| 184 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 237 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 185 bool parseSdk: false, bool append: false, String introduction: '', | 238 bool parseSdk: false, bool append: false, String introFileName: '', |
| 186 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], | 239 out: _DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries : const [], |
| 187 bool includeDependentPackages: false}) { | 240 bool includeDependentPackages: false}) { |
| 188 return _Generator.generateDocumentation(files, packageRoot: packageRoot, | 241 return _Generator.generateDocumentation(files, packageRoot: packageRoot, |
| 189 outputToYaml: outputToYaml, includePrivate: includePrivate, | 242 outputToYaml: outputToYaml, includePrivate: includePrivate, |
| 190 includeSdk: includeSdk, parseSdk: parseSdk, append: append, | 243 includeSdk: includeSdk, parseSdk: parseSdk, append: append, |
| 191 introduction: introduction, out: out, excludeLibraries: excludeLibraries, | 244 introFileName: introFileName, out: out, |
| 245 excludeLibraries: excludeLibraries, |
| 192 includeDependentPackages: includeDependentPackages); | 246 includeDependentPackages: includeDependentPackages); |
| 193 } | 247 } |
| 194 | 248 |
| 195 /// Analyzes set of libraries by getting a mirror system and triggers the | 249 /// Analyzes set of libraries by getting a mirror system and triggers the |
| 196 /// documentation of the libraries. | 250 /// documentation of the libraries. |
| 197 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, | 251 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, |
| 198 {String packageRoot, bool parseSdk: false}) { | 252 {String packageRoot, bool parseSdk: false}) { |
| 199 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 253 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 200 // Finds the root of SDK library based off the location of docgen. | 254 // Finds the root of SDK library based off the location of docgen. |
| 201 | 255 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 /// [packageRoot] is the packages directory of the directory being analyzed. | 280 /// [packageRoot] is the packages directory of the directory being analyzed. |
| 227 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will | 281 /// If [includeSdk] is `true`, then any SDK libraries explicitly imported will |
| 228 /// also be documented. | 282 /// also be documented. |
| 229 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 283 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 230 /// This option is useful when only the SDK libraries are needed. | 284 /// This option is useful when only the SDK libraries are needed. |
| 231 /// | 285 /// |
| 232 /// Returned Future completes with true if document generation is successful. | 286 /// Returned Future completes with true if document generation is successful. |
| 233 static Future<bool> generateDocumentation(List<String> files, | 287 static Future<bool> generateDocumentation(List<String> files, |
| 234 {String packageRoot, bool outputToYaml: true, bool includePrivate: false, | 288 {String packageRoot, bool outputToYaml: true, bool includePrivate: false, |
| 235 bool includeSdk: false, bool parseSdk: false, bool append: false, | 289 bool includeSdk: false, bool parseSdk: false, bool append: false, |
| 236 String introduction: '', out: _DEFAULT_OUTPUT_DIRECTORY, | 290 String introFileName: '', out: _DEFAULT_OUTPUT_DIRECTORY, |
| 237 List<String> excludeLibraries : const [], | 291 List<String> excludeLibraries : const [], |
| 238 bool includeDependentPackages: false}) { | 292 bool includeDependentPackages: false}) { |
| 239 _excluded = excludeLibraries; | 293 _excluded = excludeLibraries; |
| 240 _includePrivate = includePrivate; | 294 _includePrivate = includePrivate; |
| 241 logger.onRecord.listen((record) => print(record.message)); | 295 logger.onRecord.listen((record) => print(record.message)); |
| 242 | 296 |
| 243 _ensureOutputDirectory(out, append); | 297 _ensureOutputDirectory(out, append); |
| 244 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); | 298 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); |
| 245 | 299 |
| 246 var requestedLibraries = _findLibrariesToDocument(files, | 300 var requestedLibraries = _findLibrariesToDocument(files, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 266 availableLibraries); | 320 availableLibraries); |
| 267 var librariesToDocument = requestedLibraries.map( | 321 var librariesToDocument = requestedLibraries.map( |
| 268 (each) => availableLibrariesByPath.putIfAbsent(each, | 322 (each) => availableLibrariesByPath.putIfAbsent(each, |
| 269 () => throw "Missing library $each")).toList(); | 323 () => throw "Missing library $each")).toList(); |
| 270 librariesToDocument.addAll( | 324 librariesToDocument.addAll( |
| 271 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); | 325 (includeSdk || parseSdk) ? Indexable._sdkLibraries : []); |
| 272 librariesToDocument.removeWhere( | 326 librariesToDocument.removeWhere( |
| 273 (x) => _excluded.contains(x.simpleName)); | 327 (x) => _excluded.contains(x.simpleName)); |
| 274 _documentLibraries(librariesToDocument, includeSdk: includeSdk, | 328 _documentLibraries(librariesToDocument, includeSdk: includeSdk, |
| 275 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, | 329 outputToYaml: outputToYaml, append: append, parseSdk: parseSdk, |
| 276 introduction: introduction); | 330 introFileName: introFileName); |
| 277 return true; | 331 return true; |
| 278 }); | 332 }); |
| 279 } | 333 } |
| 280 | 334 |
| 281 /// Writes text to a file in the output directory. | 335 /// Writes text to a file in the output directory. |
| 282 static void _writeToFile(String text, String filename, {bool append: false}) { | 336 static void _writeToFile(String text, String filename, {bool append: false}) { |
| 283 if (text == null) return; | 337 if (text == null) return; |
| 284 Directory dir = new Directory(_outputDirectory); | 338 Directory dir = new Directory(_outputDirectory); |
| 285 if (!dir.existsSync()) { | 339 if (!dir.existsSync()) { |
| 286 dir.createSync(); | 340 dir.createSync(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 299 } | 353 } |
| 300 } | 354 } |
| 301 File file = new File(path.join(_outputDirectory, filename)); | 355 File file = new File(path.join(_outputDirectory, filename)); |
| 302 file.writeAsStringSync(text, | 356 file.writeAsStringSync(text, |
| 303 mode: append ? FileMode.APPEND : FileMode.WRITE); | 357 mode: append ? FileMode.APPEND : FileMode.WRITE); |
| 304 } | 358 } |
| 305 | 359 |
| 306 /// Creates documentation for filtered libraries. | 360 /// Creates documentation for filtered libraries. |
| 307 static void _documentLibraries(List<LibraryMirror> libs, | 361 static void _documentLibraries(List<LibraryMirror> libs, |
| 308 {bool includeSdk: false, bool outputToYaml: true, bool append: false, | 362 {bool includeSdk: false, bool outputToYaml: true, bool append: false, |
| 309 bool parseSdk: false, String introduction: ''}) { | 363 bool parseSdk: false, String introFileName: ''}) { |
| 310 libs.forEach((lib) { | 364 libs.forEach((lib) { |
| 311 // Files belonging to the SDK have a uri that begins with 'dart:'. | 365 // Files belonging to the SDK have a uri that begins with 'dart:'. |
| 312 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { | 366 if (includeSdk || !lib.uri.toString().startsWith('dart:')) { |
| 313 var library = generateLibrary(lib); | 367 var library = generateLibrary(lib); |
| 314 entityMap[library.name] = library; | 368 entityMap[library.name] = library; |
| 315 } | 369 } |
| 316 }); | 370 }); |
| 317 | 371 |
| 318 var filteredEntities = entityMap.values.where(_isFullChainVisible); | 372 var filteredEntities = entityMap.values.where(_isFullChainVisible); |
| 319 | 373 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 334 var aResult = set2.difference(set1); | 388 var aResult = set2.difference(set1); |
| 335 for (MirrorBased r in aResult) { | 389 for (MirrorBased r in aResult) { |
| 336 print(' a result is $r and ${r.docName}'); | 390 print(' a result is $r and ${r.docName}'); |
| 337 }*/ | 391 }*/ |
| 338 //print(set1.difference(set2)); | 392 //print(set1.difference(set2)); |
| 339 | 393 |
| 340 // Outputs a JSON file with all libraries and their preview comments. | 394 // Outputs a JSON file with all libraries and their preview comments. |
| 341 // This will help the viewer know what libraries are available to read in. | 395 // This will help the viewer know what libraries are available to read in. |
| 342 var libraryMap; | 396 var libraryMap; |
| 343 var linkResolver = (name) => Indexable.globalFixReference(name); | 397 var linkResolver = (name) => Indexable.globalFixReference(name); |
| 398 |
| 399 String readIntroductionFile(String fileName, includeSdk) { |
| 400 var defaultText = includeSdk ? DEFAULT_SDK_INTRODUCTION : ''; |
| 401 var introText = defaultText; |
| 402 if (fileName.isNotEmpty) { |
| 403 var introFile = new File(fileName); |
| 404 introText = introFile.existsSync() ? introFile.readAsStringSync() : |
| 405 defaultText; |
| 406 } |
| 407 return markdown.markdownToHtml(introText, |
| 408 linkResolver: linkResolver, inlineSyntaxes: _MARKDOWN_SYNTAXES); |
| 409 } |
| 410 |
| 344 if (append) { | 411 if (append) { |
| 345 var docsDir = listDir(_outputDirectory); | 412 var docsDir = listDir(_outputDirectory); |
| 346 if (!docsDir.contains('$_outputDirectory/library_list.json')) { | 413 if (!docsDir.contains('$_outputDirectory/library_list.json')) { |
| 347 throw new StateError('No library_list.json'); | 414 throw new StateError('No library_list.json'); |
| 348 } | 415 } |
| 349 libraryMap = | 416 libraryMap = |
| 350 JSON.decode(new File( | 417 JSON.decode(new File( |
| 351 '$_outputDirectory/library_list.json').readAsStringSync()); | 418 '$_outputDirectory/library_list.json').readAsStringSync()); |
| 352 libraryMap['libraries'].addAll(filteredEntities | 419 libraryMap['libraries'].addAll(filteredEntities |
| 353 .where((e) => e is Library) | 420 .where((e) => e is Library) |
| 354 .map((e) => e.previewMap)); | 421 .map((e) => e.previewMap)); |
| 355 if (introduction.isNotEmpty) { | 422 var intro = libraryMap['introduction']; |
| 356 var intro = libraryMap['introduction']; | 423 var spacing = intro.isEmpty ? '' : '<br/><br/>'; |
| 357 if (intro.isNotEmpty) intro += '<br/><br/>'; | 424 libraryMap['introduction'] = |
| 358 intro += markdown.markdownToHtml( | 425 "$intro$spacing${readIntroductionFile(introFileName, includeSdk)}"; |
| 359 new File(introduction).readAsStringSync(), | |
| 360 linkResolver: linkResolver, inlineSyntaxes: _MARKDOWN_SYNTAXES); | |
| 361 libraryMap['introduction'] = intro; | |
| 362 } | |
| 363 outputToYaml = libraryMap['filetype'] == 'yaml'; | 426 outputToYaml = libraryMap['filetype'] == 'yaml'; |
| 364 } else { | 427 } else { |
| 365 libraryMap = { | 428 libraryMap = { |
| 366 'libraries' : filteredEntities.where((e) => | 429 'libraries' : filteredEntities.where((e) => |
| 367 e is Library).map((e) => e.previewMap).toList(), | 430 e is Library).map((e) => e.previewMap).toList(), |
| 368 'introduction' : introduction == '' ? | 431 'introduction' : readIntroductionFile(introFileName, includeSdk), |
| 369 '' : markdown.markdownToHtml(new File(introduction) | |
| 370 .readAsStringSync(), linkResolver: linkResolver, | |
| 371 inlineSyntaxes: _MARKDOWN_SYNTAXES), | |
| 372 'filetype' : outputToYaml ? 'yaml' : 'json' | 432 'filetype' : outputToYaml ? 'yaml' : 'json' |
| 373 }; | 433 }; |
| 374 } | 434 } |
| 375 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); | 435 _writeToFile(JSON.encode(libraryMap), 'library_list.json'); |
| 376 | 436 |
| 377 // Output libraries and classes to file after all information is generated. | 437 // Output libraries and classes to file after all information is generated. |
| 378 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { | 438 filteredEntities.where((e) => e is Class || e is Library).forEach((output) { |
| 379 _writeIndexableToFile(output, outputToYaml); | 439 _writeIndexableToFile(output, outputToYaml); |
| 380 }); | 440 }); |
| 381 | 441 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 /// For this run of docgen, determine the packageRoot value. | 520 /// For this run of docgen, determine the packageRoot value. |
| 461 /// | 521 /// |
| 462 /// If packageRoot is not explicitly passed, we examine the files we're | 522 /// If packageRoot is not explicitly passed, we examine the files we're |
| 463 /// documenting to attempt to find a package root. | 523 /// documenting to attempt to find a package root. |
| 464 static String _obtainPackageRoot(String packageRoot, bool parseSdk, | 524 static String _obtainPackageRoot(String packageRoot, bool parseSdk, |
| 465 List<String> files) { | 525 List<String> files) { |
| 466 if (packageRoot == null && !parseSdk) { | 526 if (packageRoot == null && !parseSdk) { |
| 467 // TODO(efortuna): This logic seems not very robust, but it's from the | 527 // TODO(efortuna): This logic seems not very robust, but it's from the |
| 468 // original version of the code, pre-refactor, so I'm leavingt it for now. | 528 // original version of the code, pre-refactor, so I'm leavingt it for now. |
| 469 // Revisit to make more robust. | 529 // Revisit to make more robust. |
| 530 // TODO(efortuna): See lines 303-311 in |
| 531 // https://codereview.chromium.org/116043013/diff/390001/pkg/docgen/lib/do
cgen.dart |
| 470 var type = FileSystemEntity.typeSync(files.first); | 532 var type = FileSystemEntity.typeSync(files.first); |
| 471 if (type == FileSystemEntityType.DIRECTORY) { | 533 if (type == FileSystemEntityType.DIRECTORY) { |
| 472 var files2 = listDir(files.first, recursive: true); | 534 var files2 = listDir(files.first, recursive: true); |
| 473 // Return '' means that there was no pubspec.yaml and therefor no p | 535 // Return '' means that there was no pubspec.yaml and therefor no p |
| 474 // ackageRoot. | 536 // ackageRoot. |
| 475 packageRoot = files2.firstWhere((f) => | 537 packageRoot = files2.firstWhere((f) => |
| 476 f.endsWith('${path.separator}pubspec.yaml'), orElse: () => ''); | 538 f.endsWith('${path.separator}pubspec.yaml'), orElse: () => ''); |
| 477 if (packageRoot != '') { | 539 if (packageRoot != '') { |
| 478 packageRoot = path.join(path.dirname(packageRoot), 'packages'); | 540 packageRoot = path.join(path.dirname(packageRoot), 'packages'); |
| 479 } | 541 } |
| 480 } else if (type == FileSystemEntityType.FILE) { | 542 } else if (type == FileSystemEntityType.FILE) { |
| 481 logger.warning('WARNING: No package root defined. If Docgen fails, try ' | 543 logger.warning('WARNING: No package root defined. If Docgen fails, try ' |
| 482 'again by setting the --package-root option.'); | 544 'again by setting the --package-root option.'); |
| 483 } | 545 } |
| 484 } | 546 } |
| 485 logger.info('Package Root: ${packageRoot}'); | 547 logger.info('Package Root: ${packageRoot}'); |
| 486 return packageRoot; | 548 return path.normalize(path.absolute(packageRoot)); |
| 487 } | 549 } |
| 488 | 550 |
| 489 /// Given the user provided list of items to document, expand all directories | 551 /// Given the user provided list of items to document, expand all directories |
| 490 /// to document out into specific files and add any dependent packages for | 552 /// to document out into specific files and add any dependent packages for |
| 491 /// documentation if desired. | 553 /// documentation if desired. |
| 492 static List<Uri> _findLibrariesToDocument(List<String> args, | 554 static List<Uri> _findLibrariesToDocument(List<String> args, |
| 493 bool includeDependentPackages) { | 555 bool includeDependentPackages) { |
| 494 if (includeDependentPackages) { | 556 if (includeDependentPackages) { |
| 495 args.addAll(_allDependentPackageDirs(args.first)); | 557 args.addAll(_allDependentPackageDirs(args.first)); |
| 496 } | 558 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 if (map == null) map = new Map<String, Set<MirrorBased>>(); | 677 if (map == null) map = new Map<String, Set<MirrorBased>>(); |
| 616 | 678 |
| 617 var set = map[owner.docName]; | 679 var set = map[owner.docName]; |
| 618 if (set == null) set = new Set<MirrorBased>(); | 680 if (set == null) set = new Set<MirrorBased>(); |
| 619 set.add(this); | 681 set.add(this); |
| 620 map[owner.docName] = set; | 682 map[owner.docName] = set; |
| 621 mirrorToDocgen[this.mirror.qualifiedName] = map; | 683 mirrorToDocgen[this.mirror.qualifiedName] = map; |
| 622 } | 684 } |
| 623 | 685 |
| 624 /** Walk up the owner chain to find the owning library. */ | 686 /** Walk up the owner chain to find the owning library. */ |
| 625 Library _getOwningLibrary(Indexable owner) { | 687 Library _getOwningLibrary(Indexable indexable) { |
| 626 if (owner is Library) return owner; | 688 if (indexable is Library) return indexable; |
| 627 // TODO: is this needed? | 689 // TODO: is this needed? |
| 628 if (owner is DummyMirror) return getDocgenObject(owner.mirror.library); | 690 if (indexable is DummyMirror) return getDocgenObject(indexable.mirror.librar
y); |
| 629 return _getOwningLibrary(owner.owner); | 691 return _getOwningLibrary(indexable.owner); |
| 630 } | 692 } |
| 631 | 693 |
| 632 static initializeTopLevelLibraries(MirrorSystem mirrorSystem) { | 694 static initializeTopLevelLibraries(MirrorSystem mirrorSystem) { |
| 633 _sdkLibraries = mirrorSystem.libraries.values.where( | 695 _sdkLibraries = mirrorSystem.libraries.values.where( |
| 634 (each) => each.uri.scheme == 'dart'); | 696 (each) => each.uri.scheme == 'dart'); |
| 635 _coreLibrary = new Library(_sdkLibraries.singleWhere((lib) => | 697 _coreLibrary = new Library(_sdkLibraries.singleWhere((lib) => |
| 636 lib.uri.toString().startsWith('dart:core'))); | 698 lib.uri.toString().startsWith('dart:core'))); |
| 637 } | 699 } |
| 638 | 700 |
| 639 markdown.Node fixReferenceWithScope(String name) => null; | 701 markdown.Node fixReferenceWithScope(String name) => null; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 var method = new Method(mirror, owner); | 875 var method = new Method(mirror, owner); |
| 814 entityMap[method.docName] = method; | 876 entityMap[method.docName] = method; |
| 815 group[mirror.simpleName] = method; | 877 group[mirror.simpleName] = method; |
| 816 } | 878 } |
| 817 }); | 879 }); |
| 818 return group; | 880 return group; |
| 819 } | 881 } |
| 820 | 882 |
| 821 /// Returns a map of [Parameter] objects constructed from [mirrorList]. | 883 /// Returns a map of [Parameter] objects constructed from [mirrorList]. |
| 822 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList, | 884 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList, |
| 823 [Indexable owner]) { | 885 Indexable owner) { |
| 824 var data = {}; | 886 var data = {}; |
| 825 mirrorList.forEach((ParameterMirror mirror) { | 887 mirrorList.forEach((ParameterMirror mirror) { |
| 826 data[mirror.simpleName] = new Parameter(mirror, owner); | 888 data[mirror.simpleName] = new Parameter(mirror, _getOwningLibrary(owner)); |
| 827 }); | 889 }); |
| 828 return data; | 890 return data; |
| 829 } | 891 } |
| 830 | 892 |
| 831 /// Returns a map of [Generic] objects constructed from the class mirror. | 893 /// Returns a map of [Generic] objects constructed from the class mirror. |
| 832 Map<String, Generic> _createGenerics(ClassMirror mirror) { | 894 Map<String, Generic> _createGenerics(ClassMirror mirror) { |
| 833 return new Map.fromIterable(mirror.typeVariables, | 895 return new Map.fromIterable(mirror.typeVariables, |
| 834 key: (e) => e.toString(), | 896 key: (e) => e.toString(), |
| 835 value: (e) => new Generic(e)); | 897 value: (e) => new Generic(e)); |
| 836 } | 898 } |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 // The reason we do this madness is the superclass and interface owners may | 1385 // The reason we do this madness is the superclass and interface owners may |
| 1324 // not be this class's owner!! Example: BaseClient in http pkg. | 1386 // not be this class's owner!! Example: BaseClient in http pkg. |
| 1325 var superinterfaces = classMirror.superinterfaces.map( | 1387 var superinterfaces = classMirror.superinterfaces.map( |
| 1326 (interface) => new Class._possiblyDifferentOwner(interface, owner)); | 1388 (interface) => new Class._possiblyDifferentOwner(interface, owner)); |
| 1327 this.superclass = classMirror.superclass == null? null : | 1389 this.superclass = classMirror.superclass == null? null : |
| 1328 new Class._possiblyDifferentOwner(classMirror.superclass, owner); | 1390 new Class._possiblyDifferentOwner(classMirror.superclass, owner); |
| 1329 | 1391 |
| 1330 interfaces = superinterfaces.toList(); | 1392 interfaces = superinterfaces.toList(); |
| 1331 variables = _createVariables(classMirror.variables, this); | 1393 variables = _createVariables(classMirror.variables, this); |
| 1332 methods = _createMethods(classMirror.methods, this); | 1394 methods = _createMethods(classMirror.methods, this); |
| 1333 annotations = _createAnnotations(classMirror, this); | 1395 annotations = _createAnnotations(classMirror, _getOwningLibrary(owner)); |
| 1334 generics = _createGenerics(classMirror); | 1396 generics = _createGenerics(classMirror); |
| 1335 isAbstract = classMirror.isAbstract; | 1397 isAbstract = classMirror.isAbstract; |
| 1336 inheritedMethods = new Map<String, Method>(); | 1398 inheritedMethods = new Map<String, Method>(); |
| 1337 | 1399 |
| 1338 // Tell all superclasses that you are a subclass, unless you are not | 1400 // Tell all superclasses that you are a subclass, unless you are not |
| 1339 // visible or an intermediary mixin class. | 1401 // visible or an intermediary mixin class. |
| 1340 if (!classMirror.isNameSynthetic && _isVisible) { | 1402 if (!classMirror.isNameSynthetic && _isVisible) { |
| 1341 parentChain().forEach((parentClass) { | 1403 parentChain().forEach((parentClass) { |
| 1342 parentClass.addSubclass(this); | 1404 parentClass.addSubclass(this); |
| 1343 }); | 1405 }); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 if (aTypedef is DummyMirror) { | 1581 if (aTypedef is DummyMirror) { |
| 1520 aTypedef = new Typedef._(mirror, owningLibrary); | 1582 aTypedef = new Typedef._(mirror, owningLibrary); |
| 1521 } | 1583 } |
| 1522 return aTypedef; | 1584 return aTypedef; |
| 1523 } | 1585 } |
| 1524 | 1586 |
| 1525 Typedef._(TypedefMirror mirror, Library owningLibrary) : super(mirror) { | 1587 Typedef._(TypedefMirror mirror, Library owningLibrary) : super(mirror) { |
| 1526 owner = owningLibrary; | 1588 owner = owningLibrary; |
| 1527 returnType = getDocgenObject(mirror.value.returnType).docName; | 1589 returnType = getDocgenObject(mirror.value.returnType).docName; |
| 1528 generics = _createGenerics(mirror); | 1590 generics = _createGenerics(mirror); |
| 1529 parameters = _createParameters(mirror.value.parameters); | 1591 parameters = _createParameters(mirror.value.parameters, owningLibrary); |
| 1530 annotations = _createAnnotations(mirror, this); | 1592 annotations = _createAnnotations(mirror, owningLibrary); |
| 1531 } | 1593 } |
| 1532 | 1594 |
| 1533 Map toMap() => { | 1595 Map toMap() => { |
| 1534 'name': name, | 1596 'name': name, |
| 1535 'qualifiedName': qualifiedName, | 1597 'qualifiedName': qualifiedName, |
| 1536 'comment': comment, | 1598 'comment': comment, |
| 1537 'return': returnType, | 1599 'return': returnType, |
| 1538 'parameters': recurseMap(parameters), | 1600 'parameters': recurseMap(parameters), |
| 1539 'annotations': annotations.map((a) => a.toMap()).toList(), | 1601 'annotations': annotations.map((a) => a.toMap()).toList(), |
| 1540 'generics': recurseMap(generics) | 1602 'generics': recurseMap(generics) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 Method methodInheritedFrom; | 1700 Method methodInheritedFrom; |
| 1639 | 1701 |
| 1640 /// Qualified name to state where the comment is inherited from. | 1702 /// Qualified name to state where the comment is inherited from. |
| 1641 String commentInheritedFrom = ""; | 1703 String commentInheritedFrom = ""; |
| 1642 | 1704 |
| 1643 /// List of the meta annotations on the method. | 1705 /// List of the meta annotations on the method. |
| 1644 List<Annotation> annotations; | 1706 List<Annotation> annotations; |
| 1645 | 1707 |
| 1646 Indexable owner; | 1708 Indexable owner; |
| 1647 | 1709 |
| 1648 factory Method(MethodMirror mirror, Indexable owner, | 1710 factory Method(MethodMirror mirror, Indexable owner, // Indexable newOwner. |
| 1649 [Method methodInheritedFrom]) { | 1711 [Method methodInheritedFrom]) { |
| 1650 var method = getDocgenObject(mirror, owner); | 1712 var method = getDocgenObject(mirror, owner); |
| 1651 if (method is DummyMirror) { | 1713 if (method is DummyMirror) { |
| 1652 method = new Method._(mirror, owner, methodInheritedFrom); | 1714 method = new Method._(mirror, owner, methodInheritedFrom); |
| 1653 } | 1715 } |
| 1654 return method; | 1716 return method; |
| 1655 } | 1717 } |
| 1656 | 1718 |
| 1657 Method._(MethodMirror mirror, this.owner, this.methodInheritedFrom) | 1719 Method._(MethodMirror mirror, this.owner, this.methodInheritedFrom) |
| 1658 : super(mirror) { | 1720 : super(mirror) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 return super.docName; | 1771 return super.docName; |
| 1710 } | 1772 } |
| 1711 | 1773 |
| 1712 /// Makes sure that the method with an inherited equivalent have comments. | 1774 /// Makes sure that the method with an inherited equivalent have comments. |
| 1713 void ensureCommentFor(Method inheritedMethod) { | 1775 void ensureCommentFor(Method inheritedMethod) { |
| 1714 if (comment.isNotEmpty) return; | 1776 if (comment.isNotEmpty) return; |
| 1715 | 1777 |
| 1716 comment = inheritedMethod._commentToHtml(this); | 1778 comment = inheritedMethod._commentToHtml(this); |
| 1717 _unresolvedComment = inheritedMethod._unresolvedComment; | 1779 _unresolvedComment = inheritedMethod._unresolvedComment; |
| 1718 commentInheritedFrom = inheritedMethod.commentInheritedFrom == '' ? | 1780 commentInheritedFrom = inheritedMethod.commentInheritedFrom == '' ? |
| 1719 inheritedMethod.qualifiedName : inheritedMethod.commentInheritedFrom; | 1781 inheritedMethod.mirror.qualifiedName : |
| 1782 inheritedMethod.commentInheritedFrom; |
| 1720 } | 1783 } |
| 1721 | 1784 |
| 1722 /// Generates a map describing the [Method] object. | 1785 /// Generates a map describing the [Method] object. |
| 1723 Map toMap() => { | 1786 Map toMap() => { |
| 1724 'name': name, | 1787 'name': name, |
| 1725 'qualifiedName': qualifiedName, | 1788 'qualifiedName': qualifiedName, |
| 1726 'comment': comment, | 1789 'comment': comment, |
| 1727 'commentFrom': (methodInheritedFrom != null && | 1790 'commentFrom': (methodInheritedFrom != null && |
| 1728 commentInheritedFrom == methodInheritedFrom.docName ? '' | 1791 commentInheritedFrom == methodInheritedFrom.docName ? '' |
| 1729 : commentInheritedFrom), | 1792 : commentInheritedFrom), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1750 if (result == '' && methodInheritedFrom != null) { | 1813 if (result == '' && methodInheritedFrom != null) { |
| 1751 // this should be NOT from the MIRROR, but from the COMMENT | 1814 // this should be NOT from the MIRROR, but from the COMMENT |
| 1752 _unresolvedComment = methodInheritedFrom._unresolvedComment; | 1815 _unresolvedComment = methodInheritedFrom._unresolvedComment; |
| 1753 | 1816 |
| 1754 var linkResolver = (name) => fixReferenceWithScope(name); | 1817 var linkResolver = (name) => fixReferenceWithScope(name); |
| 1755 comment = _unresolvedComment == null ? '' : | 1818 comment = _unresolvedComment == null ? '' : |
| 1756 markdown.markdownToHtml(_unresolvedComment.trim(), | 1819 markdown.markdownToHtml(_unresolvedComment.trim(), |
| 1757 linkResolver: linkResolver, inlineSyntaxes: _MARKDOWN_SYNTAXES); | 1820 linkResolver: linkResolver, inlineSyntaxes: _MARKDOWN_SYNTAXES); |
| 1758 commentInheritedFrom = methodInheritedFrom.commentInheritedFrom; | 1821 commentInheritedFrom = methodInheritedFrom.commentInheritedFrom; |
| 1759 result = comment; | 1822 result = comment; |
| 1760 //print('result was $comment'); | |
| 1761 } | 1823 } |
| 1762 return result; | 1824 return result; |
| 1763 } | 1825 } |
| 1764 } | 1826 } |
| 1765 | 1827 |
| 1766 /// A class containing properties of a Dart method/function parameter. | 1828 /// Docgen wrapper around the dart2js mirror for a Dart |
| 1829 /// method/function parameter. |
| 1767 class Parameter extends MirrorBased { | 1830 class Parameter extends MirrorBased { |
| 1768 | |
| 1769 ParameterMirror mirror; | 1831 ParameterMirror mirror; |
| 1770 String name; | 1832 String name; |
| 1771 bool isOptional; | 1833 bool isOptional; |
| 1772 bool isNamed; | 1834 bool isNamed; |
| 1773 bool hasDefaultValue; | 1835 bool hasDefaultValue; |
| 1774 Type type; | 1836 Type type; |
| 1775 String defaultValue; | 1837 String defaultValue; |
| 1776 | |
| 1777 /// List of the meta annotations on the parameter. | 1838 /// List of the meta annotations on the parameter. |
| 1778 List<Annotation> annotations; | 1839 List<Annotation> annotations; |
| 1779 | 1840 |
| 1780 Parameter(this.mirror, [Indexable owner]) { | 1841 Parameter(this.mirror, Library owningLibrary) { |
| 1781 name = mirror.simpleName; | 1842 name = mirror.simpleName; |
| 1782 isOptional = mirror.isOptional; | 1843 isOptional = mirror.isOptional; |
| 1783 isNamed = mirror.isNamed; | 1844 isNamed = mirror.isNamed; |
| 1784 hasDefaultValue = mirror.hasDefaultValue; | 1845 hasDefaultValue = mirror.hasDefaultValue; |
| 1785 defaultValue = mirror.defaultValue; | 1846 defaultValue = mirror.defaultValue; |
| 1786 type = new Type(mirror.type, owner); | 1847 type = new Type(mirror.type, owningLibrary); |
| 1787 annotations = _createAnnotations(mirror, this); | 1848 annotations = _createAnnotations(mirror, owningLibrary); |
| 1788 } | 1849 } |
| 1789 | 1850 |
| 1790 /// Generates a map describing the [Parameter] object. | 1851 /// Generates a map describing the [Parameter] object. |
| 1791 Map toMap() => { | 1852 Map toMap() => { |
| 1792 'name': name, | 1853 'name': name, |
| 1793 'optional': isOptional.toString(), | 1854 'optional': isOptional.toString(), |
| 1794 'named': isNamed.toString(), | 1855 'named': isNamed.toString(), |
| 1795 'default': hasDefaultValue.toString(), | 1856 'default': hasDefaultValue.toString(), |
| 1796 'type': new List.filled(1, type.toMap()), | 1857 'type': new List.filled(1, type.toMap()), |
| 1797 'value': defaultValue, | 1858 'value': defaultValue, |
| 1798 'annotations': annotations.map((a) => a.toMap()).toList() | 1859 'annotations': annotations.map((a) => a.toMap()).toList() |
| 1799 }; | 1860 }; |
| 1800 } | 1861 } |
| 1801 | 1862 |
| 1802 /// A Docgen wrapper around the dart2js mirror for a generic type. | 1863 /// A Docgen wrapper around the dart2js mirror for a generic type. |
| 1803 class Generic extends MirrorBased { | 1864 class Generic extends MirrorBased { |
| 1804 TypeVariableMirror mirror; | 1865 TypeVariableMirror mirror; |
| 1805 Generic(this.mirror); | 1866 Generic(this.mirror); |
| 1806 Map toMap() => { | 1867 Map toMap() => { |
| 1807 'name': mirror.toString(), | 1868 'name': mirror.toString(), |
| 1808 'type': mirror.upperBound.qualifiedName | 1869 'type': mirror.upperBound.qualifiedName |
| 1809 }; | 1870 }; |
| 1810 } | 1871 } |
| 1811 | 1872 |
| 1812 /// Holds the name of a return type, and its generic type parameters. | 1873 /// Docgen wrapper around the mirror for a return type, and/or its generic |
| 1874 /// type parameters. |
| 1813 /// | 1875 /// |
| 1814 /// Return types are of a form [outer]<[inner]>. | 1876 /// Return types are of a form [outer]<[inner]>. |
| 1815 /// If there is no [inner] part, [inner] will be an empty list. | 1877 /// If there is no [inner] part, [inner] will be an empty list. |
| 1816 /// | 1878 /// |
| 1817 /// For example: | 1879 /// For example: |
| 1818 /// int size() | 1880 /// int size() |
| 1819 /// "return" : | 1881 /// "return" : |
| 1820 /// - "outer" : "dart-core.int" | 1882 /// - "outer" : "dart-core.int" |
| 1821 /// "inner" : | 1883 /// "inner" : |
| 1822 /// | 1884 /// |
| 1823 /// List<String> toList() | 1885 /// List<String> toList() |
| 1824 /// "return" : | 1886 /// "return" : |
| 1825 /// - "outer" : "dart-core.List" | 1887 /// - "outer" : "dart-core.List" |
| 1826 /// "inner" : | 1888 /// "inner" : |
| 1827 /// - "outer" : "dart-core.String" | 1889 /// - "outer" : "dart-core.String" |
| 1828 /// "inner" : | 1890 /// "inner" : |
| 1829 /// | 1891 /// |
| 1830 /// Map<String, List<int>> | 1892 /// Map<String, List<int>> |
| 1831 /// "return" : | 1893 /// "return" : |
| 1832 /// - "outer" : "dart-core.Map" | 1894 /// - "outer" : "dart-core.Map" |
| 1833 /// "inner" : | 1895 /// "inner" : |
| 1834 /// - "outer" : "dart-core.String" | 1896 /// - "outer" : "dart-core.String" |
| 1835 /// "inner" : | 1897 /// "inner" : |
| 1836 /// - "outer" : "dart-core.List" | 1898 /// - "outer" : "dart-core.List" |
| 1837 /// "inner" : | 1899 /// "inner" : |
| 1838 /// - "outer" : "dart-core.int" | 1900 /// - "outer" : "dart-core.int" |
| 1839 /// "inner" : | 1901 /// "inner" : |
| 1840 class Type extends MirrorBased { | 1902 class Type extends MirrorBased { |
| 1841 TypeMirror mirror; | 1903 TypeMirror mirror; |
| 1842 MirrorBased owner; | 1904 MirrorBased owningLibrary; |
| 1843 | 1905 |
| 1844 factory Type(TypeMirror mirror, [MirrorBased owner]) { | 1906 Type(this.mirror, this.owningLibrary); |
| 1845 return new Type._(mirror, owner); | |
| 1846 } | |
| 1847 | |
| 1848 Type._(this.mirror, this.owner); | |
| 1849 | 1907 |
| 1850 /// Returns a list of [Type] objects constructed from TypeMirrors. | 1908 /// Returns a list of [Type] objects constructed from TypeMirrors. |
| 1851 List<Type> _createTypeGenerics(TypeMirror mirror) { | 1909 List<Type> _createTypeGenerics(TypeMirror mirror) { |
| 1852 if (mirror is ClassMirror && !mirror.isTypedef) { | 1910 if (mirror is ClassMirror && !mirror.isTypedef) { |
| 1853 var innerList = []; | 1911 var innerList = []; |
| 1854 mirror.typeArguments.forEach((e) { | 1912 mirror.typeArguments.forEach((e) { |
| 1855 innerList.add(new Type(e, owner)); | 1913 innerList.add(new Type(e, owningLibrary)); |
| 1856 }); | 1914 }); |
| 1857 return innerList; | 1915 return innerList; |
| 1858 } | 1916 } |
| 1859 return []; | 1917 return []; |
| 1860 } | 1918 } |
| 1861 | 1919 |
| 1862 Map toMap() { | 1920 Map toMap() { |
| 1863 // We may encounter types whose corresponding library has not been | 1921 // We may encounter types whose corresponding library has not been |
| 1864 // processed yet, so look up the owner at the last moment. | 1922 // processed yet, so look up with the owningLibrary at the last moment. |
| 1865 var result = getDocgenObject(mirror, owner); | 1923 var result = getDocgenObject(mirror, owningLibrary); |
| 1866 return { | 1924 return { |
| 1867 'outer': result.docName, | 1925 'outer': result.docName, |
| 1868 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), | 1926 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), |
| 1869 }; | 1927 }; |
| 1870 } | 1928 } |
| 1871 } | 1929 } |
| 1872 | 1930 |
| 1873 /// Holds the name of the annotation, and its parameters. | 1931 /// Holds the name of the annotation, and its parameters. |
| 1874 class Annotation extends MirrorBased { | 1932 class Annotation extends MirrorBased { |
| 1875 List<String> parameters; | 1933 List<String> parameters; |
| 1876 /// The class of this annotation. | 1934 /// The class of this annotation. |
| 1877 ClassMirror mirror; | 1935 ClassMirror mirror; |
| 1936 Library owningLibrary; |
| 1878 | 1937 |
| 1879 Annotation(InstanceMirror originalMirror, MirrorBased annotationOwner) { | 1938 Annotation(InstanceMirror originalMirror, this.owningLibrary) { |
| 1880 mirror = originalMirror.type; | 1939 mirror = originalMirror.type; |
| 1881 parameters = originalMirror.type.variables.values | 1940 parameters = originalMirror.type.variables.values |
| 1882 .where((e) => e.isFinal) | 1941 .where((e) => e.isFinal) |
| 1883 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 1942 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 1884 .where((e) => e != null) | 1943 .where((e) => e != null) |
| 1885 .toList(); | 1944 .toList(); |
| 1886 owner = annotationOwner; | |
| 1887 } | 1945 } |
| 1888 | 1946 |
| 1889 Map toMap() => { | 1947 Map toMap() => { |
| 1890 'name': getDocgenObject(mirror, owner).docName, | 1948 'name': getDocgenObject(mirror, owningLibrary).docName, |
| 1891 'parameters': parameters | 1949 'parameters': parameters |
| 1892 }; | 1950 }; |
| 1893 } | 1951 } |
| OLD | NEW |