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 test.metadata_scope; | 5 library test.metadata_scope; |
6 | 6 |
7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 | 9 |
10 class Annotation { | 10 class Annotation { |
11 final contents; | 11 final contents; |
12 const Annotation(this.contents); | 12 const Annotation(this.contents); |
13 toString() => "Annotation($contents)"; | 13 toString() => "Annotation($contents)"; |
14 } | 14 } |
15 | 15 |
16 // Note there is no compile-time constant 'foo' in scope. In particular, A.foo | 16 // Note there is no compile-time constant 'foo' in scope. In particular, A.foo |
17 // is not in scope here. | 17 // is not in scope here. |
18 @Annotation(foo) // //# 01: compile-time error | 18 @Annotation(foo) // //# 01: compile-time error |
19 class A<@Annotation(foo) T> { | 19 class A <@Annotation(foo) T> { |
20 @Annotation(foo) | 20 @Annotation(foo) |
21 static foo() {} | 21 static foo() {} |
22 | 22 |
23 @Annotation(foo) | 23 @Annotation(foo) |
24 static bar() {} | 24 static bar() {} |
25 } | 25 } |
26 | 26 |
27 @Annotation(B.foo) | 27 @Annotation(B.foo) |
28 class B<@Annotation(B.foo) T> { | 28 class B <@Annotation(B.foo) T> { |
29 @Annotation(B.foo) | 29 @Annotation(B.foo) |
30 static foo() {} | 30 static foo() {} |
31 | 31 |
32 @Annotation(B.foo) | 32 @Annotation(B.foo) |
33 static bar() {} | 33 static bar() {} |
34 } | 34 } |
35 | 35 |
36 baz() {} | 36 baz() {} |
37 | 37 |
38 // Note the top-level function baz is in scope here, not C.baz. | 38 // Note the top-level function baz is in scope here, not C.baz. |
39 @Annotation(baz) | 39 @Annotation(baz) |
40 class C<@Annotation(baz) T> { | 40 class C <@Annotation(baz) T> { |
41 @Annotation(baz) | 41 @Annotation(baz) |
42 static baz() {} | 42 static baz() {} |
43 } | 43 } |
44 | 44 |
45 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | 45 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
46 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); | 46 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); |
47 } | 47 } |
48 | 48 |
49 main() { | 49 main() { |
50 reflectClass(A).metadata; | 50 reflectClass(A).metadata; |
51 checkMetadata(reflectClass(A).declarations[#T], [const Annotation(A.foo)]); | 51 checkMetadata(reflectClass(A).declarations[#T], [const Annotation(A.foo)]); |
52 checkMetadata(reflectClass(A).declarations[#foo], [const Annotation(A.foo)]); | 52 checkMetadata(reflectClass(A).declarations[#foo], [const Annotation(A.foo)]); |
53 checkMetadata(reflectClass(A).declarations[#bar], [const Annotation(A.foo)]); | 53 checkMetadata(reflectClass(A).declarations[#bar], [const Annotation(A.foo)]); |
54 checkMetadata(reflectClass(B), [const Annotation(B.foo)]); | 54 checkMetadata(reflectClass(B), [const Annotation(B.foo)]); |
55 checkMetadata(reflectClass(B).declarations[#T], [const Annotation(B.foo)]); | 55 checkMetadata(reflectClass(B).declarations[#T], [const Annotation(B.foo)]); |
56 checkMetadata(reflectClass(B).declarations[#foo], [const Annotation(B.foo)]); | 56 checkMetadata(reflectClass(B).declarations[#foo], [const Annotation(B.foo)]); |
57 checkMetadata(reflectClass(B).declarations[#bar], [const Annotation(B.foo)]); | 57 checkMetadata(reflectClass(B).declarations[#bar], [const Annotation(B.foo)]); |
58 // The top-level function baz, not C.baz. | 58 // The top-level function baz, not C.baz. |
59 checkMetadata(reflectClass(C), [const Annotation(baz)]); | 59 checkMetadata(reflectClass(C), [const Annotation(baz)]); |
60 // C.baz, not the top-level function baz. | 60 // C.baz, not the top-level function baz. |
61 checkMetadata(reflectClass(C).declarations[#T], [const Annotation(C.baz)]); | 61 checkMetadata(reflectClass(C).declarations[#T], [const Annotation(C.baz)]); |
62 checkMetadata(reflectClass(C).declarations[#baz], [const Annotation(C.baz)]); | 62 checkMetadata(reflectClass(C).declarations[#baz], [const Annotation(C.baz)]); |
63 } | 63 } |
OLD | NEW |