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"); |
63 | 67 |
64 var helperLibraryLocation = helperLibrary.location; | 68 var helperLibraryLocation = helperLibrary.location; |
65 Expect.isNotNull(helperLibraryLocation); | 69 Expect.isNotNull(helperLibraryLocation); |
66 Expect.equals(271, helperLibraryLocation.offset, "Unexpected offset"); | 70 Expect.equals(271, helperLibraryLocation.offset, "Unexpected offset"); |
67 Expect.equals(23, helperLibraryLocation.length, "Unexpected length"); | 71 Expect.equals(23, helperLibraryLocation.length, "Unexpected length"); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
175 // Metadata tests | 179 // Metadata tests |
176 ////////////////////////////////////////////////////////////////////////////// | 180 ////////////////////////////////////////////////////////////////////////////// |
177 | 181 |
178 var metadataList = fooClass.metadata; | 182 var metadataList = fooClass.metadata; |
179 Expect.isNotNull(metadataList); | 183 Expect.isNotNull(metadataList); |
180 Expect.equals(16, metadataList.length); | 184 Expect.equals(16, metadataList.length); |
181 var metadataListIndex = 0; | 185 var metadataListIndex = 0; |
182 var metadata; | 186 var metadata; |
183 | 187 |
184 var dartMirrorsLibrary = system.libraries['dart.mirrors']; | 188 var dartMirrorsLibrary = system.libraries[DART_MIRRORS_URI]; |
185 Expect.isNotNull(dartMirrorsLibrary); | 189 Expect.isNotNull(dartMirrorsLibrary); |
186 var commentType = dartMirrorsLibrary.classes['Comment']; | 190 var commentType = dartMirrorsLibrary.classes['Comment']; |
187 Expect.isNotNull(commentType); | 191 Expect.isNotNull(commentType); |
188 | 192 |
189 // /// Singleline doc comment. | 193 // /// Singleline doc comment. |
190 metadata = metadataList[metadataListIndex++]; | 194 metadata = metadataList[metadataListIndex++]; |
191 Expect.isTrue(metadata is InstanceMirror); | 195 Expect.isTrue(metadata is InstanceMirror); |
192 Expect.isFalse(metadata.hasReflectee); | 196 Expect.isFalse(metadata.hasReflectee); |
193 Expect.throws(() => metadata.reflectee, (_) => true); | 197 Expect.throws(() => metadata.reflectee, (_) => true); |
194 Expect.isTrue(metadata is CommentInstanceMirror); | 198 Expect.isTrue(metadata is CommentInstanceMirror); |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 Expect.isTrue(privateFactoryConstructor.isPrivate); | 1051 Expect.isTrue(privateFactoryConstructor.isPrivate); |
1048 Expect.isFalse(privateFactoryConstructor.isConstConstructor); | 1052 Expect.isFalse(privateFactoryConstructor.isConstConstructor); |
1049 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); | 1053 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); |
1050 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); | 1054 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); |
1051 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); | 1055 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); |
1052 | 1056 |
1053 var metadata = privateClass.metadata; | 1057 var metadata = privateClass.metadata; |
1054 Expect.isNotNull(metadata); | 1058 Expect.isNotNull(metadata); |
1055 Expect.equals(0, metadata.length); | 1059 Expect.equals(0, metadata.length); |
1056 } | 1060 } |
OLD | NEW |