Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; | 5 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; |
| 6 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; | 6 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; |
| 7 | 7 |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 int count(Iterable iterable) { | 10 int count(Iterable iterable) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 "Constructors map is unempty"); | 156 "Constructors map is unempty"); |
| 157 | 157 |
| 158 // TODO(johnniwinther): Add thorough tests of [ClassMirror.functions], | 158 // TODO(johnniwinther): Add thorough tests of [ClassMirror.functions], |
| 159 // [ClassMirror.getters], [ClassMirror.setters], [ClassMirror.members], | 159 // [ClassMirror.getters], [ClassMirror.setters], [ClassMirror.members], |
| 160 // and [ClassMirror.variable]. | 160 // and [ClassMirror.variable]. |
| 161 Expect.isNotNull(fooClass.functions); | 161 Expect.isNotNull(fooClass.functions); |
| 162 Expect.isNotNull(fooClass.members); | 162 Expect.isNotNull(fooClass.members); |
| 163 Expect.isNotNull(fooClass.getters); | 163 Expect.isNotNull(fooClass.getters); |
| 164 Expect.isNotNull(fooClass.setters); | 164 Expect.isNotNull(fooClass.setters); |
| 165 Expect.isNotNull(fooClass.variables); | 165 Expect.isNotNull(fooClass.variables); |
| 166 | |
| 167 ////////////////////////////////////////////////////////////////////////////// | |
| 168 // Metadata tests | |
| 169 // | |
| 170 // @Metadata | |
|
ahe
2012/12/19 15:44:03
These comments would be more helpful closer to the
Johnni Winther
2012/12/20 11:30:35
Done.
| |
| 171 // @Metadata(null) | |
| 172 // @Metadata(true) | |
| 173 // @Metadata(false) | |
| 174 // @Metadata(0) | |
| 175 // @Metadata(1.5) | |
| 176 // @Metadata("Foo") | |
| 177 // @Metadata(const ["Foo"]) | |
| 178 // @Metadata(const {'foo':"Foo"}) | |
| 179 ////////////////////////////////////////////////////////////////////////////// | |
| 180 | |
| 181 var metadata = fooClass.metadata; | |
| 182 Expect.isNotNull(metadata); | |
| 183 Expect.equals(9, metadata.length); | |
| 184 | |
| 185 var metadata0 = metadata[0]; | |
| 186 Expect.isTrue(metadata0 is InstanceMirror); | |
| 187 Expect.isFalse(metadata0.hasReflectee); | |
| 188 Expect.throws(() => metadata0.reflectee, (_) => true); | |
| 189 Expect.isTrue(metadata0 is TypeInstanceMirror); | |
| 190 var metadataType = metadata0.representedType; | |
| 191 Expect.isNotNull(metadataType); | |
| 192 Expect.stringEquals('Metadata', metadataType.simpleName); | |
| 193 | |
| 194 var metadata1 = metadata[1]; | |
| 195 Expect.isTrue(metadata1 is InstanceMirror); | |
| 196 Expect.isFalse(metadata1.hasReflectee); | |
| 197 Expect.throws(() => metadata1.reflectee, (_) => true); | |
| 198 Expect.equals(metadataType.originalDeclaration, metadata1.type); | |
| 199 metadata1.getField('data').then((InstanceMirror data) { | |
| 200 Expect.isNotNull(data); | |
| 201 Expect.isTrue(data.hasReflectee); | |
| 202 Expect.isNull(data.reflectee); | |
| 203 }); | |
| 204 | |
| 205 var metadata2 = metadata[2]; | |
| 206 Expect.isTrue(metadata2 is InstanceMirror); | |
| 207 Expect.isFalse(metadata2.hasReflectee); | |
| 208 Expect.throws(() => metadata2.reflectee, (_) => true); | |
| 209 Expect.equals(metadataType.originalDeclaration, metadata2.type); | |
| 210 metadata2.getField('data').then((InstanceMirror data) { | |
| 211 Expect.isNotNull(data); | |
| 212 Expect.isTrue(data.hasReflectee); | |
| 213 Expect.isTrue(data.reflectee); | |
| 214 }); | |
| 215 | |
| 216 var metadata3 = metadata[3]; | |
| 217 Expect.isTrue(metadata3 is InstanceMirror); | |
| 218 Expect.isFalse(metadata3.hasReflectee); | |
| 219 Expect.throws(() => metadata3.reflectee, (_) => true); | |
| 220 Expect.equals(metadataType.originalDeclaration, metadata3.type); | |
| 221 metadata3.getField('data').then((InstanceMirror data) { | |
| 222 Expect.isNotNull(data); | |
| 223 Expect.isTrue(data.hasReflectee); | |
| 224 Expect.isFalse(data.reflectee); | |
| 225 }); | |
| 226 | |
| 227 var metadata4 = metadata[4]; | |
| 228 Expect.isTrue(metadata4 is InstanceMirror); | |
| 229 Expect.isFalse(metadata4.hasReflectee); | |
| 230 Expect.throws(() => metadata4.reflectee, (_) => true); | |
| 231 Expect.equals(metadataType.originalDeclaration, metadata4.type); | |
| 232 metadata4.getField('data').then((InstanceMirror data) { | |
| 233 Expect.isNotNull(data); | |
| 234 Expect.isTrue(data.hasReflectee); | |
| 235 Expect.equals(0, data.reflectee); | |
| 236 }); | |
| 237 | |
| 238 var metadata5 = metadata[5]; | |
| 239 Expect.isTrue(metadata5 is InstanceMirror); | |
| 240 Expect.isFalse(metadata5.hasReflectee); | |
| 241 Expect.throws(() => metadata5.reflectee, (_) => true); | |
| 242 Expect.equals(metadataType.originalDeclaration, metadata5.type); | |
| 243 metadata5.getField('data').then((InstanceMirror data) { | |
| 244 Expect.isNotNull(data); | |
| 245 Expect.isTrue(data.hasReflectee); | |
| 246 Expect.equals(1.5, data.reflectee); | |
| 247 }); | |
| 248 | |
| 249 var metadata6 = metadata[6]; | |
| 250 Expect.isTrue(metadata6 is InstanceMirror); | |
| 251 Expect.isFalse(metadata6.hasReflectee); | |
| 252 Expect.throws(() => metadata6.reflectee, (_) => true); | |
| 253 Expect.equals(metadataType.originalDeclaration, metadata6.type); | |
| 254 metadata6.getField('data').then((InstanceMirror data) { | |
| 255 Expect.isNotNull(data); | |
| 256 Expect.isTrue(data.hasReflectee); | |
| 257 Expect.stringEquals("Foo", data.reflectee); | |
| 258 }); | |
| 259 | |
| 260 var metadata7 = metadata[7]; | |
| 261 Expect.isTrue(metadata7 is InstanceMirror); | |
| 262 Expect.isFalse(metadata7.hasReflectee); | |
| 263 Expect.throws(() => metadata7.reflectee, (_) => true); | |
| 264 Expect.equals(metadataType.originalDeclaration, metadata7.type); | |
| 265 metadata7.getField('data').then((InstanceMirror data) { | |
| 266 Expect.isTrue(data is ListInstanceMirror); | |
| 267 Expect.isFalse(data.hasReflectee); | |
| 268 Expect.throws(() => data.reflectee, (_) => true); | |
| 269 ListInstanceMirror listData = data; | |
| 270 Expect.equals(1, listData.length); | |
| 271 listData[0].then((InstanceMirror element) { | |
| 272 Expect.isNotNull(element); | |
| 273 Expect.isTrue(element.hasReflectee); | |
| 274 Expect.stringEquals("Foo", element.reflectee); | |
| 275 }); | |
| 276 }); | |
| 277 | |
| 278 var metadata8 = metadata[8]; | |
| 279 Expect.isTrue(metadata8 is InstanceMirror); | |
| 280 Expect.isFalse(metadata8.hasReflectee); | |
| 281 Expect.throws(() => metadata8.reflectee, (_) => true); | |
| 282 Expect.equals(metadataType.originalDeclaration, metadata8.type); | |
| 283 metadata8.getField('data').then((InstanceMirror data) { | |
| 284 Expect.isTrue(data is MapInstanceMirror); | |
| 285 Expect.isFalse(data.hasReflectee); | |
| 286 Expect.throws(() => data.reflectee, (_) => true); | |
| 287 MapInstanceMirror mapData = data; | |
| 288 Expect.equals(1, mapData.length); | |
| 289 Expect.stringEquals('foo', mapData.keys.iterator().next()); | |
| 290 mapData['foo'].then((InstanceMirror element) { | |
| 291 Expect.isNotNull(element); | |
| 292 Expect.isTrue(element.hasReflectee); | |
| 293 Expect.stringEquals("Foo", element.reflectee); | |
| 294 }); | |
| 295 Expect.isNull(mapData['bar']); | |
| 296 }); | |
| 297 | |
| 166 } | 298 } |
| 167 | 299 |
| 168 // Testing interface Bar: | 300 // Testing interface Bar: |
| 169 // | 301 // |
| 170 // interface Bar<E> { | 302 // interface Bar<E> { |
| 171 // | 303 // |
| 172 // } | 304 // } |
| 173 void testBar(MirrorSystem system, LibraryMirror helperLibrary, | 305 void testBar(MirrorSystem system, LibraryMirror helperLibrary, |
| 174 Map<String,TypeMirror> classes) { | 306 Map<String,TypeMirror> classes) { |
| 175 var barInterface = classes["Bar"]; | 307 var barInterface = classes["Bar"]; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 368 |
| 237 var barInterfaceMembers = barInterface.members; | 369 var barInterfaceMembers = barInterface.members; |
| 238 Expect.isNotNull(barInterfaceMembers, "Declared members map is null"); | 370 Expect.isNotNull(barInterfaceMembers, "Declared members map is null"); |
| 239 Expect.isTrue(barInterfaceMembers.isEmpty, | 371 Expect.isTrue(barInterfaceMembers.isEmpty, |
| 240 "Declared members map is unempty"); | 372 "Declared members map is unempty"); |
| 241 | 373 |
| 242 var barInterfaceConstructors = barInterface.constructors; | 374 var barInterfaceConstructors = barInterface.constructors; |
| 243 Expect.isNotNull(barInterfaceConstructors, "Constructors map is null"); | 375 Expect.isNotNull(barInterfaceConstructors, "Constructors map is null"); |
| 244 Expect.isTrue(barInterfaceConstructors.isEmpty, | 376 Expect.isTrue(barInterfaceConstructors.isEmpty, |
| 245 "Constructors map is unempty"); | 377 "Constructors map is unempty"); |
| 378 | |
| 379 var metadata = barInterface.metadata; | |
| 380 Expect.isNotNull(metadata); | |
| 381 Expect.equals(0, metadata.length); | |
| 246 } | 382 } |
| 247 | 383 |
| 248 // Testing class Baz: | 384 // Testing class Baz: |
| 249 // | 385 // |
| 250 // class Baz<E,F extends Foo> implements Bar<E> { | 386 // class Baz<E,F extends Foo> implements Bar<E> { |
| 251 // Baz(); | 387 // Baz(); |
| 252 // const Baz.named(); | 388 // const Baz.named(); |
| 253 // factory Baz.factory() => new Baz<E,F>(); | 389 // factory Baz.factory() => new Baz<E,F>(); |
| 254 // | 390 // |
| 255 // static method1(e) {} | 391 // static method1(e) {} |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 Expect.isFalse(bazClassFactoryConstructor.isRedirectingConstructor); | 850 Expect.isFalse(bazClassFactoryConstructor.isRedirectingConstructor); |
| 715 Expect.isTrue(bazClassFactoryConstructor.isFactoryConstructor); | 851 Expect.isTrue(bazClassFactoryConstructor.isFactoryConstructor); |
| 716 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.simpleName); | 852 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.simpleName); |
| 717 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.displayName); | 853 Expect.stringEquals('Baz.factory', bazClassFactoryConstructor.displayName); |
| 718 Expect.stringEquals('mirrors_helper.Baz.Baz.factory', | 854 Expect.stringEquals('mirrors_helper.Baz.Baz.factory', |
| 719 bazClassFactoryConstructor.qualifiedName); | 855 bazClassFactoryConstructor.qualifiedName); |
| 720 Expect.stringEquals('factory', bazClassFactoryConstructor.constructorName); | 856 Expect.stringEquals('factory', bazClassFactoryConstructor.constructorName); |
| 721 | 857 |
| 722 // TODO(johnniwinther): Add more tests of constructors. | 858 // TODO(johnniwinther): Add more tests of constructors. |
| 723 // TODO(johnniwinther): Add a test for unnamed factory methods. | 859 // TODO(johnniwinther): Add a test for unnamed factory methods. |
| 860 | |
| 861 var metadata = bazClass.metadata; | |
| 862 Expect.isNotNull(metadata); | |
| 863 Expect.equals(0, metadata.length); | |
| 724 } | 864 } |
| 725 | 865 |
| 726 // class _PrivateClass { | 866 // class _PrivateClass { |
| 727 // var _privateField; | 867 // var _privateField; |
| 728 // get _privateGetter => _privateField; | 868 // get _privateGetter => _privateField; |
| 729 // void set _privateSetter(value) => _privateField = value; | 869 // void set _privateSetter(value) => _privateField = value; |
| 730 // void _privateMethod() {} | 870 // void _privateMethod() {} |
| 731 // _PrivateClass._privateConstructor(); | 871 // _PrivateClass._privateConstructor(); |
| 732 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); | 872 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); |
| 733 // } | 873 // } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 778 var privateFactoryConstructor = | 918 var privateFactoryConstructor = |
| 779 privateClass.members['_PrivateClass._privateFactoryConstructor']; | 919 privateClass.members['_PrivateClass._privateFactoryConstructor']; |
| 780 Expect.isNotNull(privateFactoryConstructor); | 920 Expect.isNotNull(privateFactoryConstructor); |
| 781 Expect.isTrue(privateFactoryConstructor is MethodMirror); | 921 Expect.isTrue(privateFactoryConstructor is MethodMirror); |
| 782 Expect.isTrue(privateFactoryConstructor.isConstructor); | 922 Expect.isTrue(privateFactoryConstructor.isConstructor); |
| 783 Expect.isTrue(privateFactoryConstructor.isPrivate); | 923 Expect.isTrue(privateFactoryConstructor.isPrivate); |
| 784 Expect.isFalse(privateFactoryConstructor.isConstConstructor); | 924 Expect.isFalse(privateFactoryConstructor.isConstConstructor); |
| 785 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); | 925 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); |
| 786 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); | 926 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); |
| 787 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); | 927 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); |
| 928 | |
| 929 var metadata = privateClass.metadata; | |
| 930 Expect.isNotNull(metadata); | |
| 931 Expect.equals(0, metadata.length); | |
| 788 } | 932 } |
| OLD | NEW |