Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // compile options: --emit-metadata | |
| 2 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | |
| 3 // for details. All rights reserved. Use of this source code is governed by a | |
| 4 // BSD-style license that can be found in the LICENSE file. | |
| 5 | |
| 6 // Run essentially the same test, but with emit-metadata compile option, | |
| 7 // which allows us to reflect on the fields. | |
| 8 import 'dart:mirrors'; | |
| 9 import 'package:expect/expect.dart'; | |
| 10 | |
| 11 import 'field_metadata_test.dart' as field_metadata_test; | |
| 12 import 'field_metadata_test.dart' show Foo, Bar; | |
| 13 | |
| 14 void main() { | |
| 15 // Make sure the other test still works. | |
| 16 field_metadata_test.main(); | |
| 17 | |
| 18 // Check that we can now relfect on the annotations. | |
|
vsm
2017/05/02 21:43:53
relfect -> reflect
Jennifer Messerly
2017/05/02 21:44:50
thanks! done :)
| |
| 19 dynamic f = new Foo(); | |
| 20 var members = reflect(f).type.declarations; | |
| 21 var bar = members[#x].metadata.first.reflectee as Bar; | |
| 22 Expect.equals(bar.name, 'bar'); | |
| 23 | |
| 24 var baz = members[#y].metadata.first.reflectee as Bar; | |
| 25 Expect.equals(baz.name, 'baz'); | |
| 26 } | |
| OLD | NEW |