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.annotation; | 5 library docgen.models.annotation; |
| 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 '../library_helpers.dart'; | 10 import '../library_helpers.dart'; |
| 11 | 11 |
| 12 import 'library.dart'; | 12 import 'library.dart'; |
| 13 import 'mirror_based.dart'; | 13 import 'mirror_based.dart'; |
| 14 | 14 |
| 15 /// Holds the name of the annotation, and its parameters. | 15 /// Holds the name of the annotation, and its parameters. |
| 16 class Annotation extends MirrorBased { | 16 class Annotation extends MirrorBased<ClassMirror> { |
|
kevmoo
2014/04/20 21:34:54
Added a generic param to MirrorBased to improve ty
| |
| 17 /// The class of this annotation. | 17 /// The class of this annotation. |
| 18 final ClassMirror mirror; | 18 final ClassMirror mirror; |
| 19 final Library owningLibrary; | 19 final Library owningLibrary; |
| 20 List<String> parameters; | 20 final List<String> parameters; |
| 21 | 21 |
| 22 Annotation(InstanceMirror originalMirror, this.owningLibrary) | 22 Annotation(InstanceMirror originalMirror, this.owningLibrary) |
| 23 : mirror = originalMirror.type { | 23 : mirror = originalMirror.type, |
| 24 parameters = dart2js_util.variablesOf(originalMirror.type.declarations) | 24 parameters = _createParamaters(originalMirror); |
|
kevmoo
2014/04/20 21:34:54
popped this mountain of code into a helper
| |
| 25 .where((e) => e.isFinal) | |
| 26 .map((e) => originalMirror.getField(e.simpleName).reflectee) | |
| 27 .where((e) => e != null) | |
| 28 .toList(); | |
| 29 } | |
| 30 | 25 |
| 31 Map toMap() => { | 26 Map toMap() => { |
| 32 'name': getDocgenObject(mirror, owningLibrary).docName, | 27 'name': getDocgenObject(mirror, owningLibrary).docName, |
| 33 'parameters': parameters | 28 'parameters': parameters |
| 34 }; | 29 }; |
| 35 } | 30 } |
| 31 | |
| 32 List<String> _createParamaters(InstanceMirror originalMirror) { | |
| 33 return dart2js_util.variablesOf(originalMirror.type.declarations) | |
| 34 .where((e) => e.isFinal) | |
| 35 .map((e) => originalMirror.getField(e.simpleName).reflectee) | |
| 36 .where((e) => e != null) | |
| 37 .toList(); | |
| 38 } | |
| OLD | NEW |