OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 /// Example illustrating how to use checked_mirrors, and how it works when you |
| 6 /// declare a symbol with [MirrorsUsed]. |
| 7 library checked_mirrors.example.symbol; |
| 8 |
| 9 import 'package:checked_mirrors/checked_mirrors.dart'; |
| 10 import 'package:checked_mirrors/control.dart' as control; |
| 11 import 'package:logging/logging.dart'; |
| 12 |
| 13 // Typically this annotation goes in an import to 'dart:mirrors', we would like |
| 14 // to put it in the import of checked_mirrors, but we moved it here until |
| 15 // dartbug.com/10360 is fixed. |
| 16 @MirrorsUsed(symbols: 'x') |
| 17 const checked_mirrors_workaround_for_issue_10360 = 0; |
| 18 |
| 19 var a = new A(); |
| 20 |
| 21 main() { |
| 22 // This loads up the rules declared with @MirrorsUsed. |
| 23 control.initialize(log: true); |
| 24 |
| 25 // Print the warnings to the console. |
| 26 Logger.root.onRecord.listen((r) => print(r)); |
| 27 |
| 28 // These are OK: |
| 29 MirrorSystem.getName(#x); |
| 30 MirrorSystem.getSymbol('x'); |
| 31 |
| 32 // These will issue a warning: |
| 33 MirrorSystem.getName(#y); |
| 34 MirrorSystem.getSymbol('y'); |
| 35 } |
OLD | NEW |