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 library test.constructor_kinds_test; | |
6 | |
7 @MirrorsUsed(targets: "test.constructor_kinds_test") | |
8 import 'dart:mirrors'; | |
9 import 'package:expect/expect.dart'; | |
10 | |
11 class ClassWithDefaultConstructor {} | |
12 | |
13 class Class { | |
14 Class.generativeConstructor(); | |
15 Class.redirectingGenerativeConstructor() : this.generativeConstructor(); | |
16 factory Class.factoryConstructor() => new Class.generativeConstructor(); | |
17 factory Class.redirectingFactoryConstructor() = Class.factoryConstructor; | |
18 | |
19 const Class.constGenerativeConstructor(); | |
20 const Class.constRedirectingGenerativeConstructor() | |
21 : this.constGenerativeConstructor(); | |
22 // Not legal. | |
23 // const factory Class.constFactoryConstructor() => ... | |
24 const factory Class.constRedirectingFactoryConstructor() = | |
25 Class.constGenerativeConstructor; | |
26 } | |
27 | |
28 main() { | |
29 ClassMirror cm; | |
30 MethodMirror mm; | |
31 | |
32 // Multitest with and without constructor calls. On the VM, we want to check | |
33 // that constructor properties are correctly set even if the constructor | |
34 // hasn't been fully compiled. On dart2js, we want to check that constructors | |
35 // are retain even if there are no base-level calls. | |
36 new ClassWithDefaultConstructor(); // //# 01: ok | |
37 new Class.generativeConstructor(); // //# 01: ok | |
38 new Class.redirectingGenerativeConstructor(); // //# 01: ok | |
39 new Class.factoryConstructor(); // //# 01: ok | |
40 new Class.redirectingFactoryConstructor(); // //# 01: ok | |
41 const Class.constGenerativeConstructor(); // //# 01: ok | |
42 const Class.constRedirectingGenerativeConstructor(); // //# 01: ok | |
43 const Class.constRedirectingFactoryConstructor(); // //# 01: ok | |
44 | |
45 cm = reflectClass(ClassWithDefaultConstructor); | |
46 mm = cm.declarations.values | |
47 .where((d) => d is MethodMirror && d.isConstructor) | |
48 .single; | |
49 Expect.isTrue(mm.isConstructor); | |
50 Expect.isTrue(mm.isGenerativeConstructor); | |
51 Expect.isFalse(mm.isFactoryConstructor); | |
52 Expect.isFalse(mm.isRedirectingConstructor); | |
53 Expect.isFalse(mm.isConstConstructor); | |
54 | |
55 cm = reflectClass(Class); | |
56 | |
57 mm = cm.declarations[#Class.generativeConstructor]; | |
58 Expect.isTrue(mm.isConstructor); | |
59 Expect.isTrue(mm.isGenerativeConstructor); | |
60 Expect.isFalse(mm.isFactoryConstructor); | |
61 Expect.isFalse(mm.isRedirectingConstructor); | |
62 Expect.isFalse(mm.isConstConstructor); | |
63 | |
64 mm = cm.declarations[#Class.redirectingGenerativeConstructor]; | |
65 Expect.isTrue(mm.isConstructor); | |
66 Expect.isTrue(mm.isGenerativeConstructor); | |
67 Expect.isFalse(mm.isFactoryConstructor); | |
68 Expect.isTrue(mm.isRedirectingConstructor); | |
69 Expect.isFalse(mm.isConstConstructor); | |
70 | |
71 mm = cm.declarations[#Class.factoryConstructor]; | |
72 Expect.isTrue(mm.isConstructor); | |
73 Expect.isFalse(mm.isGenerativeConstructor); | |
74 Expect.isTrue(mm.isFactoryConstructor); | |
75 Expect.isFalse(mm.isRedirectingConstructor); | |
76 Expect.isFalse(mm.isConstConstructor); | |
77 | |
78 mm = cm.declarations[#Class.redirectingFactoryConstructor]; | |
79 Expect.isTrue(mm.isConstructor); | |
80 Expect.isFalse(mm.isGenerativeConstructor); | |
81 Expect.isTrue(mm.isFactoryConstructor); | |
82 Expect.isTrue(mm.isRedirectingConstructor); | |
83 Expect.isFalse(mm.isConstConstructor); | |
84 | |
85 mm = cm.declarations[#Class.constGenerativeConstructor]; | |
86 Expect.isTrue(mm.isConstructor); | |
87 Expect.isTrue(mm.isGenerativeConstructor); | |
88 Expect.isFalse(mm.isFactoryConstructor); | |
89 Expect.isFalse(mm.isRedirectingConstructor); | |
90 Expect.isTrue(mm.isConstConstructor); | |
91 | |
92 mm = cm.declarations[#Class.constRedirectingGenerativeConstructor]; | |
93 Expect.isTrue(mm.isConstructor); | |
94 Expect.isTrue(mm.isGenerativeConstructor); | |
95 Expect.isFalse(mm.isFactoryConstructor); | |
96 Expect.isTrue(mm.isRedirectingConstructor); | |
97 Expect.isTrue(mm.isConstConstructor); | |
98 | |
99 // Not legal. | |
100 // mm = cm.declarations[#Class.constFactoryConstructor]; | |
101 // Expect.isTrue(mm.isConstructor); | |
102 // Expect.isFalse(mm.isGenerativeConstructor); | |
103 // Expect.isTrue(mm.isFactoryConstructor); | |
104 // Expect.isFalse(mm.isRedirectingConstructor); | |
105 // Expect.isTrue(mm.isConstConstructor); | |
106 | |
107 mm = cm.declarations[#Class.constRedirectingFactoryConstructor]; | |
108 Expect.isTrue(mm.isConstructor); | |
109 Expect.isFalse(mm.isGenerativeConstructor); | |
110 Expect.isTrue(mm.isFactoryConstructor); | |
111 Expect.isTrue(mm.isRedirectingConstructor); | |
112 Expect.isTrue(mm.isConstConstructor); | |
113 } | |
OLD | NEW |