| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'
; | 6 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart'
; |
| 7 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart'; | 7 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.
dart'; |
| 8 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
r.dart'; | 8 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirro
r.dart'; |
| 9 | 9 |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 import 'dart:uri'; |
| 12 |
| 13 const Uri DART_MIRRORS_URI = |
| 14 const Uri.fromComponents(scheme: 'dart', path: 'mirrors'); |
| 11 | 15 |
| 12 int count(Iterable iterable) { | 16 int count(Iterable iterable) { |
| 13 var count = 0; | 17 var count = 0; |
| 14 for (var element in iterable) { | 18 for (var element in iterable) { |
| 15 count++; | 19 count++; |
| 16 } | 20 } |
| 17 return count; | 21 return count; |
| 18 } | 22 } |
| 19 | 23 |
| 20 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) { | 24 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) { |
| 21 for (var element in iterable) { | 25 for (var element in iterable) { |
| 22 if (element.originalDeclaration == expected.originalDeclaration) { | 26 if (element.originalDeclaration == expected.originalDeclaration) { |
| 23 return true; | 27 return true; |
| 24 } | 28 } |
| 25 } | 29 } |
| 26 return false; | 30 return false; |
| 27 } | 31 } |
| 28 | 32 |
| 29 DeclarationMirror findMirror(List<DeclarationMirror> list, String name) { | 33 DeclarationMirror findMirror(Iterable<DeclarationMirror> list, String name) { |
| 30 for (DeclarationMirror mirror in list) { | 34 for (DeclarationMirror mirror in list) { |
| 31 if (mirror.simpleName == name) { | 35 if (mirror.simpleName == name) { |
| 32 return mirror; | 36 return mirror; |
| 33 } | 37 } |
| 34 } | 38 } |
| 35 return null; | 39 return null; |
| 36 } | 40 } |
| 37 | 41 |
| 38 main() { | 42 main() { |
| 39 var scriptPath = new Path(new Options().script); | 43 var scriptPath = new Path(new Options().script); |
| 40 var dirPath = scriptPath.directoryPath; | 44 var dirPath = scriptPath.directoryPath; |
| 41 var libPath = dirPath.join(new Path('../../../sdk/')); | 45 var libPath = dirPath.join(new Path('../../../sdk/')); |
| 42 var inputPath = dirPath.join(new Path('mirrors_helper.dart')); | 46 var inputPath = dirPath.join(new Path('mirrors_helper.dart')); |
| 43 var result = analyze([inputPath], libPath, | 47 var result = analyze([inputPath], libPath, |
| 44 options: <String>['--preserve-comments']); | 48 options: <String>['--preserve-comments']); |
| 45 result.then((MirrorSystem mirrors) { | 49 result.then((MirrorSystem mirrors) { |
| 46 test(mirrors); | 50 test(mirrors); |
| 47 }); | 51 }); |
| 48 } | 52 } |
| 49 | 53 |
| 50 void test(MirrorSystem mirrors) { | 54 void test(MirrorSystem mirrors) { |
| 51 Expect.isNotNull(mirrors, "No mirror system returned from compilation"); | 55 Expect.isNotNull(mirrors, "No mirror system returned from compilation"); |
| 52 | 56 |
| 53 var libraries = mirrors.libraries; | 57 var libraries = mirrors.libraries; |
| 54 Expect.isNotNull(libraries, "No libraries map returned"); | 58 Expect.isNotNull(libraries, "No libraries map returned"); |
| 55 Expect.isFalse(libraries.isEmpty, "Empty libraries map returned"); | 59 Expect.isFalse(libraries.isEmpty, "Empty libraries map returned"); |
| 56 | 60 |
| 57 var helperLibrary = libraries["mirrors_helper"]; | 61 var helperLibrary = findMirror(libraries.values, "mirrors_helper"); |
| 58 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); | 62 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); |
| 59 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName, | 63 Expect.stringEquals("mirrors_helper", helperLibrary.simpleName, |
| 60 "Unexpected library simple name"); | 64 "Unexpected library simple name"); |
| 61 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName, | 65 Expect.stringEquals("mirrors_helper", helperLibrary.qualifiedName, |
| 62 "Unexpected library qualified name"); | 66 "Unexpected library qualified name"); |
| 67 Expect.equals(helperLibrary, mirrors.findLibrary('mirrors_helper').single); |
| 63 | 68 |
| 64 var helperLibraryLocation = helperLibrary.location; | 69 var helperLibraryLocation = helperLibrary.location; |
| 65 Expect.isNotNull(helperLibraryLocation); | 70 Expect.isNotNull(helperLibraryLocation); |
| 66 Expect.equals(271, helperLibraryLocation.offset, "Unexpected offset"); | 71 Expect.equals(271, helperLibraryLocation.offset, "Unexpected offset"); |
| 67 Expect.equals(23, helperLibraryLocation.length, "Unexpected length"); | 72 Expect.equals(23, helperLibraryLocation.length, "Unexpected length"); |
| 68 Expect.equals(9, helperLibraryLocation.line, "Unexpected line"); | 73 Expect.equals(9, helperLibraryLocation.line, "Unexpected line"); |
| 69 Expect.equals(1, helperLibraryLocation.column, "Unexpected column"); | 74 Expect.equals(1, helperLibraryLocation.column, "Unexpected column"); |
| 70 | 75 |
| 71 | 76 |
| 72 var classes = helperLibrary.classes; | 77 var classes = helperLibrary.classes; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 ////////////////////////////////////////////////////////////////////////////// | 179 ////////////////////////////////////////////////////////////////////////////// |
| 175 // Metadata tests | 180 // Metadata tests |
| 176 ////////////////////////////////////////////////////////////////////////////// | 181 ////////////////////////////////////////////////////////////////////////////// |
| 177 | 182 |
| 178 var metadataList = fooClass.metadata; | 183 var metadataList = fooClass.metadata; |
| 179 Expect.isNotNull(metadataList); | 184 Expect.isNotNull(metadataList); |
| 180 Expect.equals(16, metadataList.length); | 185 Expect.equals(16, metadataList.length); |
| 181 var metadataListIndex = 0; | 186 var metadataListIndex = 0; |
| 182 var metadata; | 187 var metadata; |
| 183 | 188 |
| 184 var dartMirrorsLibrary = system.libraries['dart.mirrors']; | 189 var dartMirrorsLibrary = system.libraries[DART_MIRRORS_URI]; |
| 185 Expect.isNotNull(dartMirrorsLibrary); | 190 Expect.isNotNull(dartMirrorsLibrary); |
| 186 var commentType = dartMirrorsLibrary.classes['Comment']; | 191 var commentType = dartMirrorsLibrary.classes['Comment']; |
| 187 Expect.isNotNull(commentType); | 192 Expect.isNotNull(commentType); |
| 188 | 193 |
| 189 // /// Singleline doc comment. | 194 // /// Singleline doc comment. |
| 190 metadata = metadataList[metadataListIndex++]; | 195 metadata = metadataList[metadataListIndex++]; |
| 191 Expect.isTrue(metadata is InstanceMirror); | 196 Expect.isTrue(metadata is InstanceMirror); |
| 192 Expect.isFalse(metadata.hasReflectee); | 197 Expect.isFalse(metadata.hasReflectee); |
| 193 Expect.throws(() => metadata.reflectee, (_) => true); | 198 Expect.throws(() => metadata.reflectee, (_) => true); |
| 194 Expect.isTrue(metadata is CommentInstanceMirror); | 199 Expect.isTrue(metadata is CommentInstanceMirror); |
| (...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 Expect.isTrue(privateFactoryConstructor.isPrivate); | 1052 Expect.isTrue(privateFactoryConstructor.isPrivate); |
| 1048 Expect.isFalse(privateFactoryConstructor.isConstConstructor); | 1053 Expect.isFalse(privateFactoryConstructor.isConstConstructor); |
| 1049 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); | 1054 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); |
| 1050 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); | 1055 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); |
| 1051 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); | 1056 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); |
| 1052 | 1057 |
| 1053 var metadata = privateClass.metadata; | 1058 var metadata = privateClass.metadata; |
| 1054 Expect.isNotNull(metadata); | 1059 Expect.isNotNull(metadata); |
| 1055 Expect.equals(0, metadata.length); | 1060 Expect.equals(0, metadata.length); |
| 1056 } | 1061 } |
| OLD | NEW |