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.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 String name; |
|
kevmoo
2014/05/06 23:05:08
Does this need to be mutable?
Emily Fortuna
2014/05/06 23:19:43
no longer. removed.
| |
| 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; | |
| 28 | 30 |
| 29 Parameter(ParameterMirror mirror, Library owningLibrary) | 31 Parameter(ParameterMirror mirror, Library owningLibrary) |
| 30 : this.mirror = mirror, | 32 : this.mirror = mirror, |
| 31 name = dart2js_util.nameOf(mirror), | 33 name = dart2js_util.nameOf(mirror), |
| 32 isOptional = mirror.isOptional, | 34 isOptional = mirror.isOptional, |
| 33 isNamed = mirror.isNamed, | 35 isNamed = mirror.isNamed, |
| 34 hasDefaultValue = mirror.hasDefaultValue, | 36 hasDefaultValue = mirror.hasDefaultValue, |
| 35 defaultValue = getDefaultValue(mirror), | 37 defaultValue = getDefaultValue(mirror), |
| 36 type = new DocGenType(mirror.type, owningLibrary), | 38 type = new DocGenType(mirror.type, owningLibrary), |
| 37 annotations = createAnnotations(mirror, owningLibrary); | 39 annotations = createAnnotations(mirror, owningLibrary), |
| 40 owningLibrary = owningLibrary; | |
| 38 | 41 |
| 39 /// Generates a map describing the [Parameter] object. | 42 /// Generates a map describing the [Parameter] object. |
| 40 Map toMap() => { | 43 Map toMap() { |
| 41 'name': name, | 44 var map = { |
| 42 'optional': isOptional, | 45 'name': name, |
| 43 'named': isNamed, | 46 'optional': isOptional, |
| 44 'default': hasDefaultValue, | 47 'named': isNamed, |
| 45 'type': new List.filled(1, type.toMap()), | 48 'default': hasDefaultValue, |
| 46 'value': defaultValue, | 49 'type': new List.filled(1, type.toMap()), |
| 47 'annotations': annotations.map((a) => a.toMap()).toList() | 50 'value': defaultValue, |
| 48 }; | 51 'annotations': annotations.map((a) => a.toMap()).toList() |
| 49 } | 52 }; |
| 53 if (mirror.type is FunctionTypeMirror) { | |
| 54 map['functionDeclaration'] = | |
| 55 new Closure(mirror.type as FunctionTypeMirror, owningLibrary).toMap(); | |
| 56 } | |
| 57 return map; | |
| 58 } | |
| 59 } | |
| OLD | NEW |