mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 15:21:54 +00:00
00b2e580a3
Bug: https://github.com/dart-lang/sdk/issues/40045 Change-Id: I597259b38684de87016f1e136723d24f4ac05420 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132440 Reviewed-by: Ben Konyi <bkonyi@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
65 lines
2.3 KiB
Dart
65 lines
2.3 KiB
Dart
// 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.
|
|
|
|
import "dart:mirrors";
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
class ParameterAnnotation {
|
|
final String value;
|
|
const ParameterAnnotation(this.value);
|
|
}
|
|
|
|
class Foo {
|
|
Foo(@ParameterAnnotation("vogel") p) {}
|
|
Foo.named(@ParameterAnnotation("hamster") p) {}
|
|
Foo.named2(
|
|
@ParameterAnnotation("hamster") p, @ParameterAnnotation("wurm") p2) {}
|
|
|
|
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]) {}
|
|
f6({@ParameterAnnotation("fisk") z, @ParameterAnnotation("hval") p}) {}
|
|
|
|
set s1(@ParameterAnnotation("cheval") p) {}
|
|
}
|
|
|
|
expectAnnotations(
|
|
Type type, Symbol method, int parameterIndex, List<String> expectedValues) {
|
|
MethodMirror mirror = reflectClass(type).declarations[method] as MethodMirror;
|
|
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, #Foo, 0, ["vogel"]);
|
|
expectAnnotations(Foo, #Foo.named, 0, ["hamster"]);
|
|
expectAnnotations(Foo, #Foo.named2, 0, ["hamster"]);
|
|
expectAnnotations(Foo, #Foo.named2, 1, ["wurm"]);
|
|
|
|
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"]);
|
|
expectAnnotations(Foo, #f6, 0, ["fisk"]);
|
|
expectAnnotations(Foo, #f6, 1, ["hval"]);
|
|
|
|
expectAnnotations(Foo, const Symbol('s1='), 0, ["cheval"]);
|
|
}
|