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 `ScopeMetaReflector` and `AllReflectorsMetaReflector` |
| 9 /// classes are independent of the particular entry point 'reflectors_test.dart' |
| 10 /// and its transitive closure, it could be in a third-party package only |
| 11 /// depending on reflectable. |
| 12 library test_reflectable.test.meta_reflectors_scoping; |
| 13 |
| 14 @GlobalQuantifyCapability(r"^reflectable.reflectable.Reflectable$", |
| 15 const AllReflectorsMetaReflector()) |
| 16 import 'package:reflectable/reflectable.dart'; |
| 17 |
| 18 /// Used to provide access to reflectors associated with a given scope, |
| 19 /// which is a [String]. The connection is created by top level functions |
| 20 /// in the program with the annotation `@MetaReflector()`. Such a function |
| 21 /// must have type `F` where `typedef Iterable<Reflectable> F(String _)`, |
| 22 /// and it is assumed to return the set of reflectors which belong to the |
| 23 /// scope specified by the argument. |
| 24 class ScopeMetaReflector extends Reflectable { |
| 25 const ScopeMetaReflector() |
| 26 : super(const TopLevelInvokeMetaCapability(ScopeMetaReflector), |
| 27 declarationsCapability, libraryCapability); |
| 28 Set<Reflectable> reflectablesOfScope(String scope) { |
| 29 Set<Reflectable> result = new Set<Reflectable>(); |
| 30 for (LibraryMirror library in libraries.values) { |
| 31 for (DeclarationMirror declaration in library.declarations.values) { |
| 32 result.addAll(library.invoke(declaration.simpleName, [scope])); |
| 33 } |
| 34 } |
| 35 return result; |
| 36 } |
| 37 } |
| 38 |
| 39 /// Used to get access to all reflectors. |
| 40 class AllReflectorsMetaReflector extends Reflectable { |
| 41 const AllReflectorsMetaReflector() |
| 42 : super(subtypeQuantifyCapability, newInstanceCapability); |
| 43 |
| 44 Set<Reflectable> get reflectors { |
| 45 Set<Reflectable> result = new Set<Reflectable>(); |
| 46 annotatedClasses.forEach((ClassMirror classMirror) { |
| 47 if (classMirror.isAbstract) return; |
| 48 Reflectable reflector = |
| 49 Reflectable.getInstance(classMirror.reflectedType); |
| 50 if (reflector != null) result.add(reflector); |
| 51 }); |
| 52 return result; |
| 53 } |
| 54 } |
OLD | NEW |