| 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"; |
| 11 | 11 |
| 12 import 'memory_compiler.dart' show | 12 import 'memory_compiler.dart' show |
| 13 compilerFor; | 13 compilerFor; |
| 14 | 14 |
| 15 import 'package:compiler/implementation/apiimpl.dart' show | 15 import 'package:compiler/implementation/apiimpl.dart' show |
| 16 Compiler; | 16 Compiler; |
| 17 | 17 |
| 18 import 'package:compiler/implementation/constants/values.dart' show | 18 import 'package:compiler/implementation/constants/values.dart' show |
| 19 Constant, | 19 ConstantValue, |
| 20 TypeConstant; | 20 TypeConstantValue; |
| 21 | 21 |
| 22 import 'package:compiler/implementation/elements/elements.dart' show | 22 import 'package:compiler/implementation/elements/elements.dart' show |
| 23 Element, | 23 Element, |
| 24 Elements; | 24 Elements; |
| 25 | 25 |
| 26 import 'package:compiler/implementation/js_backend/js_backend.dart' show | 26 import 'package:compiler/implementation/js_backend/js_backend.dart' show |
| 27 JavaScriptBackend; | 27 JavaScriptBackend; |
| 28 | 28 |
| 29 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) { | 29 void expectOnlyVerboseInfo(Uri uri, int begin, int end, String message, kind) { |
| 30 if (kind.name == 'verbose info') { | 30 if (kind.name == 'verbose info') { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Expect.isFalse( | 108 Expect.isFalse( |
| 109 compiler.backend.isAccessibleByReflection(member), '$member'); | 109 compiler.backend.isAccessibleByReflection(member), '$member'); |
| 110 } | 110 } |
| 111 }); | 111 }); |
| 112 } | 112 } |
| 113 | 113 |
| 114 // There should at least be one metadata constant: | 114 // There should at least be one metadata constant: |
| 115 // 1. The constructed constant for 'MirrorsUsed'. | 115 // 1. The constructed constant for 'MirrorsUsed'. |
| 116 Expect.isTrue(backend.metadataConstants.length >= 1); | 116 Expect.isTrue(backend.metadataConstants.length >= 1); |
| 117 | 117 |
| 118 Set<Constant> compiledConstants = backend.constants.compiledConstants; | 118 Set<ConstantValue> compiledConstants = backend.constants.compiledConstants; |
| 119 // Make sure that most of the metadata constants aren't included in the | 119 // Make sure that most of the metadata constants aren't included in the |
| 120 // generated code. | 120 // generated code. |
| 121 for (var dependency in backend.metadataConstants) { | 121 for (var dependency in backend.metadataConstants) { |
| 122 Constant constant = dependency.constant; | 122 ConstantValue constant = dependency.constant; |
| 123 Expect.isFalse(compiledConstants.contains(constant), | 123 Expect.isFalse(compiledConstants.contains(constant), |
| 124 constant.toStructuredString()); | 124 constant.toStructuredString()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 // The type literal 'Foo' is both used as metadata, and as a plain value in | 127 // The type literal 'Foo' is both used as metadata, and as a plain value in |
| 128 // the program. Make sure that it isn't duplicated. | 128 // the program. Make sure that it isn't duplicated. |
| 129 int fooConstantCount = 0; | 129 int fooConstantCount = 0; |
| 130 for (Constant constant in compiledConstants) { | 130 for (ConstantValue constant in compiledConstants) { |
| 131 if (constant is TypeConstant && '${constant.representedType}' == 'Foo') { | 131 if (constant is TypeConstantValue && |
| 132 '${constant.representedType}' == 'Foo') { |
| 132 fooConstantCount++; | 133 fooConstantCount++; |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 Expect.equals( | 136 Expect.equals( |
| 136 1, fooConstantCount, | 137 1, fooConstantCount, |
| 137 "The type literal 'Foo' is duplicated or missing."); | 138 "The type literal 'Foo' is duplicated or missing."); |
| 138 })); | 139 })); |
| 139 } | 140 } |
| 140 | 141 |
| 141 const MEMORY_SOURCE_FILES = const <String, String> { | 142 const MEMORY_SOURCE_FILES = const <String, String> { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 164 library lib; | 165 library lib; |
| 165 | 166 |
| 166 import 'dart:mirrors'; | 167 import 'dart:mirrors'; |
| 167 | 168 |
| 168 useReflect(type) { | 169 useReflect(type) { |
| 169 print(new Symbol('Foo')); | 170 print(new Symbol('Foo')); |
| 170 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); | 171 print(MirrorSystem.getName(reflectClass(type).owner.qualifiedName)); |
| 171 } | 172 } |
| 172 """, | 173 """, |
| 173 }; | 174 }; |
| OLD | NEW |