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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // emitter is the full emitter. | 101 // emitter is the full emitter. |
102 full.Emitter fullEmitter = backend.emitter.emitter; | 102 full.Emitter fullEmitter = backend.emitter.emitter; |
103 Set recordedNames = new Set() | 103 Set recordedNames = new Set() |
104 ..addAll(fullEmitter.recordedMangledNames) | 104 ..addAll(fullEmitter.recordedMangledNames) |
105 ..addAll(fullEmitter.mangledFieldNames.keys) | 105 ..addAll(fullEmitter.mangledFieldNames.keys) |
106 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); | 106 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); |
107 Expect.setEquals(new Set.from(expectedNames), recordedNames); | 107 Expect.setEquals(new Set.from(expectedNames), recordedNames); |
108 | 108 |
109 for (var library in compiler.libraryLoader.libraries) { | 109 for (var library in compiler.libraryLoader.libraries) { |
110 library.forEachLocalMember((member) { | 110 library.forEachLocalMember((member) { |
111 if (library == compiler.mainApp && member.name == 'Foo') { | 111 if (member.isClass) { |
112 Expect.isTrue( | 112 if (library == compiler.mainApp && member.name == 'Foo') { |
113 compiler.backend.mirrorsData.isAccessibleByReflection(member), | |
114 '$member'); | |
115 member.forEachLocalMember((classMember) { | |
116 Expect.isTrue( | 113 Expect.isTrue( |
117 compiler.backend.mirrorsData | 114 compiler.backend.mirrorsData |
118 .isAccessibleByReflection(classMember), | 115 .isClassAccessibleByReflection(member), |
119 '$classMember'); | 116 '$member'); |
120 }); | 117 member.forEachLocalMember((classMember) { |
| 118 Expect.isTrue( |
| 119 compiler.backend.mirrorsData |
| 120 .isMemberAccessibleByReflection(classMember), |
| 121 '$classMember'); |
| 122 }); |
| 123 } else { |
| 124 Expect.isFalse( |
| 125 compiler.backend.mirrorsData |
| 126 .isClassAccessibleByReflection(member), |
| 127 '$member'); |
| 128 } |
| 129 } else if (member.isTypedef) { |
| 130 Expect.isFalse( |
| 131 compiler.backend.mirrorsData |
| 132 .isTypedefAccessibleByReflection(member), |
| 133 '$member'); |
121 } else { | 134 } else { |
122 Expect.isFalse( | 135 Expect.isFalse( |
123 compiler.backend.mirrorsData.isAccessibleByReflection(member), | 136 compiler.backend.mirrorsData |
| 137 .isMemberAccessibleByReflection(member), |
124 '$member'); | 138 '$member'); |
125 } | 139 } |
126 }); | 140 }); |
127 } | 141 } |
128 | 142 |
129 int metadataCount = 0; | 143 int metadataCount = 0; |
130 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; | 144 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; |
131 // Make sure that most of the metadata constants aren't included in the | 145 // Make sure that most of the metadata constants aren't included in the |
132 // generated code. | 146 // generated code. |
133 MirrorsResolutionAnalysisImpl mirrorsResolutionAnalysis = | 147 MirrorsResolutionAnalysisImpl mirrorsResolutionAnalysis = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 library lib; | 199 library lib; |
186 | 200 |
187 import 'dart:mirrors'; | 201 import 'dart:mirrors'; |
188 | 202 |
189 useReflect(type) { | 203 useReflect(type) { |
190 print(new Symbol('Foo')); | 204 print(new Symbol('Foo')); |
191 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 205 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
192 } | 206 } |
193 """, | 207 """, |
194 }; | 208 }; |
OLD | NEW |