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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // We always include the names of some native classes. | 90 // We always include the names of some native classes. |
91 List<ClassElement> nativeClasses = [ | 91 List<ClassElement> nativeClasses = [ |
92 compiler.resolution.commonElements.intClass, | 92 compiler.resolution.commonElements.intClass, |
93 compiler.resolution.commonElements.doubleClass, | 93 compiler.resolution.commonElements.doubleClass, |
94 compiler.resolution.commonElements.numClass, | 94 compiler.resolution.commonElements.numClass, |
95 compiler.resolution.commonElements.stringClass, | 95 compiler.resolution.commonElements.stringClass, |
96 compiler.resolution.commonElements.boolClass, | 96 compiler.resolution.commonElements.boolClass, |
97 compiler.resolution.commonElements.nullClass, | 97 compiler.resolution.commonElements.nullClass, |
98 compiler.resolution.commonElements.listClass | 98 compiler.resolution.commonElements.listClass |
99 ]; | 99 ]; |
100 Iterable<String> nativeNames = nativeClasses.map(backend.namer.className); | 100 Iterable<String> nativeNames = |
| 101 // `backend.namer.className` returns a Name, but a String is required. |
| 102 // ignore: ARGUMENT_TYPE_NOT_ASSIGNABLE |
| 103 nativeClasses.map((c) => backend.namer.className(c)); |
101 expectedNames = expectedNames.map(backend.namer.asName).toList(); | 104 expectedNames = expectedNames.map(backend.namer.asName).toList(); |
102 expectedNames.addAll(nativeNames); | 105 expectedNames.addAll(nativeNames); |
103 | 106 |
104 // Mirrors only work in the full emitter. We can thus be certain that the | 107 // Mirrors only work in the full emitter. We can thus be certain that the |
105 // emitter is the full emitter. | 108 // emitter is the full emitter. |
106 full.Emitter fullEmitter = backend.emitter.emitter; | 109 full.Emitter fullEmitter = backend.emitter.emitter; |
107 Set recordedNames = new Set() | 110 Set recordedNames = new Set() |
108 ..addAll(fullEmitter.recordedMangledNames) | 111 ..addAll(fullEmitter.recordedMangledNames) |
109 ..addAll(fullEmitter.mangledFieldNames.keys) | 112 ..addAll(fullEmitter.mangledFieldNames.keys) |
110 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); | 113 ..addAll(fullEmitter.mangledGlobalFieldNames.keys); |
111 Expect.setEquals(new Set.from(expectedNames), recordedNames); | 114 Expect.setEquals(new Set.from(expectedNames), recordedNames); |
112 | 115 |
113 for (var library in compiler.libraryLoader.libraries) { | 116 for (dynamic library in compiler.libraryLoader.libraries) { |
114 library.forEachLocalMember((member) { | 117 library.forEachLocalMember((member) { |
115 if (member.isClass) { | 118 if (member.isClass) { |
116 if (library == compiler.mainApp && member.name == 'Foo') { | 119 if (library == compiler.mainApp && member.name == 'Foo') { |
117 Expect.isTrue( | 120 Expect.isTrue( |
118 compiler.backend.mirrorsData | 121 compiler.backend.mirrorsData |
119 .isClassAccessibleByReflection(member), | 122 .isClassAccessibleByReflection(member), |
120 '$member'); | 123 '$member'); |
121 member.forEachLocalMember((classMember) { | 124 member.forEachLocalMember((classMember) { |
122 Expect.isTrue( | 125 Expect.isTrue( |
123 compiler.backend.mirrorsData | 126 compiler.backend.mirrorsData |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 library lib; | 208 library lib; |
206 | 209 |
207 import 'dart:mirrors'; | 210 import 'dart:mirrors'; |
208 | 211 |
209 useReflect(type) { | 212 useReflect(type) { |
210 print(new Symbol('Foo')); | 213 print(new Symbol('Foo')); |
211 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 214 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
212 } | 215 } |
213 """, | 216 """, |
214 }; | 217 }; |
OLD | NEW |