Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: test_reflectable/test/reflectors_test.dart

Issue 1391543003: Creates `reflectors`, as a meta-meta feature that enables dynamic selection of a "mirror system". (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Review response. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test_reflectable/test/reflected_type_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 library test_reflectable.test.reflectors_test;
6
7 @GlobalQuantifyCapability(r".(A|B)$", const Reflector3())
8 @GlobalQuantifyMetaCapability(P, const Reflector4())
9 @GlobalQuantifyCapability(r"^reflectable.reflectable.Reflectable$",
10 const AllReflectorsMetaReflector())
11 import "package:reflectable/reflectable.dart";
12 import "package:unittest/unittest.dart";
13
14 /// Used to get access to all reflectors.
15 class AllReflectorsMetaReflector extends Reflectable {
16 const AllReflectorsMetaReflector()
17 : super(subtypeQuantifyCapability, newInstanceCapability);
18
19 Set<Reflectable> get reflectors {
20 Set<Reflectable> result = new Set<Reflectable>();
21 annotatedClasses.forEach((ClassMirror classMirror) {
22 if (classMirror.isAbstract) return;
23 Reflectable reflector =
24 Reflectable.getInstance(classMirror.reflectedType);
25 if (reflector != null) result.add(reflector);
26 });
27 return result;
28 }
29 }
30
31 class Reflector extends Reflectable {
32 const Reflector()
33 : super(invokingCapability, declarationsCapability, libraryCapability);
34 }
35
36 class Reflector2 extends Reflectable {
37 const Reflector2()
38 : super(invokingCapability, metadataCapability, libraryCapability);
39 }
40
41 class Reflector3 extends Reflectable {
42 const Reflector3() : super(invokingCapability);
43 }
44
45 class Reflector4 extends Reflectable {
46 const Reflector4() : super(declarationsCapability);
47 }
48
49 class ReflectorUpwardsClosed extends Reflectable {
50 const ReflectorUpwardsClosed()
51 : super(superclassQuantifyCapability, invokingCapability,
52 declarationsCapability, typeRelationsCapability);
53 }
54
55 class ReflectorUpwardsClosedToA extends Reflectable {
56 const ReflectorUpwardsClosedToA()
57 : super(const SuperclassQuantifyCapability(A), invokingCapability,
58 declarationsCapability);
59 }
60
61 class ReflectorUpwardsClosedUntilA extends Reflectable {
62 const ReflectorUpwardsClosedUntilA()
63 : super(const SuperclassQuantifyCapability(A, excludeUpperBound: true),
64 invokingCapability, declarationsCapability);
65 }
66
67 @Reflector()
68 @Reflector2()
69 @P()
70 class M1 {
71 foo() {}
72 var field;
73 static staticFoo(x) {}
74 }
75
76 class P {
77 const P();
78 }
79
80 @Reflector()
81 @Reflector2()
82 class M2 {}
83
84 @Reflector()
85 @Reflector2()
86 class M3 {}
87
88 @Reflector()
89 class A {
90 foo() {}
91 var field;
92 static staticFoo(x) {}
93 static staticBar() {}
94 }
95
96 @Reflector()
97 @Reflector2()
98 class B extends A with M1 {}
99
100 @Reflector()
101 @Reflector2()
102 @ReflectorUpwardsClosed()
103 @ReflectorUpwardsClosedUntilA()
104 class C extends B with M2, M3 {}
105
106 @Reflector()
107 @Reflector2()
108 @ReflectorUpwardsClosed()
109 @ReflectorUpwardsClosedToA()
110 class D = A with M1;
111
112 main() {
113 List<Reflectable> reflectors =
114 const AllReflectorsMetaReflector().reflectors.toList();
115
116 test("Mixin, superclasses not included", () {
117 expect(
118 reflectors,
119 [
120 const Reflector(),
121 const Reflector2(),
122 const Reflector3(),
123 const Reflector4(),
124 const ReflectorUpwardsClosed(),
125 const ReflectorUpwardsClosedToA(),
126 const ReflectorUpwardsClosedUntilA(),
127 const AllReflectorsMetaReflector()
128 ].toSet());
129 });
130 }
OLDNEW
« no previous file with comments | « test_reflectable/test/reflected_type_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698