OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 /// Test that the @MirrorsUsed annotation suppress hints and that only | 5 /// Test that the @MirrorsUsed annotation suppress hints and that only |
6 /// requested elements are retained for reflection. | 6 /// requested elements are retained for reflection. |
7 library dart2js.test.mirrors_used_test; | 7 library dart2js.test.mirrors_used_test; |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 compiler.backend.isAccessibleByReflection(classMember), | 120 compiler.backend.isAccessibleByReflection(classMember), |
121 '$classMember'); | 121 '$classMember'); |
122 }); | 122 }); |
123 } else { | 123 } else { |
124 Expect.isFalse( | 124 Expect.isFalse( |
125 compiler.backend.isAccessibleByReflection(member), '$member'); | 125 compiler.backend.isAccessibleByReflection(member), '$member'); |
126 } | 126 } |
127 }); | 127 }); |
128 } | 128 } |
129 | 129 |
130 // There should at least be one metadata constant: | 130 int metadataCount = 0; |
131 // 1. The constructed constant for 'MirrorsUsed'. | |
132 Expect.isTrue(backend.metadataConstants.length >= 1); | |
133 | |
134 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; | 131 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; |
135 // Make sure that most of the metadata constants aren't included in the | 132 // Make sure that most of the metadata constants aren't included in the |
136 // generated code. | 133 // generated code. |
137 for (var dependency in backend.metadataConstants) { | 134 backend.processMetadata( |
138 ConstantValue constant = dependency.constant; | 135 compiler.enqueuer.resolution.processedElements, (metadata) { |
| 136 ConstantValue constant = |
| 137 backend.constants.getConstantValueForMetadata(metadata); |
139 Expect.isFalse(compiledConstants.contains(constant), | 138 Expect.isFalse(compiledConstants.contains(constant), |
140 constant.toStructuredText()); | 139 constant.toStructuredText()); |
141 } | 140 metadataCount++; |
| 141 }); |
| 142 |
| 143 // There should at least be one metadata constant: |
| 144 // 1. The constructed constant for 'MirrorsUsed'. |
| 145 Expect.isTrue(metadataCount >= 1); |
142 | 146 |
143 // The type literal 'Foo' is both used as metadata, and as a plain value in | 147 // The type literal 'Foo' is both used as metadata, and as a plain value in |
144 // the program. Make sure that it isn't duplicated. | 148 // the program. Make sure that it isn't duplicated. |
145 int fooConstantCount = 0; | 149 int fooConstantCount = 0; |
146 for (ConstantValue constant in compiledConstants) { | 150 for (ConstantValue constant in compiledConstants) { |
147 if (constant is TypeConstantValue && | 151 if (constant is TypeConstantValue && |
148 '${constant.representedType}' == 'Foo') { | 152 '${constant.representedType}' == 'Foo') { |
149 fooConstantCount++; | 153 fooConstantCount++; |
150 } | 154 } |
151 } | 155 } |
(...skipping 29 matching lines...) Expand all Loading... |
181 library lib; | 185 library lib; |
182 | 186 |
183 import 'dart:mirrors'; | 187 import 'dart:mirrors'; |
184 | 188 |
185 useReflect(type) { | 189 useReflect(type) { |
186 print(new Symbol('Foo')); | 190 print(new Symbol('Foo')); |
187 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 191 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
188 } | 192 } |
189 """, | 193 """, |
190 }; | 194 }; |
OLD | NEW |