OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 // Regression test for Issue 13817. | 5 // Regression test for Issue 13817. |
6 | 6 |
7 library test.metadata_constructor_arguments; | 7 library test.metadata_constructor_arguments; |
8 | 8 |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
11 | 11 |
12 class Tag { | 12 class Tag { |
13 final name; | 13 final name; |
14 const Tag({named}) : this.name = named; | 14 const Tag({named}) : this.name = named; |
15 } | 15 } |
16 | 16 |
17 @Tag(named: undefined) /// 01: compile-time error | 17 @Tag(named: undefined) // /// 01: compile-time error |
18 class A {} | 18 class A {} |
19 | 19 |
20 @Tag(named: 'valid') | 20 @Tag(named: 'valid') |
21 class B {} | 21 class B {} |
22 | 22 |
23 @Tag(named: C.STATIC_FIELD) | 23 @Tag(named: C.STATIC_FIELD) |
24 class C { | 24 class C { |
25 static const STATIC_FIELD = 3; | 25 static const STATIC_FIELD = 3; |
26 } | 26 } |
27 | 27 |
28 @Tag(named: D.instanceMethod()) /// 02: compile-time error | 28 @Tag(named: D.instanceMethod()) // /// 02: compile-time error |
29 class D { | 29 class D { |
30 instanceMethod() {} | 30 instanceMethod() {} |
31 } | 31 } |
32 | 32 |
33 @Tag(named: instanceField) /// 03: compile-time error | 33 @Tag(named: instanceField) // /// 03: compile-time error |
34 class E { | 34 class E { |
35 var instanceField; | 35 var instanceField; |
36 } | 36 } |
37 | 37 |
38 @Tag(named: F.nonConstStaticField) /// 04: compile-time error | 38 @Tag(named: F.nonConstStaticField) // /// 04: compile-time error |
39 class F { | 39 class F { |
40 static var nonConstStaticField = 6; | 40 static var nonConstStaticField = 6; |
41 } | 41 } |
42 | 42 |
43 @Tag(named: instanceMethod) /// 05: compile-time error | 43 @Tag(named: instanceMethod) // /// 05: compile-time error |
44 class G { | 44 class G { |
45 instanceMethod() {} | 45 instanceMethod() {} |
46 } | 46 } |
47 | 47 |
48 @Tag(named: this) /// 06: compile-time error | 48 @Tag(named: this) // /// 06: compile-time error |
49 class H { | 49 class H { |
50 instanceMethod() {} | 50 instanceMethod() {} |
51 } | 51 } |
52 | 52 |
53 @Tag(named: super) /// 07: compile-time error | 53 @Tag(named: super) // /// 07: compile-time error |
54 class I { | 54 class I { |
55 instanceMethod() {} | 55 instanceMethod() {} |
56 } | 56 } |
57 | 57 |
58 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | 58 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
59 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); | 59 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); |
60 } | 60 } |
61 | 61 |
62 main() { | 62 main() { |
63 reflectClass(A).metadata; | 63 reflectClass(A).metadata; |
64 checkMetadata(reflectClass(B), [const Tag(named: 'valid')]); | 64 checkMetadata(reflectClass(B), [const Tag(named: 'valid')]); |
65 checkMetadata(reflectClass(C), [const Tag(named: C.STATIC_FIELD)]); | 65 checkMetadata(reflectClass(C), [const Tag(named: C.STATIC_FIELD)]); |
66 reflectClass(D).metadata; | 66 reflectClass(D).metadata; |
67 reflectClass(E).metadata; | 67 reflectClass(E).metadata; |
68 reflectClass(F).metadata; | 68 reflectClass(F).metadata; |
69 reflectClass(G).metadata; | 69 reflectClass(G).metadata; |
70 reflectClass(H).metadata; | 70 reflectClass(H).metadata; |
71 reflectClass(I).metadata; | 71 reflectClass(I).metadata; |
72 } | 72 } |
OLD | NEW |