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 @string @symbol | 5 @string @symbol |
6 library test.metadata_test; | 6 library test.metadata_test; |
7 | 7 |
8 import 'dart:mirrors'; | 8 import 'dart:mirrors'; |
9 | 9 |
10 const string = 'a metadata string'; | 10 const string = 'a metadata string'; |
11 | 11 |
12 const symbol = const Symbol('symbol'); | 12 const symbol = const Symbol('symbol'); |
13 | 13 |
14 const hest = 'hest'; | 14 const hest = 'hest'; |
15 | 15 |
16 @symbol @string | 16 @symbol @string |
17 class MyClass { | 17 class MyClass { |
18 @hest @hest @symbol | 18 @hest @hest @symbol |
19 var x; | 19 var x; |
| 20 var y; |
20 | 21 |
21 @string @symbol @string | 22 @string @symbol @string |
22 myMethod() => 1; | 23 myMethod() => 1; |
23 } | 24 } |
24 | 25 |
25 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | 26 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
26 List metadata = mirror.metadata.map((m) => m.reflectee).toList(); | 27 List metadata = mirror.metadata.map((m) => m.reflectee).toList(); |
27 if (metadata == null) { | 28 if (metadata == null) { |
28 throw 'Null metadata on $mirror'; | 29 throw 'Null metadata on $mirror'; |
29 } | 30 } |
(...skipping 25 matching lines...) Expand all Loading... |
55 ClassMirror myClassMirror = reflectClass(MyClass); | 56 ClassMirror myClassMirror = reflectClass(MyClass); |
56 checkMetadata(myClassMirror, [symbol, string]); | 57 checkMetadata(myClassMirror, [symbol, string]); |
57 ClosureMirror closure = reflect(main); | 58 ClosureMirror closure = reflect(main); |
58 checkMetadata(closure.function, [symbol, string, symbol]); | 59 checkMetadata(closure.function, [symbol, string, symbol]); |
59 closure = reflect(new MyClass().myMethod); | 60 closure = reflect(new MyClass().myMethod); |
60 checkMetadata(closure.function, [string, symbol, string]); | 61 checkMetadata(closure.function, [string, symbol, string]); |
61 | 62 |
62 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')]; | 63 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')]; |
63 checkMetadata(xMirror, [hest, hest, symbol]); | 64 checkMetadata(xMirror, [hest, hest, symbol]); |
64 | 65 |
| 66 VariableMirror yMirror = myClassMirror.variables[const Symbol('y')]; |
| 67 checkMetadata(yMirror, []); |
| 68 |
65 // TODO(ahe): Test local functions. | 69 // TODO(ahe): Test local functions. |
66 } | 70 } |
OLD | NEW |