| 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 int metadataCount = 0; | 130 // There should at least be one metadata constant: |
| 131 // 1. The constructed constant for 'MirrorsUsed'. |
| 132 Expect.isTrue(backend.metadataConstants.length >= 1); |
| 133 |
| 131 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; | 134 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; |
| 132 // Make sure that most of the metadata constants aren't included in the | 135 // Make sure that most of the metadata constants aren't included in the |
| 133 // generated code. | 136 // generated code. |
| 134 backend.processMetadata( | 137 for (var dependency in backend.metadataConstants) { |
| 135 compiler.enqueuer.resolution.processedElements, (metadata) { | 138 ConstantValue constant = dependency.constant; |
| 136 ConstantValue constant = | |
| 137 backend.constants.getConstantValueForMetadata(metadata); | |
| 138 Expect.isFalse(compiledConstants.contains(constant), | 139 Expect.isFalse(compiledConstants.contains(constant), |
| 139 constant.toStructuredText()); | 140 constant.toStructuredText()); |
| 140 metadataCount++; | 141 } |
| 141 }); | |
| 142 | |
| 143 // There should at least be one metadata constant: | |
| 144 // 1. The constructed constant for 'MirrorsUsed'. | |
| 145 Expect.isTrue(metadataCount >= 1); | |
| 146 | 142 |
| 147 // The type literal 'Foo' is both used as metadata, and as a plain value in | 143 // The type literal 'Foo' is both used as metadata, and as a plain value in |
| 148 // the program. Make sure that it isn't duplicated. | 144 // the program. Make sure that it isn't duplicated. |
| 149 int fooConstantCount = 0; | 145 int fooConstantCount = 0; |
| 150 for (ConstantValue constant in compiledConstants) { | 146 for (ConstantValue constant in compiledConstants) { |
| 151 if (constant is TypeConstantValue && | 147 if (constant is TypeConstantValue && |
| 152 '${constant.representedType}' == 'Foo') { | 148 '${constant.representedType}' == 'Foo') { |
| 153 fooConstantCount++; | 149 fooConstantCount++; |
| 154 } | 150 } |
| 155 } | 151 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 185 library lib; | 181 library lib; |
| 186 | 182 |
| 187 import 'dart:mirrors'; | 183 import 'dart:mirrors'; |
| 188 | 184 |
| 189 useReflect(type) { | 185 useReflect(type) { |
| 190 print(new Symbol('Foo')); | 186 print(new Symbol('Foo')); |
| 191 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 187 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 192 } | 188 } |
| 193 """, | 189 """, |
| 194 }; | 190 }; |
| OLD | NEW |