Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.metadata_scope; | |
| 6 | |
| 7 import 'dart:mirrors'; | |
| 8 import 'package:expect/expect.dart'; | |
| 9 | |
| 10 class Annotation { | |
| 11 final contents; | |
| 12 const Annotation(this.contents); | |
| 13 toString() => "Annotation($contents)"; | |
| 14 } | |
| 15 | |
| 16 @Annotation(foo) /// 01: compile-time error | |
|
hausner
2014/03/28 22:25:33
Maybe a comment why this is a compile-time error?
rmacnak
2014/03/28 22:36:58
Done
| |
| 17 class A { | |
| 18 @Annotation(foo) | |
| 19 static foo() {} | |
| 20 | |
| 21 @Annotation(foo) | |
| 22 static bar() {} | |
| 23 } | |
| 24 | |
| 25 @Annotation(B.foo) | |
| 26 class B { | |
| 27 @Annotation(B.foo) | |
| 28 static foo() {} | |
| 29 | |
| 30 @Annotation(B.foo) | |
| 31 static bar() {} | |
| 32 } | |
| 33 | |
| 34 baz() {} | |
| 35 | |
| 36 @Annotation(baz) | |
|
hausner
2014/03/28 22:25:33
Comment to note that the baz in the metadata shoul
rmacnak
2014/03/28 22:36:58
Done
| |
| 37 class C { | |
| 38 @Annotation(baz) | |
| 39 static baz() {} | |
| 40 } | |
| 41 | |
| 42 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | |
| 43 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); | |
| 44 } | |
| 45 | |
| 46 main() { | |
| 47 reflectClass(A).metadata; | |
| 48 checkMetadata(reflectClass(A).declarations[#foo], [const Annotation(A.foo)]); | |
| 49 checkMetadata(reflectClass(A).declarations[#bar], [const Annotation(A.foo)]); | |
| 50 checkMetadata(reflectClass(B), [const Annotation(B.foo)]); | |
| 51 checkMetadata(reflectClass(B).declarations[#foo], [const Annotation(B.foo)]); | |
| 52 checkMetadata(reflectClass(B).declarations[#bar], [const Annotation(B.foo)]); | |
| 53 checkMetadata(reflectClass(C), [const Annotation(baz)]); | |
| 54 checkMetadata(reflectClass(C).declarations[#baz], [const Annotation(C.baz)]); | |
| 55 } | |
| OLD | NEW |