OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in |
| 3 // the LICENSE file. |
| 4 |
| 5 // File being transformed by the reflectable transformer. |
| 6 // Part of the entry point 'reflectors_test.dart'. |
| 7 // |
| 8 // Independence: The `MetaReflector` class is independent of the particular |
| 9 // entry point 'reflectors_test.dart' and its transitive closure, it could be |
| 10 // in a third-party package only depending on reflectable. |
| 11 |
| 12 library test_reflectable.test.meta_reflectors_scoping; |
| 13 |
| 14 import 'package:reflectable/reflectable.dart'; |
| 15 |
| 16 /// Used to provide access to reflectors associated with a given scope, |
| 17 /// which is a [String]. The connection is created by top level functions |
| 18 /// in the program with the annotation `@MetaReflector()`. Such a function |
| 19 /// must have type `F` where `typedef Iterable<Reflectable> F(String _)`, |
| 20 /// and it is assumed to return the set of reflectors which belong to the |
| 21 /// scope specified by the argument. |
| 22 class ScopeMetaReflector extends Reflectable { |
| 23 const ScopeMetaReflector() |
| 24 : super(const TopLevelInvokeMetaCapability(ScopeMetaReflector), |
| 25 declarationsCapability, libraryCapability); |
| 26 Set<Reflectable> reflectablesOfScope(String scope) { |
| 27 Set<Reflectable> result = new Set<Reflectable>(); |
| 28 for (LibraryMirror library in libraries.values) { |
| 29 for (DeclarationMirror declaration in library.declarations.values) { |
| 30 result.addAll(library.invoke(declaration.simpleName, [scope])); |
| 31 } |
| 32 } |
| 33 return result; |
| 34 } |
| 35 } |
OLD | NEW |