| 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 @MirrorsUsed(targets: "Foo") | 5 @MirrorsUsed(targets: "Foo") |
| 6 import "dart:mirrors"; | 6 import "dart:mirrors"; |
| 7 | 7 |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 | 9 |
| 10 class ParameterAnnotation { | 10 class ParameterAnnotation { |
| 11 final String value; | 11 final String value; |
| 12 const ParameterAnnotation(this.value); | 12 const ParameterAnnotation(this.value); |
| 13 } | 13 } |
| 14 | 14 |
| 15 class Foo { | 15 class Foo { |
| 16 f1(@ParameterAnnotation("hest") p) {} | 16 f1(@ParameterAnnotation("hest") p) {} |
| 17 f2(@ParameterAnnotation("hest") @ParameterAnnotation("fisk") p) {} | 17 f2(@ParameterAnnotation("hest") @ParameterAnnotation("fisk") p) {} |
| 18 f3(a, @ParameterAnnotation("fugl") p) {} | 18 f3(a, @ParameterAnnotation("fugl") p) {} |
| 19 f4(@ParameterAnnotation("fisk") a, | 19 f4(@ParameterAnnotation("fisk") a, |
| 20 {@ParameterAnnotation("hval") p}) {} | 20 {@ParameterAnnotation("hval") p}) {} |
| 21 f5(@ParameterAnnotation("fisk") a, | 21 f5(@ParameterAnnotation("fisk") a, |
| 22 [@ParameterAnnotation("hval") p]) {} | 22 [@ParameterAnnotation("hval") p]) {} |
| 23 f6({@ParameterAnnotation("fisk") z, | |
| 24 @ParameterAnnotation("hval") p}) {} | |
| 25 } | 23 } |
| 26 | 24 |
| 27 expectAnnotations(Type type, Symbol method, int parameterIndex, | 25 expectAnnotations(Type type, Symbol method, int parameterIndex, |
| 28 List<String> expectedValues) { | 26 List<String> expectedValues) { |
| 29 MethodMirror mirror = reflectClass(type).declarations[method]; | 27 MethodMirror mirror = reflectClass(type).declarations[method]; |
| 30 ParameterMirror parameter = mirror.parameters[parameterIndex]; | 28 ParameterMirror parameter = mirror.parameters[parameterIndex]; |
| 31 List<InstanceMirror> annotations = parameter.metadata; | 29 List<InstanceMirror> annotations = parameter.metadata; |
| 32 Expect.equals(annotations.length, expectedValues.length, | 30 Expect.equals(annotations.length, expectedValues.length, |
| 33 "wrong number of parameter annotations"); | 31 "wrong number of parameter annotations"); |
| 34 for (int i = 0; i < annotations.length; i++) { | 32 for (int i = 0; i < annotations.length; i++) { |
| 35 Expect.equals(expectedValues[i], annotations[i].reflectee.value, | 33 Expect.equals(expectedValues[i], annotations[i].reflectee.value, |
| 36 "annotation #$i of parameter #$parameterIndex " | 34 "annotation #$i of parameter #$parameterIndex " |
| 37 "of $type.$method."); | 35 "of $type.$method."); |
| 38 } | 36 } |
| 39 } | 37 } |
| 40 | 38 |
| 41 main() { | 39 main() { |
| 42 expectAnnotations(Foo, #f1, 0, ["hest"]); | 40 expectAnnotations(Foo, #f1, 0, ["hest"]); |
| 43 expectAnnotations(Foo, #f2, 0, ["hest", "fisk"]); | 41 expectAnnotations(Foo, #f2, 0, ["hest", "fisk"]); |
| 44 expectAnnotations(Foo, #f3, 0, []); | 42 expectAnnotations(Foo, #f3, 0, []); |
| 45 expectAnnotations(Foo, #f3, 1, ["fugl"]); | 43 expectAnnotations(Foo, #f3, 1, ["fugl"]); |
| 46 expectAnnotations(Foo, #f4, 0, ["fisk"]); | 44 expectAnnotations(Foo, #f4, 0, ["fisk"]); |
| 47 expectAnnotations(Foo, #f4, 1, ["hval"]); | 45 expectAnnotations(Foo, #f4, 1, ["hval"]); |
| 48 expectAnnotations(Foo, #f5, 0, ["fisk"]); | 46 expectAnnotations(Foo, #f5, 0, ["fisk"]); |
| 49 expectAnnotations(Foo, #f5, 1, ["hval"]); | 47 expectAnnotations(Foo, #f5, 1, ["hval"]); |
| 50 expectAnnotations(Foo, #f6, 0, ["fisk"]); | |
| 51 expectAnnotations(Foo, #f6, 1, ["hval"]); | |
| 52 } | 48 } |
| OLD | NEW |