| 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.parameter; | 5 library docgen.models.parameter; |
| 6 | 6 |
| 7 import '../exports/mirrors_util.dart' as dart2js_util; | 7 import '../exports/mirrors_util.dart' as dart2js_util; |
| 8 import '../exports/source_mirrors.dart'; | 8 import '../exports/source_mirrors.dart'; |
| 9 | 9 |
| 10 import 'annotation.dart'; | 10 import 'annotation.dart'; |
| 11 import 'closure.dart'; |
| 11 import 'doc_gen_type.dart'; | 12 import 'doc_gen_type.dart'; |
| 12 import 'library.dart'; | 13 import 'library.dart'; |
| 13 import 'mirror_based.dart'; | 14 import 'mirror_based.dart'; |
| 14 import 'model_helpers.dart'; | 15 import 'model_helpers.dart'; |
| 15 | 16 |
| 16 /// Docgen wrapper around the dart2js mirror for a Dart | 17 /// Docgen wrapper around the dart2js mirror for a Dart |
| 17 /// method/function parameter. | 18 /// method/function parameter. |
| 18 class Parameter extends MirrorBased { | 19 class Parameter extends MirrorBased { |
| 19 final ParameterMirror mirror; | 20 final ParameterMirror mirror; |
| 20 final String name; | 21 final String name; |
| 21 final bool isOptional; | 22 final bool isOptional; |
| 22 final bool isNamed; | 23 final bool isNamed; |
| 23 final bool hasDefaultValue; | 24 final bool hasDefaultValue; |
| 24 final DocGenType type; | 25 final DocGenType type; |
| 25 final String defaultValue; | 26 final String defaultValue; |
| 26 /// List of the meta annotations on the parameter. | 27 /// List of the meta annotations on the parameter. |
| 27 final List<Annotation> annotations; | 28 final List<Annotation> annotations; |
| 29 final Library owningLibrary; |
| 30 // Only non-null if this parameter is a function declaration. |
| 31 Closure functionDeclaration; |
| 28 | 32 |
| 29 Parameter(ParameterMirror mirror, Library owningLibrary) | 33 Parameter(ParameterMirror mirror, Library owningLibrary) |
| 30 : this.mirror = mirror, | 34 : this.mirror = mirror, |
| 31 name = dart2js_util.nameOf(mirror), | 35 name = dart2js_util.nameOf(mirror), |
| 32 isOptional = mirror.isOptional, | 36 isOptional = mirror.isOptional, |
| 33 isNamed = mirror.isNamed, | 37 isNamed = mirror.isNamed, |
| 34 hasDefaultValue = mirror.hasDefaultValue, | 38 hasDefaultValue = mirror.hasDefaultValue, |
| 35 defaultValue = getDefaultValue(mirror), | 39 defaultValue = getDefaultValue(mirror), |
| 36 type = new DocGenType(mirror.type, owningLibrary), | 40 type = new DocGenType(mirror.type, owningLibrary), |
| 37 annotations = createAnnotations(mirror, owningLibrary); | 41 annotations = createAnnotations(mirror, owningLibrary), |
| 42 owningLibrary = owningLibrary { |
| 43 if (mirror.type is FunctionTypeMirror) { |
| 44 functionDeclaration = |
| 45 new Closure(mirror.type as FunctionTypeMirror, owningLibrary); |
| 46 } |
| 47 } |
| 38 | 48 |
| 39 /// Generates a map describing the [Parameter] object. | 49 /// Generates a map describing the [Parameter] object. |
| 40 Map toMap() => { | 50 Map toMap() { |
| 41 'name': name, | 51 var map = { |
| 42 'optional': isOptional, | 52 'name': name, |
| 43 'named': isNamed, | 53 'optional': isOptional, |
| 44 'default': hasDefaultValue, | 54 'named': isNamed, |
| 45 'type': new List.filled(1, type.toMap()), | 55 'default': hasDefaultValue, |
| 46 'value': defaultValue, | 56 'type': new List.filled(1, type.toMap()), |
| 47 'annotations': annotations.map((a) => a.toMap()).toList() | 57 'value': defaultValue, |
| 48 }; | 58 'annotations': annotations.map((a) => a.toMap()).toList() |
| 49 } | 59 }; |
| 60 if (functionDeclaration != null) { |
| 61 map['functionDeclaration'] = functionDeclaration.toMap(); |
| 62 } |
| 63 return map; |
| 64 } |
| 65 } |
| OLD | NEW |