| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 compiler.backend.isNeededForReflection(classMember), | 85 compiler.backend.isNeededForReflection(classMember), |
| 86 '$classMember'); | 86 '$classMember'); |
| 87 }); | 87 }); |
| 88 } else { | 88 } else { |
| 89 Expect.isFalse( | 89 Expect.isFalse( |
| 90 compiler.backend.isNeededForReflection(member), '$member'); | 90 compiler.backend.isNeededForReflection(member), '$member'); |
| 91 } | 91 } |
| 92 }); | 92 }); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // There should at least be three metadata constants: | 95 // There should at least be one metadata constant: |
| 96 // 1. The type literal 'Foo'. | 96 // 1. The constructed constant for 'MirrorsUsed'. |
| 97 // 2. The list 'const [Foo]'. | 97 Expect.isTrue(compiler.backend.metadataConstants.length >= 1); |
| 98 // 3. The constructed constant for 'MirrorsUsed'. | |
| 99 Expect.isTrue(compiler.metadataHandler.compiledConstants.length >= 3); | |
| 100 | 98 |
| 101 // Make sure that most of the metadata constants aren't included in the | 99 // Make sure that most of the metadata constants aren't included in the |
| 102 // generated code. | 100 // generated code. |
| 103 for (Constant constant in compiler.metadataHandler.compiledConstants) { | 101 for (var dependency in compiler.backend.metadataConstants) { |
| 104 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { | 102 Constant constant = dependency.constant; |
| 105 // The type literal 'Foo' is retained as a constant because it is being | |
| 106 // passed to reflectClass. | |
| 107 continue; | |
| 108 } | |
| 109 Expect.isFalse( | 103 Expect.isFalse( |
| 110 compiler.constantHandler.compiledConstants.contains(constant), | 104 compiler.constantHandler.compiledConstants.contains(constant), |
| 111 '$constant'); | 105 '$constant'); |
| 112 } | 106 } |
| 113 | 107 |
| 114 // The type literal 'Foo' is both used as metadata, and as a plain value in | 108 // The type literal 'Foo' is both used as metadata, and as a plain value in |
| 115 // the program. Make sure that it isn't duplicated. | 109 // the program. Make sure that it isn't duplicated. |
| 116 int fooConstantCount = 0; | 110 int fooConstantCount = 0; |
| 117 for (Constant constant in compiler.metadataHandler.compiledConstants) { | 111 for (Constant constant in compiler.constantHandler.compiledConstants) { |
| 118 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { | 112 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { |
| 119 fooConstantCount++; | 113 fooConstantCount++; |
| 120 } | 114 } |
| 121 } | 115 } |
| 122 Expect.equals( | 116 Expect.equals( |
| 123 1, fooConstantCount, | 117 1, fooConstantCount, |
| 124 "The type literal 'Foo' is duplicated or missing."); | 118 "The type literal 'Foo' is duplicated or missing."); |
| 125 })); | 119 })); |
| 126 } | 120 } |
| 127 | 121 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 library lib; | 143 library lib; |
| 150 | 144 |
| 151 import 'dart:mirrors'; | 145 import 'dart:mirrors'; |
| 152 | 146 |
| 153 useReflect(type) { | 147 useReflect(type) { |
| 154 print(new Symbol('Foo')); | 148 print(new Symbol('Foo')); |
| 155 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 149 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 156 } | 150 } |
| 157 """, | 151 """, |
| 158 }; | 152 }; |
| OLD | NEW |