Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Unified Diff: tests/lib/mirrors/parameter_annotation_mirror_test.dart

Issue 160343002: Implement reflection on annotations of parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comment. Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/lib/js_mirrors.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/mirrors/parameter_annotation_mirror_test.dart
diff --git a/tests/lib/mirrors/parameter_annotation_mirror_test.dart b/tests/lib/mirrors/parameter_annotation_mirror_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c0a625ad80072c846f24ddc58fa4e64deb841a12
--- /dev/null
+++ b/tests/lib/mirrors/parameter_annotation_mirror_test.dart
@@ -0,0 +1,48 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+@MirrorsUsed(targets: "Foo")
+import "dart:mirrors";
+
+import 'package:expect/expect.dart';
+
+class ParameterAnnotation {
+ final String value;
+ const ParameterAnnotation(this.value);
+}
+
+class Foo {
+ f1(@ParameterAnnotation("hest") p) {}
+ f2(@ParameterAnnotation("hest") @ParameterAnnotation("fisk") p) {}
+ f3(a, @ParameterAnnotation("fugl") p) {}
+ f4(@ParameterAnnotation("fisk") a,
+ {@ParameterAnnotation("hval") p}) {}
+ f5(@ParameterAnnotation("fisk") a,
+ [@ParameterAnnotation("hval") p]) {}
+}
+
+expectAnnotations(Type type, Symbol method, int parameterIndex,
+ List<String> expectedValues) {
+ MethodMirror mirror = reflectClass(type).declarations[method];
+ ParameterMirror parameter = mirror.parameters[parameterIndex];
+ List<InstanceMirror> annotations = parameter.metadata;
+ Expect.equals(annotations.length, expectedValues.length,
+ "wrong number of parameter annotations");
+ for (int i = 0; i < annotations.length; i++) {
+ Expect.equals(expectedValues[i], annotations[i].reflectee.value,
+ "annotation #$i of parameter #$parameterIndex "
+ "of $type.$method.");
+ }
+}
+
+main() {
+ expectAnnotations(Foo, #f1, 0, ["hest"]);
+ expectAnnotations(Foo, #f2, 0, ["hest", "fisk"]);
+ expectAnnotations(Foo, #f3, 0, []);
+ expectAnnotations(Foo, #f3, 1, ["fugl"]);
+ expectAnnotations(Foo, #f4, 0, ["fisk"]);
+ expectAnnotations(Foo, #f4, 1, ["hval"]);
+ expectAnnotations(Foo, #f5, 0, ["fisk"]);
+ expectAnnotations(Foo, #f5, 1, ["hval"]);
+}
« no previous file with comments | « sdk/lib/_internal/lib/js_mirrors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698