Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library docgen.models; | 5 library docgen.models; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:markdown/markdown.dart' as markdown; | 9 import 'package:markdown/markdown.dart' as markdown; |
| 10 | 10 |
| 11 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart'; | 11 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart'; |
| 12 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart' | 12 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart' |
| 13 as dart2js_util; | 13 as dart2js_util; |
| 14 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rrors.dart' | 14 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rrors.dart' |
| 15 as dart2js_mirrors; | 15 as dart2js_mirrors; |
| 16 | 16 |
| 17 import 'library_helpers.dart'; | 17 import 'library_helpers.dart'; |
| 18 import 'mdn.dart'; | 18 import 'mdn.dart'; |
| 19 import 'model_helpers.dart'; | 19 import 'model_helpers.dart'; |
| 20 import 'package_helpers.dart'; | 20 import 'package_helpers.dart'; |
| 21 | 21 |
| 22 /// Docgen representation of an item to be documented, that wraps around a | 22 /// Docgen representation of an item to be documented, that wraps around a |
| 23 /// dart2js mirror. | 23 /// dart2js mirror. |
| 24 abstract class MirrorBased<TMirror extends DeclarationMirror> { | 24 abstract class MirrorBased<TMirror extends DeclarationMirror> { |
| 25 /// The original dart2js mirror around which this object wraps. | 25 /// The original dart2js mirror around which this object wraps. |
| 26 TMirror get mirror; | 26 TMirror get mirror; |
| 27 | |
| 28 /// Return an informative [Object.toString] for debugging. | |
| 29 String toString() => "${super.toString()} - $mirror"; | |
|
Emily Fortuna
2014/04/02 16:33:49
I found printing out dart2js_util.qualifiedNameOf(
kevmoo
2014/04/02 16:35:14
I'll keep that in mind for future hacks here. :-)
| |
| 27 } | 30 } |
| 28 | 31 |
| 29 /// A Docgen wrapper around the dart2js mirror for a generic type. | 32 /// A Docgen wrapper around the dart2js mirror for a generic type. |
| 30 class Generic extends MirrorBased<TypeVariableMirror> { | 33 class Generic extends MirrorBased<TypeVariableMirror> { |
| 31 final TypeVariableMirror mirror; | 34 final TypeVariableMirror mirror; |
| 32 | 35 |
| 33 Generic(this.mirror); | 36 Generic(this.mirror); |
| 34 | 37 |
| 35 Map toMap() => { | 38 Map toMap() => { |
| 36 'name': dart2js_util.nameOf(mirror), | 39 'name': dart2js_util.nameOf(mirror), |
| 37 'type': dart2js_util.qualifiedNameOf(mirror.upperBound) | 40 'type': dart2js_util.qualifiedNameOf(mirror.upperBound) |
| 38 }; | 41 }; |
| 39 } | 42 } |
| 40 | 43 |
| 41 /// For types that we do not explicitly create or have not yet created in our | 44 /// For types that we do not explicitly create or have not yet created in our |
| 42 /// entity map (like core types). | 45 /// entity map (like core types). |
| 43 class DummyMirror implements Indexable { | 46 class DummyMirror implements Indexable { |
| 44 DeclarationMirror mirror; | 47 final DeclarationMirror mirror; |
| 45 /// The library that contains this element, if any. Used as a hint to help | 48 /// The library that contains this element, if any. Used as a hint to help |
| 46 /// determine which object we're referring to when looking up this mirror in | 49 /// determine which object we're referring to when looking up this mirror in |
| 47 /// our map. | 50 /// our map. |
| 48 Indexable owner; | 51 final Indexable owner; |
| 49 DummyMirror(this.mirror, [this.owner]); | 52 DummyMirror(this.mirror, [this.owner]); |
| 50 | 53 |
| 51 String get docName { | 54 String get docName { |
| 52 if (mirror == null) return ''; | 55 if (mirror == null) return ''; |
| 53 if (mirror is LibraryMirror) { | 56 if (mirror is LibraryMirror) { |
| 54 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); | 57 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); |
| 55 } | 58 } |
| 56 var mirrorOwner = mirror.owner; | 59 var mirrorOwner = mirror.owner; |
| 57 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror); | 60 if (mirrorOwner == null) return dart2js_util.qualifiedNameOf(mirror); |
| 58 var simpleName = dart2js_util.nameOf(mirror); | 61 var simpleName = dart2js_util.nameOf(mirror); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 /// These are items that refer to concrete entities (a Class, for example, | 98 /// These are items that refer to concrete entities (a Class, for example, |
| 96 /// but not a Type, which is a "pointer" to a class) that we wish to be | 99 /// but not a Type, which is a "pointer" to a class) that we wish to be |
| 97 /// globally resolvable. This includes things such as class methods and | 100 /// globally resolvable. This includes things such as class methods and |
| 98 /// variables, but parameters for methods are not "Indexable" as we do not want | 101 /// variables, but parameters for methods are not "Indexable" as we do not want |
| 99 /// the user to be able to search for a method based on its parameter names! | 102 /// the user to be able to search for a method based on its parameter names! |
| 100 /// The set of indexable items also includes Typedefs, since the user can refer | 103 /// The set of indexable items also includes Typedefs, since the user can refer |
| 101 /// to them as concrete entities in a particular scope. | 104 /// to them as concrete entities in a particular scope. |
| 102 abstract class Indexable<TMirror extends DeclarationMirror> | 105 abstract class Indexable<TMirror extends DeclarationMirror> |
| 103 extends MirrorBased<TMirror> { | 106 extends MirrorBased<TMirror> { |
| 104 | 107 |
| 105 | 108 Library get owningLibrary => owner.owningLibrary; |
| 106 Library get _owningLibrary => owner._owningLibrary; | |
| 107 | 109 |
| 108 String get qualifiedName => fileName; | 110 String get qualifiedName => fileName; |
| 109 final TMirror mirror; | 111 final TMirror mirror; |
| 110 final bool isPrivate; | 112 final bool isPrivate; |
| 111 /// The comment text pre-resolution. We keep this around because inherited | 113 /// The comment text pre-resolution. We keep this around because inherited |
| 112 /// methods need to resolve links differently from the superclass. | 114 /// methods need to resolve links differently from the superclass. |
| 113 String _unresolvedComment = ''; | 115 String _unresolvedComment = ''; |
| 114 | 116 |
| 115 Indexable(TMirror mirror) | 117 Indexable(TMirror mirror) |
| 116 : this.mirror = mirror, | 118 : this.mirror = mirror, |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 var commentText = _commentText; | 251 var commentText = _commentText; |
| 250 _unresolvedComment = commentText; | 252 _unresolvedComment = commentText; |
| 251 | 253 |
| 252 var linkResolver = (name) => resolvingScope.fixReference(name); | 254 var linkResolver = (name) => resolvingScope.fixReference(name); |
| 253 commentText = commentText == null ? '' : | 255 commentText = commentText == null ? '' : |
| 254 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver, | 256 markdown.markdownToHtml(commentText.trim(), linkResolver: linkResolver, |
| 255 inlineSyntaxes: MARKDOWN_SYNTAXES); | 257 inlineSyntaxes: MARKDOWN_SYNTAXES); |
| 256 return commentText; | 258 return commentText; |
| 257 } | 259 } |
| 258 | 260 |
| 259 /// Returns a map of [Variable] objects constructed from [mirrorMap]. | |
| 260 /// The optional parameter [containingLibrary] is contains data for variables | |
| 261 /// defined at the top level of a library (potentially for exporting | |
| 262 /// purposes). | |
| 263 Map<String, Variable> _createVariables(Iterable<VariableMirror> mirrors, | |
| 264 Indexable owner) { | |
| 265 var data = {}; | |
| 266 // TODO(janicejl): When map to map feature is created, replace the below | |
| 267 // with a filter. Issue(#9590). | |
| 268 mirrors.forEach((dart2js_mirrors.Dart2JsFieldMirror mirror) { | |
| 269 if (includePrivateMembers || !isHidden(mirror)) { | |
| 270 var mirrorName = dart2js_util.nameOf(mirror); | |
| 271 data[mirrorName] = new Variable(mirrorName, mirror, owner); | |
| 272 } | |
| 273 }); | |
| 274 return data; | |
| 275 } | |
| 276 | |
| 277 /// Returns a map of [Method] objects constructed from [mirrorMap]. | |
| 278 /// The optional parameter [containingLibrary] is contains data for variables | |
| 279 /// defined at the top level of a library (potentially for exporting | |
| 280 /// purposes). | |
| 281 Map<String, Method> _createMethods(Iterable<MethodMirror> mirrors, | |
| 282 Indexable owner) { | |
| 283 var group = new Map<String, Method>(); | |
| 284 mirrors.forEach((MethodMirror mirror) { | |
| 285 if (includePrivateMembers || !mirror.isPrivate) { | |
| 286 group[dart2js_util.nameOf(mirror)] = new Method(mirror, owner); | |
| 287 } | |
| 288 }); | |
| 289 return group; | |
| 290 } | |
| 291 | |
| 292 /// Returns a map of [Parameter] objects constructed from [mirrorList]. | |
| 293 Map<String, Parameter> _createParameters(List<ParameterMirror> mirrorList, | |
| 294 Indexable owner) { | |
| 295 var data = {}; | |
| 296 mirrorList.forEach((ParameterMirror mirror) { | |
| 297 data[dart2js_util.nameOf(mirror)] = | |
| 298 new Parameter(mirror, owner._owningLibrary); | |
| 299 }); | |
| 300 return data; | |
| 301 } | |
| 302 | |
| 303 /// Returns a map of [Generic] objects constructed from the class mirror. | |
| 304 Map<String, Generic> _createGenerics(TypeMirror mirror) { | |
| 305 return new Map.fromIterable(mirror.typeVariables, | |
| 306 key: (e) => dart2js_util.nameOf(e), | |
| 307 value: (e) => new Generic(e)); | |
| 308 } | |
| 309 | |
| 310 /// Return an informative [Object.toString] for debugging. | |
| 311 String toString() => "${super.toString()}(${name.toString()})"; | |
| 312 | |
| 313 /// Return a map representation of this type. | 261 /// Return a map representation of this type. |
| 314 Map toMap(); | 262 Map toMap(); |
| 315 | 263 |
| 316 | |
| 317 /// Expand the method map [mapToExpand] into a more detailed map that | 264 /// Expand the method map [mapToExpand] into a more detailed map that |
| 318 /// separates out setters, getters, constructors, operators, and methods. | 265 /// separates out setters, getters, constructors, operators, and methods. |
| 319 Map _expandMethodMap(Map<String, Method> mapToExpand) => { | 266 Map _expandMethodMap(Map<String, Method> mapToExpand) => { |
| 320 'setters': recurseMap(filterMap(mapToExpand, | 267 'setters': recurseMap(filterMap(mapToExpand, |
| 321 (key, val) => val.mirror.isSetter)), | 268 (key, val) => val.mirror.isSetter)), |
| 322 'getters': recurseMap(filterMap(mapToExpand, | 269 'getters': recurseMap(filterMap(mapToExpand, |
| 323 (key, val) => val.mirror.isGetter)), | 270 (key, val) => val.mirror.isGetter)), |
| 324 'constructors': recurseMap(filterMap(mapToExpand, | 271 'constructors': recurseMap(filterMap(mapToExpand, |
| 325 (key, val) => val.mirror.isConstructor)), | 272 (key, val) => val.mirror.isConstructor)), |
| 326 'operators': recurseMap(filterMap(mapToExpand, | 273 'operators': recurseMap(filterMap(mapToExpand, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 346 /// Top-level variables in the library. | 293 /// Top-level variables in the library. |
| 347 Map<String, Variable> variables; | 294 Map<String, Variable> variables; |
| 348 | 295 |
| 349 /// Top-level functions in the library. | 296 /// Top-level functions in the library. |
| 350 Map<String, Method> functions; | 297 Map<String, Method> functions; |
| 351 | 298 |
| 352 String packageName = ''; | 299 String packageName = ''; |
| 353 bool _hasBeenCheckedForPackage = false; | 300 bool _hasBeenCheckedForPackage = false; |
| 354 String packageIntro; | 301 String packageIntro; |
| 355 | 302 |
| 356 Library get _owningLibrary => this; | 303 Library get owningLibrary => this; |
| 357 | 304 |
| 358 /// Returns the [Library] for the given [mirror] if it has already been | 305 /// Returns the [Library] for the given [mirror] if it has already been |
| 359 /// created, else creates it. | 306 /// created, else creates it. |
| 360 factory Library(LibraryMirror mirror) { | 307 factory Library(LibraryMirror mirror) { |
| 361 var library = getDocgenObject(mirror); | 308 var library = getDocgenObject(mirror); |
| 362 if (library is DummyMirror) { | 309 if (library is DummyMirror) { |
| 363 library = new Library._(mirror); | 310 library = new Library._(mirror); |
| 364 } | 311 } |
| 365 return library; | 312 return library; |
| 366 } | 313 } |
| 367 | 314 |
| 368 Library._(LibraryMirror libraryMirror) : super(libraryMirror) { | 315 Library._(LibraryMirror libraryMirror) : super(libraryMirror) { |
| 369 var exported = _calcExportedItems(libraryMirror); | 316 var exported = calcExportedItems(libraryMirror); |
| 370 var exportedClasses = _addAll(exported['classes'], | 317 var exportedClasses = addAll(exported['classes'], |
| 371 dart2js_util.typesOf(libraryMirror.declarations)); | 318 dart2js_util.typesOf(libraryMirror.declarations)); |
| 372 updateLibraryPackage(mirror); | 319 updateLibraryPackage(mirror); |
| 373 exportedClasses.forEach((String mirrorName, TypeMirror mirror) { | 320 exportedClasses.forEach((String mirrorName, TypeMirror mirror) { |
| 374 if (mirror is TypedefMirror) { | 321 if (mirror is TypedefMirror) { |
| 375 // This is actually a Dart2jsTypedefMirror, and it does define value, | 322 // This is actually a Dart2jsTypedefMirror, and it does define value, |
| 376 // but we don't have visibility to that type. | 323 // but we don't have visibility to that type. |
| 377 if (includePrivateMembers || !mirror.isPrivate) { | 324 if (includePrivateMembers || !mirror.isPrivate) { |
| 378 typedefs[dart2js_util.nameOf(mirror)] = new Typedef(mirror, this); | 325 typedefs[dart2js_util.nameOf(mirror)] = new Typedef(mirror, this); |
| 379 } | 326 } |
| 380 } else if (mirror is ClassMirror) { | 327 } else if (mirror is ClassMirror) { |
| 381 var clazz = new Class(mirror, this); | 328 var clazz = new Class(mirror, this); |
| 382 | 329 |
| 383 if (clazz.isError()) { | 330 if (clazz.isError()) { |
| 384 errors[dart2js_util.nameOf(mirror)] = clazz; | 331 errors[dart2js_util.nameOf(mirror)] = clazz; |
| 385 } else { | 332 } else { |
| 386 classes[dart2js_util.nameOf(mirror)] = clazz; | 333 classes[dart2js_util.nameOf(mirror)] = clazz; |
| 387 } | 334 } |
| 388 } else { | 335 } else { |
| 389 throw new ArgumentError( | 336 throw new ArgumentError( |
| 390 '${dart2js_util.nameOf(mirror)} - no class type match. '); | 337 '${dart2js_util.nameOf(mirror)} - no class type match. '); |
| 391 } | 338 } |
| 392 }); | 339 }); |
| 393 this.functions = _createMethods(_addAll(exported['methods'], | 340 this.functions = createMethods(addAll(exported['methods'], |
| 394 libraryMirror.declarations.values.where( | 341 libraryMirror.declarations.values.where( |
| 395 (mirror) => mirror is MethodMirror)).values, this); | 342 (mirror) => mirror is MethodMirror)).values, this); |
| 396 this.variables = _createVariables(_addAll(exported['variables'], | 343 this.variables = createVariables(addAll(exported['variables'], |
| 397 dart2js_util.variablesOf(libraryMirror.declarations)).values, this); | 344 dart2js_util.variablesOf(libraryMirror.declarations)).values, this); |
| 398 } | 345 } |
| 399 | 346 |
| 400 /// Look for the specified name starting with the current member, and | 347 /// Look for the specified name starting with the current member, and |
| 401 /// progressively working outward to the current library scope. | 348 /// progressively working outward to the current library scope. |
| 402 String findElementInScope(String name) { | 349 String findElementInScope(String name) { |
| 403 var lookupFunc = determineLookupFunc(name); | 350 var lookupFunc = determineLookupFunc(name); |
| 404 var libraryScope = lookupFunc(mirror, name); | 351 var libraryScope = lookupFunc(mirror, name); |
| 405 if (libraryScope != null) { | 352 if (libraryScope != null) { |
| 406 var result = getDocgenObject(libraryScope, this); | 353 var result = getDocgenObject(libraryScope, this); |
| 407 if (result is DummyMirror) return packagePrefix + result.docName; | 354 if (result is DummyMirror) return packagePrefix + result.docName; |
| 408 return result.packagePrefix + result.docName; | 355 return result.packagePrefix + result.docName; |
| 409 } | 356 } |
| 410 return super.findElementInScope(name); | 357 return super.findElementInScope(name); |
| 411 } | 358 } |
| 412 | 359 |
| 413 String _mdnComment() => ''; | 360 String _mdnComment() => ''; |
| 414 | 361 |
| 415 /// Helper that maps [mirrors] to their simple name in map. | |
| 416 static Map _addAll(Map map, Iterable<DeclarationMirror> mirrors) { | |
| 417 for (var mirror in mirrors) { | |
| 418 map[dart2js_util.nameOf(mirror)] = mirror; | |
| 419 } | |
| 420 return map; | |
| 421 } | |
| 422 | |
| 423 /// For a library's [mirror], determine the name of the package (if any) we | 362 /// For a library's [mirror], determine the name of the package (if any) we |
| 424 /// believe it came from (because of its file URI). | 363 /// believe it came from (because of its file URI). |
| 425 /// | 364 /// |
| 426 /// If no package could be determined, we return an empty string. | 365 /// If no package could be determined, we return an empty string. |
| 427 void updateLibraryPackage(LibraryMirror mirror) { | 366 void updateLibraryPackage(LibraryMirror mirror) { |
| 428 if (mirror == null) return; | 367 if (mirror == null) return; |
| 429 if (_hasBeenCheckedForPackage) return; | 368 if (_hasBeenCheckedForPackage) return; |
| 430 _hasBeenCheckedForPackage = true; | 369 _hasBeenCheckedForPackage = true; |
| 431 if (mirror.uri.scheme != 'file') return; | 370 if (mirror.uri.scheme != 'file') return; |
| 432 packageName = getPackageName(mirror); | 371 packageName = getPackageName(mirror); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 465 } | 404 } |
| 466 return basic; | 405 return basic; |
| 467 } | 406 } |
| 468 | 407 |
| 469 String get name => docName; | 408 String get name => docName; |
| 470 | 409 |
| 471 String get docName { | 410 String get docName { |
| 472 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); | 411 return dart2js_util.qualifiedNameOf(mirror).replaceAll('.','-'); |
| 473 } | 412 } |
| 474 | 413 |
| 475 /// For the given library determine what items (if any) are exported. | |
| 476 /// | |
| 477 /// Returns a Map with three keys: "classes", "methods", and "variables" the | |
| 478 /// values of which point to a map of exported name identifiers with values | |
| 479 /// corresponding to the actual DeclarationMirror. | |
| 480 Map<String, Map<String, DeclarationMirror>> _calcExportedItems( | |
| 481 LibrarySourceMirror library) { | |
| 482 var exports = {}; | |
| 483 exports['classes'] = {}; | |
| 484 exports['methods'] = {}; | |
| 485 exports['variables'] = {}; | |
| 486 | |
| 487 // Determine the classes, variables and methods that are exported for a | |
| 488 // specific dependency. | |
| 489 void _populateExports(LibraryDependencyMirror export, bool showExport) { | |
| 490 if (!showExport) { | |
| 491 // Add all items, and then remove the hidden ones. | |
| 492 // Ex: "export foo hide bar" | |
| 493 _addAll(exports['classes'], | |
| 494 dart2js_util.typesOf(export.targetLibrary.declarations)); | |
| 495 _addAll(exports['methods'], | |
| 496 export.targetLibrary.declarations.values.where( | |
| 497 (mirror) => mirror is MethodMirror)); | |
| 498 _addAll(exports['variables'], | |
| 499 dart2js_util.variablesOf(export.targetLibrary.declarations)); | |
| 500 } | |
| 501 for (CombinatorMirror combinator in export.combinators) { | |
| 502 for (String identifier in combinator.identifiers) { | |
| 503 var librarySourceMirror = | |
| 504 export.targetLibrary as DeclarationSourceMirror; | |
| 505 var declaration = librarySourceMirror.lookupInScope(identifier); | |
| 506 if (declaration == null) { | |
| 507 // Technically this should be a bug, but some of our packages | |
| 508 // (such as the polymer package) are curently broken in this | |
| 509 // way, so we just produce a warning. | |
| 510 print('Warning identifier $identifier not found in library ' | |
| 511 '${dart2js_util.qualifiedNameOf(export.targetLibrary)}'); | |
| 512 } else { | |
| 513 var subMap = exports['classes']; | |
| 514 if (declaration is MethodMirror) { | |
| 515 subMap = exports['methods']; | |
| 516 } else if (declaration is VariableMirror) { | |
| 517 subMap = exports['variables']; | |
| 518 } | |
| 519 if (showExport) { | |
| 520 subMap[identifier] = declaration; | |
| 521 } else { | |
| 522 subMap.remove(identifier); | |
| 523 } | |
| 524 } | |
| 525 } | |
| 526 } | |
| 527 } | |
| 528 | |
| 529 Iterable<LibraryDependencyMirror> exportList = | |
| 530 library.libraryDependencies.where((lib) => lib.isExport); | |
| 531 for (LibraryDependencyMirror export in exportList) { | |
| 532 // If there is a show in the export, add only the show items to the | |
| 533 // library. Ex: "export foo show bar" | |
| 534 // Otherwise, add all items, and then remove the hidden ones. | |
| 535 // Ex: "export foo hide bar" | |
| 536 _populateExports(export, | |
| 537 export.combinators.any((combinator) => combinator.isShow)); | |
| 538 } | |
| 539 return exports; | |
| 540 } | |
| 541 | |
| 542 /// Checks if the given name is a key for any of the Class Maps. | 414 /// Checks if the given name is a key for any of the Class Maps. |
| 543 bool containsKey(String name) => | 415 bool containsKey(String name) => |
| 544 classes.containsKey(name) || errors.containsKey(name); | 416 classes.containsKey(name) || errors.containsKey(name); |
| 545 | 417 |
| 546 /// Generates a map describing the [Library] object. | 418 /// Generates a map describing the [Library] object. |
| 547 Map toMap() => { | 419 Map toMap() => { |
| 548 'name': name, | 420 'name': name, |
| 549 'qualifiedName': qualifiedName, | 421 'qualifiedName': qualifiedName, |
| 550 'comment': comment, | 422 'comment': comment, |
| 551 'variables': recurseMap(variables), | 423 'variables': recurseMap(variables), |
| 552 'functions': _expandMethodMap(functions), | 424 'functions': _expandMethodMap(functions), |
| 553 'classes': { | 425 'classes': { |
| 554 'class': classes.values.where((c) => c.isVisible) | 426 'class': classes.values.where((c) => c.isVisible) |
| 555 .map((e) => e.previewMap).toList(), | 427 .map((e) => e.previewMap).toList(), |
| 556 'typedef': recurseMap(typedefs), | 428 'typedef': recurseMap(typedefs), |
| 557 'error': errors.values.where((e) => e.isVisible) | 429 'error': errors.values.where((e) => e.isVisible) |
| 558 .map((e) => e.previewMap).toList() | 430 .map((e) => e.previewMap).toList() |
| 559 }, | 431 }, |
| 560 'packageName': packageName, | 432 'packageName': packageName, |
| 561 'packageIntro' : packageIntro | 433 'packageIntro' : packageIntro |
| 562 }; | 434 }; |
| 563 | 435 |
| 564 String get typeName => 'library'; | 436 String get typeName => 'library'; |
| 565 | 437 |
| 566 bool isValidMirror(DeclarationMirror mirror) => mirror is LibraryMirror; | 438 bool isValidMirror(DeclarationMirror mirror) => mirror is LibraryMirror; |
| 567 } | 439 } |
| 568 | 440 |
| 569 abstract class OwnedIndexable extends Indexable { | 441 abstract class OwnedIndexable<TMirror extends DeclarationMirror> |
| 442 extends Indexable<TMirror> { | |
| 443 /// List of the meta annotations on this item. | |
| 444 final List<Annotation> annotations; | |
| 445 | |
| 570 /// The object one scope-level above which this item is defined. | 446 /// The object one scope-level above which this item is defined. |
| 571 /// | 447 /// |
| 572 /// Ex: The owner for a top level class, would be its enclosing library. | 448 /// Ex: The owner for a top level class, would be its enclosing library. |
| 573 /// The owner of a local variable in a method would be the enclosing method. | 449 /// The owner of a local variable in a method would be the enclosing method. |
| 574 Indexable owner; | 450 final Indexable owner; |
| 575 | |
| 576 /// List of the meta annotations on this item. | |
| 577 List<Annotation> annotations; | |
| 578 | 451 |
| 579 /// Returns this object's qualified name, but following the conventions | 452 /// Returns this object's qualified name, but following the conventions |
| 580 /// we're using in Dartdoc, which is that library names with dots in them | 453 /// we're using in Dartdoc, which is that library names with dots in them |
| 581 /// have them replaced with hyphens. | 454 /// have them replaced with hyphens. |
| 582 String get docName => owner.docName + '.' + dart2js_util.nameOf(mirror); | 455 String get docName => owner.docName + '.' + dart2js_util.nameOf(mirror); |
| 583 | 456 |
| 584 OwnedIndexable(DeclarationMirror mirror, this.owner) : super(mirror); | 457 OwnedIndexable(DeclarationMirror mirror, Indexable owner) |
| 458 : annotations = createAnnotations(mirror, owner.owningLibrary), | |
| 459 this.owner = owner, | |
| 460 super(mirror); | |
| 585 | 461 |
| 586 /// Generates MDN comments from database.json. | 462 /// Generates MDN comments from database.json. |
| 587 String _mdnComment() { | 463 String _mdnComment() { |
| 588 var domAnnotation = this.annotations.firstWhere( | 464 var domAnnotation = this.annotations.firstWhere( |
| 589 (e) => e.mirror.qualifiedName == #metadata.DomName, | 465 (e) => e.mirror.qualifiedName == #metadata.DomName, |
| 590 orElse: () => null); | 466 orElse: () => null); |
| 591 if (domAnnotation == null) return ''; | 467 if (domAnnotation == null) return ''; |
| 592 var domName = domAnnotation.parameters.single; | 468 var domName = domAnnotation.parameters.single; |
| 593 | 469 |
| 594 return mdnComment(rootDirectory, logger, domName); | 470 return mdnComment(rootDirectory, logger, domName); |
| 595 } | 471 } |
| 596 | 472 |
| 597 String get packagePrefix => owner.packagePrefix; | 473 String get packagePrefix => owner.packagePrefix; |
| 598 } | 474 } |
| 599 | 475 |
| 600 /// A class containing contents of a Dart class. | 476 /// A class containing contents of a Dart class. |
| 601 class Class extends OwnedIndexable implements Comparable { | 477 class Class |
| 478 extends OwnedIndexable<dart2js_mirrors.Dart2JsInterfaceTypeMirror> | |
| 479 implements Comparable<Class> { | |
| 602 | 480 |
| 603 /// List of the names of interfaces that this class implements. | 481 /// List of the names of interfaces that this class implements. |
| 604 List<Class> interfaces = []; | 482 List<Class> interfaces = []; |
| 605 | 483 |
| 606 /// Names of classes that extends or implements this class. | 484 /// Names of classes that extends or implements this class. |
| 607 Set<Class> subclasses = new Set<Class>(); | 485 Set<Class> subclasses = new Set<Class>(); |
| 608 | 486 |
| 609 /// Top-level variables in the class. | 487 /// Top-level variables in the class. |
| 610 Map<String, Variable> variables; | 488 Map<String, Variable> variables; |
| 611 | 489 |
| 612 /// Inherited variables in the class. | 490 /// Inherited variables in the class. |
| 613 Map<String, Variable> inheritedVariables; | 491 final Map<String, Variable> inheritedVariables = {}; |
| 614 | 492 |
| 615 /// Methods in the class. | 493 /// Methods in the class. |
| 616 Map<String, Method> methods; | 494 Map<String, Method> methods; |
| 617 | 495 |
| 618 Map<String, Method> inheritedMethods; | 496 final Map<String, Method> inheritedMethods = new Map<String, Method>(); |
| 619 | 497 |
| 620 /// Generic infomation about the class. | 498 /// Generic infomation about the class. |
| 621 Map<String, Generic> generics; | 499 final Map<String, Generic> generics; |
| 622 | 500 |
| 623 Class superclass; | 501 Class superclass; |
| 624 bool isAbstract; | 502 bool get isAbstract => mirror.isAbstract; |
| 625 | 503 |
| 626 /// Make sure that we don't check for inherited comments more than once. | 504 /// Make sure that we don't check for inherited comments more than once. |
| 627 bool _commentsEnsured = false; | 505 bool _commentsEnsured = false; |
| 628 | 506 |
| 629 /// Returns the [Class] for the given [mirror] if it has already been created, | 507 /// Returns the [Class] for the given [mirror] if it has already been created, |
| 630 /// else creates it. | 508 /// else creates it. |
| 631 factory Class(ClassMirror mirror, Library owner) { | 509 factory Class(ClassMirror mirror, Library owner) { |
| 632 var clazz = getDocgenObject(mirror, owner); | 510 var clazz = getDocgenObject(mirror, owner); |
| 633 if (clazz is DummyMirror) { | 511 if (clazz is DummyMirror) { |
| 634 clazz = new Class._(mirror, owner); | 512 clazz = new Class._(mirror, owner); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 647 if (realOwner is Library) { | 525 if (realOwner is Library) { |
| 648 return new Class(mirror, realOwner); | 526 return new Class(mirror, realOwner); |
| 649 } else { | 527 } else { |
| 650 return new Class(mirror, originalOwner); | 528 return new Class(mirror, originalOwner); |
| 651 } | 529 } |
| 652 } else { | 530 } else { |
| 653 return new Class(mirror, originalOwner); | 531 return new Class(mirror, originalOwner); |
| 654 } | 532 } |
| 655 } | 533 } |
| 656 | 534 |
| 657 Class._(ClassSourceMirror classMirror, Indexable owner) : | 535 Class._(ClassSourceMirror classMirror, Indexable owner) |
| 658 super(classMirror, owner) { | 536 : generics = createGenerics(classMirror), |
| 659 inheritedVariables = {}; | 537 super(classMirror, owner) { |
| 660 | 538 |
| 661 // The reason we do this madness is the superclass and interface owners may | 539 // The reason we do this madness is the superclass and interface owners may |
| 662 // not be this class's owner!! Example: BaseClient in http pkg. | 540 // not be this class's owner!! Example: BaseClient in http pkg. |
| 663 var superinterfaces = classMirror.superinterfaces.map( | 541 var superinterfaces = classMirror.superinterfaces.map( |
| 664 (interface) => new Class._possiblyDifferentOwner(interface, owner)); | 542 (interface) => new Class._possiblyDifferentOwner(interface, owner)); |
| 665 this.superclass = classMirror.superclass == null? null : | 543 this.superclass = classMirror.superclass == null? null : |
| 666 new Class._possiblyDifferentOwner(classMirror.superclass, owner); | 544 new Class._possiblyDifferentOwner(classMirror.superclass, owner); |
| 667 | 545 |
| 668 interfaces = superinterfaces.toList(); | 546 interfaces = superinterfaces.toList(); |
| 669 variables = _createVariables( | 547 variables = createVariables( |
| 670 dart2js_util.variablesOf(classMirror.declarations), this); | 548 dart2js_util.variablesOf(classMirror.declarations), this); |
| 671 methods = _createMethods(classMirror.declarations.values.where( | 549 methods = createMethods(classMirror.declarations.values.where( |
| 672 (mirror) => mirror is MethodMirror), this); | 550 (mirror) => mirror is MethodMirror), this); |
| 673 annotations = createAnnotations(classMirror, owner._owningLibrary); | |
| 674 generics = _createGenerics(classMirror); | |
| 675 isAbstract = classMirror.isAbstract; | |
| 676 inheritedMethods = new Map<String, Method>(); | |
| 677 | 551 |
| 678 // Tell superclass that you are a subclass, unless you are not | 552 // Tell superclass that you are a subclass, unless you are not |
| 679 // visible or an intermediary mixin class. | 553 // visible or an intermediary mixin class. |
| 680 if (!classMirror.isNameSynthetic && isVisible && superclass != null) { | 554 if (!classMirror.isNameSynthetic && isVisible && superclass != null) { |
| 681 superclass.addSubclass(this); | 555 superclass.addSubclass(this); |
| 682 } | 556 } |
| 683 | 557 |
| 684 if (this.superclass != null) addInherited(superclass); | 558 if (this.superclass != null) addInherited(superclass); |
| 685 interfaces.forEach((interface) => addInherited(interface)); | 559 interfaces.forEach((interface) => addInherited(interface)); |
| 686 } | 560 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 'subclass': (subclasses.toList()..sort()) | 692 'subclass': (subclasses.toList()..sort()) |
| 819 .map((x) => x.qualifiedName).toList(), | 693 .map((x) => x.qualifiedName).toList(), |
| 820 'variables': recurseMap(variables), | 694 'variables': recurseMap(variables), |
| 821 'inheritedVariables': recurseMap(inheritedVariables), | 695 'inheritedVariables': recurseMap(inheritedVariables), |
| 822 'methods': _expandMethodMap(methods), | 696 'methods': _expandMethodMap(methods), |
| 823 'inheritedMethods': _expandMethodMap(inheritedMethods), | 697 'inheritedMethods': _expandMethodMap(inheritedMethods), |
| 824 'annotations': annotations.map((a) => a.toMap()).toList(), | 698 'annotations': annotations.map((a) => a.toMap()).toList(), |
| 825 'generics': recurseMap(generics) | 699 'generics': recurseMap(generics) |
| 826 }; | 700 }; |
| 827 | 701 |
| 828 int compareTo(aClass) => name.compareTo(aClass.name); | 702 int compareTo(Class other) => name.compareTo(other.name); |
| 829 | 703 |
| 830 bool isValidMirror(DeclarationMirror mirror) => mirror is ClassMirror; | 704 bool isValidMirror(DeclarationMirror mirror) => mirror is ClassMirror; |
| 831 } | 705 } |
| 832 | 706 |
| 833 class Typedef extends OwnedIndexable { | 707 class Typedef extends OwnedIndexable { |
| 834 String returnType; | 708 final String returnType; |
| 835 | 709 |
| 836 Map<String, Parameter> parameters; | 710 final Map<String, Parameter> parameters; |
| 837 | 711 |
| 838 /// Generic information about the typedef. | 712 /// Generic information about the typedef. |
| 839 Map<String, Generic> generics; | 713 final Map<String, Generic> generics; |
| 840 | 714 |
| 841 /// Returns the [Library] for the given [mirror] if it has already been | 715 /// Returns the [Library] for the given [mirror] if it has already been |
| 842 /// created, else creates it. | 716 /// created, else creates it. |
| 843 factory Typedef(TypedefMirror mirror, Library owningLibrary) { | 717 factory Typedef(TypedefMirror mirror, Library owningLibrary) { |
| 844 var aTypedef = getDocgenObject(mirror, owningLibrary); | 718 var aTypedef = getDocgenObject(mirror, owningLibrary); |
| 845 if (aTypedef is DummyMirror) { | 719 if (aTypedef is DummyMirror) { |
| 846 aTypedef = new Typedef._(mirror, owningLibrary); | 720 aTypedef = new Typedef._(mirror, owningLibrary); |
| 847 } | 721 } |
| 848 return aTypedef; | 722 return aTypedef; |
| 849 } | 723 } |
| 850 | 724 |
| 851 Typedef._(TypedefMirror mirror, Library owningLibrary) : | 725 Typedef._(TypedefMirror mirror, Library owningLibrary) |
| 852 super(mirror, owningLibrary) { | 726 : returnType = getDocgenObject(mirror.referent.returnType).docName, |
| 853 returnType = getDocgenObject(mirror.referent.returnType).docName; | 727 generics = createGenerics(mirror), |
| 854 generics = _createGenerics(mirror); | 728 parameters = createParameters(mirror.referent.parameters, |
| 855 parameters = _createParameters(mirror.referent.parameters, owningLibrary); | 729 owningLibrary), |
| 856 annotations = createAnnotations(mirror, owningLibrary); | 730 super(mirror, owningLibrary); |
| 857 } | |
| 858 | 731 |
| 859 Map toMap() { | 732 Map toMap() { |
| 860 var map = { | 733 var map = { |
| 861 'name': name, | 734 'name': name, |
| 862 'qualifiedName': qualifiedName, | 735 'qualifiedName': qualifiedName, |
| 863 'comment': comment, | 736 'comment': comment, |
| 864 'return': returnType, | 737 'return': returnType, |
| 865 'parameters': recurseMap(parameters), | 738 'parameters': recurseMap(parameters), |
| 866 'annotations': annotations.map((a) => a.toMap()).toList(), | 739 'annotations': annotations.map((a) => a.toMap()).toList(), |
| 867 'generics': recurseMap(generics) | 740 'generics': recurseMap(generics) |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 898 return new Variable._(variableName, mirror, owner); | 771 return new Variable._(variableName, mirror, owner); |
| 899 } | 772 } |
| 900 return variable; | 773 return variable; |
| 901 } | 774 } |
| 902 | 775 |
| 903 Variable._(this._variableName, VariableMirror mirror, Indexable owner) : | 776 Variable._(this._variableName, VariableMirror mirror, Indexable owner) : |
| 904 super(mirror, owner) { | 777 super(mirror, owner) { |
| 905 isFinal = mirror.isFinal; | 778 isFinal = mirror.isFinal; |
| 906 isStatic = mirror.isStatic; | 779 isStatic = mirror.isStatic; |
| 907 isConst = mirror.isConst; | 780 isConst = mirror.isConst; |
| 908 type = new Type(mirror.type, owner._owningLibrary); | 781 type = new Type(mirror.type, owner.owningLibrary); |
| 909 annotations = createAnnotations(mirror, owner._owningLibrary); | |
| 910 } | 782 } |
| 911 | 783 |
| 912 String get name => _variableName; | 784 String get name => _variableName; |
| 913 | 785 |
| 914 /// Generates a map describing the [Variable] object. | 786 /// Generates a map describing the [Variable] object. |
| 915 Map toMap() => { | 787 Map toMap() => { |
| 916 'name': name, | 788 'name': name, |
| 917 'qualifiedName': qualifiedName, | 789 'qualifiedName': qualifiedName, |
| 918 'comment': comment, | 790 'comment': comment, |
| 919 'final': isFinal, | 791 'final': isFinal, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 return super.findElementInScope(name); | 823 return super.findElementInScope(name); |
| 952 } | 824 } |
| 953 | 825 |
| 954 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror; | 826 bool isValidMirror(DeclarationMirror mirror) => mirror is VariableMirror; |
| 955 } | 827 } |
| 956 | 828 |
| 957 /// A class containing properties of a Dart method. | 829 /// A class containing properties of a Dart method. |
| 958 class Method extends OwnedIndexable { | 830 class Method extends OwnedIndexable { |
| 959 | 831 |
| 960 /// Parameters for this method. | 832 /// Parameters for this method. |
| 961 Map<String, Parameter> parameters; | 833 final Map<String, Parameter> parameters; |
| 962 | 834 |
| 963 bool isStatic; | 835 final bool isStatic; |
| 964 bool isAbstract; | 836 final bool isAbstract; |
| 965 bool isConst; | 837 final bool isConst; |
| 966 Type returnType; | 838 final Type returnType; |
| 967 Method methodInheritedFrom; | 839 Method methodInheritedFrom; |
| 968 | 840 |
| 969 /// Qualified name to state where the comment is inherited from. | 841 /// Qualified name to state where the comment is inherited from. |
| 970 String commentInheritedFrom = ""; | 842 String commentInheritedFrom = ""; |
| 971 | 843 |
| 972 factory Method(MethodMirror mirror, Indexable owner, | 844 factory Method(MethodMirror mirror, Indexable owner, |
| 973 [Method methodInheritedFrom]) { | 845 [Method methodInheritedFrom]) { |
| 974 var method = getDocgenObject(mirror, owner); | 846 var method = getDocgenObject(mirror, owner); |
| 975 if (method is DummyMirror) { | 847 if (method is DummyMirror) { |
| 976 method = new Method._(mirror, owner, methodInheritedFrom); | 848 method = new Method._(mirror, owner, methodInheritedFrom); |
| 977 } | 849 } |
| 978 return method; | 850 return method; |
| 979 } | 851 } |
| 980 | 852 |
| 981 Method._(MethodMirror mirror, Indexable owner, this.methodInheritedFrom) | 853 Method._(MethodMirror mirror, Indexable owner, this.methodInheritedFrom) |
| 982 : super(mirror, owner) { | 854 : returnType = new Type(mirror.returnType, owner.owningLibrary), |
| 983 isStatic = mirror.isStatic; | 855 isStatic = mirror.isStatic, |
| 984 isAbstract = mirror.isAbstract; | 856 isAbstract = mirror.isAbstract, |
| 985 isConst = mirror.isConstConstructor; | 857 isConst = mirror.isConstConstructor, |
| 986 returnType = new Type(mirror.returnType, owner._owningLibrary); | 858 parameters = createParameters(mirror.parameters, owner), |
| 987 parameters = _createParameters(mirror.parameters, owner); | 859 super(mirror, owner); |
| 988 annotations = createAnnotations(mirror, owner._owningLibrary); | |
| 989 } | |
| 990 | 860 |
| 991 Method get originallyInheritedFrom => methodInheritedFrom == null ? | 861 Method get originallyInheritedFrom => methodInheritedFrom == null ? |
| 992 this : methodInheritedFrom.originallyInheritedFrom; | 862 this : methodInheritedFrom.originallyInheritedFrom; |
| 993 | 863 |
| 994 /// Look for the specified name starting with the current member, and | 864 /// Look for the specified name starting with the current member, and |
| 995 /// progressively working outward to the current library scope. | 865 /// progressively working outward to the current library scope. |
| 996 String findElementInScope(String name) { | 866 String findElementInScope(String name) { |
| 997 var lookupFunc = determineLookupFunc(name); | 867 var lookupFunc = determineLookupFunc(name); |
| 998 | 868 |
| 999 var memberScope = lookupFunc(this.mirror, name); | 869 var memberScope = lookupFunc(this.mirror, name); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 'qualifiedName': qualifiedName, | 917 'qualifiedName': qualifiedName, |
| 1048 'comment': comment, | 918 'comment': comment, |
| 1049 'commentFrom': (methodInheritedFrom != null && | 919 'commentFrom': (methodInheritedFrom != null && |
| 1050 commentInheritedFrom == methodInheritedFrom.docName ? '' | 920 commentInheritedFrom == methodInheritedFrom.docName ? '' |
| 1051 : commentInheritedFrom), | 921 : commentInheritedFrom), |
| 1052 'inheritedFrom': (methodInheritedFrom == null? '' : | 922 'inheritedFrom': (methodInheritedFrom == null? '' : |
| 1053 originallyInheritedFrom.docName), | 923 originallyInheritedFrom.docName), |
| 1054 'static': isStatic, | 924 'static': isStatic, |
| 1055 'abstract': isAbstract, | 925 'abstract': isAbstract, |
| 1056 'constant': isConst, | 926 'constant': isConst, |
| 1057 'return': new List.filled(1, returnType.toMap()), | 927 'return': [returnType.toMap()], |
| 1058 'parameters': recurseMap(parameters), | 928 'parameters': recurseMap(parameters), |
| 1059 'annotations': annotations.map((a) => a.toMap()).toList() | 929 'annotations': annotations.map((a) => a.toMap()).toList() |
| 1060 }; | 930 }; |
| 1061 | 931 |
| 1062 String get typeName { | 932 String get typeName { |
| 1063 MethodMirror theMirror = mirror; | 933 MethodMirror theMirror = mirror; |
| 1064 if (theMirror.isConstructor) return 'constructor'; | 934 if (theMirror.isConstructor) return 'constructor'; |
| 1065 if (theMirror.isGetter) return 'getter'; | 935 if (theMirror.isGetter) return 'getter'; |
| 1066 if (theMirror.isSetter) return'setter'; | 936 if (theMirror.isSetter) return'setter'; |
| 1067 if (theMirror.isOperator) return 'operator'; | 937 if (theMirror.isOperator) return 'operator'; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1156 /// - "outer" : "dart-core.List" | 1026 /// - "outer" : "dart-core.List" |
| 1157 /// "inner" : | 1027 /// "inner" : |
| 1158 /// - "outer" : "dart-core.int" | 1028 /// - "outer" : "dart-core.int" |
| 1159 /// "inner" : | 1029 /// "inner" : |
| 1160 class Type extends MirrorBased { | 1030 class Type extends MirrorBased { |
| 1161 final TypeMirror mirror; | 1031 final TypeMirror mirror; |
| 1162 final Library owningLibrary; | 1032 final Library owningLibrary; |
| 1163 | 1033 |
| 1164 Type(this.mirror, this.owningLibrary); | 1034 Type(this.mirror, this.owningLibrary); |
| 1165 | 1035 |
| 1166 /// Returns a list of [Type] objects constructed from TypeMirrors. | |
| 1167 List<Type> _createTypeGenerics(TypeMirror mirror) { | |
| 1168 if (mirror is ClassMirror) { | |
| 1169 var innerList = []; | |
| 1170 mirror.typeArguments.forEach((e) { | |
| 1171 innerList.add(new Type(e, owningLibrary)); | |
| 1172 }); | |
| 1173 return innerList; | |
| 1174 } | |
| 1175 return []; | |
| 1176 } | |
| 1177 | |
| 1178 Map toMap() { | 1036 Map toMap() { |
| 1179 var result = getDocgenObject(mirror, owningLibrary); | 1037 var result = getDocgenObject(mirror, owningLibrary); |
| 1180 return { | 1038 return { |
| 1181 // We may encounter types whose corresponding library has not been | 1039 // We may encounter types whose corresponding library has not been |
| 1182 // processed yet, so look up with the owningLibrary at the last moment. | 1040 // processed yet, so look up with the owningLibrary at the last moment. |
| 1183 'outer': result.packagePrefix + result.docName, | 1041 'outer': result.packagePrefix + result.docName, |
| 1184 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), | 1042 'inner': _createTypeGenerics(mirror).map((e) => e.toMap()).toList(), |
| 1185 }; | 1043 }; |
| 1186 } | 1044 } |
| 1045 | |
| 1046 /// Returns a list of [Type] objects constructed from TypeMirrors. | |
| 1047 List<Type> _createTypeGenerics(TypeMirror mirror) { | |
| 1048 if (mirror is! ClassMirror) return []; | |
| 1049 return mirror.typeArguments.map((e) => new Type(e, owningLibrary)).toList(); | |
| 1050 } | |
| 1187 } | 1051 } |
| 1188 | 1052 |
| 1189 /// Holds the name of the annotation, and its parameters. | 1053 /// Holds the name of the annotation, and its parameters. |
| 1190 class Annotation extends MirrorBased { | 1054 class Annotation extends MirrorBased { |
| 1191 /// The class of this annotation. | 1055 /// The class of this annotation. |
| 1192 final ClassMirror mirror; | 1056 final ClassMirror mirror; |
| 1193 final Library owningLibrary; | 1057 final Library owningLibrary; |
| 1194 List<String> parameters; | 1058 List<String> parameters; |
| 1195 | 1059 |
| 1196 Annotation(InstanceMirror originalMirror, this.owningLibrary) | 1060 Annotation(InstanceMirror originalMirror, this.owningLibrary) |
| 1197 : mirror = originalMirror.type { | 1061 : mirror = originalMirror.type { |
| 1198 parameters = dart2js_util.variablesOf(originalMirror.type.declarations) | 1062 parameters = dart2js_util.variablesOf(originalMirror.type.declarations) |
| 1199 .where((e) => e.isFinal) | 1063 .where((e) => e.isFinal) |
| 1200 .map((e) => originalMirror.getField(e.simpleName).reflectee) | 1064 .map((e) => originalMirror.getField(e.simpleName).reflectee) |
| 1201 .where((e) => e != null) | 1065 .where((e) => e != null) |
| 1202 .toList(); | 1066 .toList(); |
| 1203 } | 1067 } |
| 1204 | 1068 |
| 1205 Map toMap() => { | 1069 Map toMap() => { |
| 1206 'name': getDocgenObject(mirror, owningLibrary).docName, | 1070 'name': getDocgenObject(mirror, owningLibrary).docName, |
| 1207 'parameters': parameters | 1071 'parameters': parameters |
| 1208 }; | 1072 }; |
| 1209 } | 1073 } |
| OLD | NEW |