OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 import "package:expect/expect.dart"; | |
6 import "package:async_helper/async_helper.dart"; | |
7 import 'package:compiler/src/mirrors/source_mirrors.dart'; | |
8 import 'package:compiler/src/mirrors/mirrors_util.dart'; | |
9 import 'package:compiler/src/mirrors/analyze.dart'; | |
10 import 'package:compiler/src/filenames.dart' | |
11 show currentDirectory; | |
12 import 'package:compiler/src/source_file_provider.dart'; | |
13 | |
14 import 'dart:io'; | |
15 | |
16 final Uri DART_MIRRORS_URI = new Uri(scheme: 'dart', path: 'mirrors'); | |
17 | |
18 int count(Iterable iterable) { | |
19 var count = 0; | |
20 for (var element in iterable) { | |
21 count++; | |
22 } | |
23 return count; | |
24 } | |
25 | |
26 bool containsType(TypeMirror expected, Iterable<TypeMirror> iterable) { | |
27 for (var element in iterable) { | |
28 if (element.originalDeclaration == expected.originalDeclaration) { | |
29 return true; | |
30 } | |
31 } | |
32 return false; | |
33 } | |
34 | |
35 DeclarationMirror findMirror(Iterable<DeclarationMirror> list, Symbol name) { | |
36 for (DeclarationMirror mirror in list) { | |
37 if (mirror.simpleName == name) { | |
38 return mirror; | |
39 } | |
40 } | |
41 return null; | |
42 } | |
43 | |
44 main() { | |
45 Uri scriptUri = currentDirectory.resolveUri(Platform.script); | |
46 Uri packageRoot = scriptUri.resolve('../packages/'); | |
47 Uri libUri = scriptUri.resolve('../../../../sdk/'); | |
48 Uri inputUri = scriptUri.resolve('../data/mirrors_helper.dart'); | |
49 var provider = new CompilerSourceFileProvider(); | |
50 var diagnosticHandler = new FormattingDiagnosticHandler(provider); | |
51 asyncStart(); | |
52 var result = analyze([inputUri], libUri, packageRoot, | |
53 provider.readStringFromUri, diagnosticHandler, | |
54 <String>['--preserve-comments']); | |
55 result.then((MirrorSystem mirrors) { | |
56 test(mirrors); | |
57 }).then(asyncSuccess); | |
58 } | |
59 | |
60 void test(MirrorSystem mirrors) { | |
61 Expect.isNotNull(mirrors, "No mirror system returned from compilation"); | |
62 | |
63 var libraries = mirrors.libraries; | |
64 Expect.isNotNull(libraries, "No libraries map returned"); | |
65 Expect.isFalse(libraries.isEmpty, "Empty libraries map returned"); | |
66 | |
67 var helperLibrary = findMirror(libraries.values, #mirrors_helper); | |
68 Expect.isNotNull(helperLibrary, "Library 'mirrors_helper' not found"); | |
69 Expect.equals(#mirrors_helper, helperLibrary.simpleName, | |
70 "Unexpected library simple name"); | |
71 Expect.equals(#mirrors_helper, helperLibrary.qualifiedName, | |
72 "Unexpected library qualified name"); | |
73 Expect.equals(helperLibrary, mirrors.findLibrary(#mirrors_helper)); | |
74 | |
75 var helperLibraryLocation = helperLibrary.location; | |
76 Expect.isNotNull(helperLibraryLocation); | |
77 Expect.equals(271, helperLibraryLocation.offset, "Unexpected offset"); | |
78 Expect.equals(23, helperLibraryLocation.length, "Unexpected length"); | |
79 Expect.equals(9, helperLibraryLocation.line, "Unexpected line"); | |
80 Expect.equals(1, helperLibraryLocation.column, "Unexpected column"); | |
81 | |
82 | |
83 var declarations = helperLibrary.declarations; | |
84 Expect.isNotNull(declarations, "No declarations map returned"); | |
85 Expect.isFalse(declarations.isEmpty, "Empty declarations map returned"); | |
86 | |
87 testFoo(mirrors, helperLibrary, declarations); | |
88 testBar(mirrors, helperLibrary, declarations); | |
89 testBaz(mirrors, helperLibrary, declarations); | |
90 // TODO(johnniwinther): Add test of class [Boz] and typedef [Func]. | |
91 // TODO(johnniwinther): Add tests of type argument substitution, which | |
92 // is not currently implemented in dart2js. | |
93 // TODO(johnniwinther): Add tests of Location and Source. | |
94 testPrivate(mirrors, helperLibrary, declarations); | |
95 } | |
96 | |
97 // Testing class Foo: | |
98 // | |
99 // class Foo { | |
100 // | |
101 // } | |
102 void testFoo(MirrorSystem system, LibraryMirror helperLibrary, | |
103 Map<Symbol, DeclarationMirror> declarations) { | |
104 var fooClass = declarations[#Foo]; | |
105 Expect.isNotNull(fooClass, "Type 'Foo' not found"); | |
106 Expect.isTrue(fooClass is ClassMirror, | |
107 "Unexpected mirror type returned"); | |
108 Expect.equals(#Foo, fooClass.simpleName, | |
109 "Unexpected type simple name"); | |
110 Expect.equals(#mirrors_helper.Foo, fooClass.qualifiedName, | |
111 "Unexpected type qualified name"); | |
112 | |
113 Expect.equals(helperLibrary, getLibrary(fooClass), | |
114 "Unexpected library returned from type"); | |
115 | |
116 Expect.isFalse(isObject(fooClass), "Class is Object"); | |
117 Expect.isFalse(fooClass.isDynamic, "Class is dynamic"); | |
118 Expect.isFalse(fooClass.isVoid, "Class is void"); | |
119 Expect.isFalse(fooClass is TypeVariableMirror, "Class is a type variable"); | |
120 Expect.isFalse(fooClass is TypedefMirror, "Class is a typedef"); | |
121 Expect.isFalse(fooClass is FunctionTypeMirror, "Class is a function"); | |
122 | |
123 Expect.isTrue(fooClass.isOriginalDeclaration); | |
124 Expect.equals(fooClass, fooClass.originalDeclaration); | |
125 | |
126 Expect.isTrue(fooClass is ClassMirror, "Class is not class"); | |
127 Expect.isFalse(fooClass.isAbstract); | |
128 Expect.isFalse(fooClass.isPrivate, "Class is private"); | |
129 | |
130 var objectType = fooClass.superclass; | |
131 Expect.isNotNull(objectType, "Superclass is null"); | |
132 Expect.isTrue(isObject(objectType), "Object is not Object"); | |
133 Expect.isTrue(objectType.isOriginalDeclaration); | |
134 Expect.isTrue(containsType(fooClass, | |
135 computeSubdeclarations(system, objectType)), | |
136 "Class is not subclass of superclass"); | |
137 | |
138 var fooInterfaces = fooClass.superinterfaces; | |
139 Expect.isNotNull(fooInterfaces, "Interfaces map is null"); | |
140 Expect.isTrue(fooInterfaces.isEmpty, "Interfaces map is not empty"); | |
141 | |
142 var fooSubdeclarations = computeSubdeclarations(system, fooClass); | |
143 Expect.equals(1, count(fooSubdeclarations), "Unexpected subtype count"); | |
144 for (var fooSubdeclaration in fooSubdeclarations) { | |
145 Expect.equals(fooClass, fooSubdeclaration.superclass.originalDeclaration); | |
146 } | |
147 | |
148 Expect.isTrue(fooClass.typeArguments.isEmpty); | |
149 var fooClassTypeVariables = fooClass.typeVariables; | |
150 Expect.isNotNull(fooClassTypeVariables, "Type variable list is null"); | |
151 Expect.isTrue(fooClassTypeVariables.isEmpty, | |
152 "Type variable list is not empty"); | |
153 | |
154 var fooClassMembers = fooClass.declarations; | |
155 Expect.isNotNull(fooClassMembers, "Declared members map is null"); | |
156 Expect.equals(1, fooClassMembers.length); | |
157 | |
158 var fooM = fooClassMembers[#m]; | |
159 Expect.isNotNull(fooM); | |
160 Expect.isTrue(fooM is MethodMirror); | |
161 Expect.equals(1, fooM.parameters.length); | |
162 var fooMa = fooM.parameters[0]; | |
163 Expect.isNotNull(fooMa); | |
164 Expect.isTrue(fooMa is ParameterMirror); | |
165 | |
166 ////////////////////////////////////////////////////////////////////////////// | |
167 // Metadata tests | |
168 ////////////////////////////////////////////////////////////////////////////// | |
169 | |
170 var metadataList = fooClass.metadata; | |
171 Expect.isNotNull(metadataList); | |
172 Expect.equals(14, metadataList.length); | |
173 var metadataListIndex = 0; | |
174 var metadata; | |
175 | |
176 var dartMirrorsLibrary = system.libraries[DART_MIRRORS_URI]; | |
177 Expect.isNotNull(dartMirrorsLibrary); | |
178 var commentType = dartMirrorsLibrary.declarations[#Comment]; | |
179 Expect.isNotNull(commentType); | |
180 | |
181 // /// Singleline doc comment. | |
182 metadata = metadataList[metadataListIndex++]; | |
183 Expect.isTrue(metadata is InstanceMirror); | |
184 Expect.isFalse(metadata.hasReflectee); | |
185 Expect.throws(() => metadata.reflectee, (_) => true); | |
186 Expect.isTrue(metadata is CommentInstanceMirror, | |
187 "Unexpected metadata: $metadata"); | |
188 Expect.equals(commentType.originalDeclaration, metadata.type); | |
189 Expect.isTrue(metadata.isDocComment); | |
190 Expect.stringEquals( | |
191 "/// Singleline doc comment.", metadata.text); | |
192 Expect.stringEquals( | |
193 "Singleline doc comment.", metadata.trimmedText); | |
194 | |
195 // @Metadata(null) | |
196 metadata = metadataList[metadataListIndex++]; | |
197 var metadataType = metadata.type; | |
198 Expect.isTrue(metadata is InstanceMirror); | |
199 Expect.isFalse(metadata.hasReflectee); | |
200 Expect.throws(() => metadata.reflectee, (_) => true); | |
201 Expect.isTrue(metadataType.isOriginalDeclaration); | |
202 InstanceMirror data = metadata.getField(#data); | |
203 Expect.isNotNull(data); | |
204 Expect.isTrue(data.hasReflectee); | |
205 Expect.isNull(data.reflectee); | |
206 | |
207 // Singleline comment 1. | |
208 metadata = metadataList[metadataListIndex++]; | |
209 Expect.isTrue(metadata is InstanceMirror); | |
210 Expect.isFalse(metadata.hasReflectee); | |
211 Expect.throws(() => metadata.reflectee, (_) => true); | |
212 Expect.isTrue(metadata is CommentInstanceMirror); | |
213 Expect.equals(commentType.originalDeclaration, metadata.type); | |
214 Expect.isFalse(metadata.isDocComment); | |
215 Expect.stringEquals( | |
216 "// Singleline comment 1.", metadata.text); | |
217 Expect.stringEquals( | |
218 "Singleline comment 1.", metadata.trimmedText); | |
219 | |
220 // Singleline comment 2. | |
221 metadata = metadataList[metadataListIndex++]; | |
222 Expect.isTrue(metadata is InstanceMirror); | |
223 Expect.isFalse(metadata.hasReflectee); | |
224 Expect.throws(() => metadata.reflectee, (_) => true); | |
225 Expect.isTrue(metadata is CommentInstanceMirror); | |
226 Expect.equals(commentType.originalDeclaration, metadata.type); | |
227 Expect.isFalse(metadata.isDocComment); | |
228 Expect.stringEquals( | |
229 "// Singleline comment 2.", metadata.text); | |
230 Expect.stringEquals( | |
231 "Singleline comment 2.", metadata.trimmedText); | |
232 | |
233 // @Metadata(true) | |
234 metadata = metadataList[metadataListIndex++]; | |
235 Expect.isTrue(metadata is InstanceMirror); | |
236 Expect.isFalse(metadata.hasReflectee); | |
237 Expect.throws(() => metadata.reflectee, (_) => true); | |
238 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
239 data = metadata.getField(#data); | |
240 Expect.isNotNull(data); | |
241 Expect.isTrue(data.hasReflectee); | |
242 Expect.isTrue(data.reflectee); | |
243 | |
244 // @Metadata(false) | |
245 metadata = metadataList[metadataListIndex++]; | |
246 Expect.isTrue(metadata is InstanceMirror); | |
247 Expect.isFalse(metadata.hasReflectee); | |
248 Expect.throws(() => metadata.reflectee, (_) => true); | |
249 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
250 data = metadata.getField(#data); | |
251 Expect.isNotNull(data); | |
252 Expect.isTrue(data.hasReflectee); | |
253 Expect.isFalse(data.reflectee); | |
254 | |
255 // @Metadata(0) | |
256 metadata = metadataList[metadataListIndex++]; | |
257 Expect.isTrue(metadata is InstanceMirror); | |
258 Expect.isFalse(metadata.hasReflectee); | |
259 Expect.throws(() => metadata.reflectee, (_) => true); | |
260 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
261 data = metadata.getField(#data); | |
262 Expect.isNotNull(data); | |
263 Expect.isTrue(data.hasReflectee); | |
264 Expect.equals(0, data.reflectee); | |
265 | |
266 // @Metadata(1.5) | |
267 metadata = metadataList[metadataListIndex++]; | |
268 Expect.isTrue(metadata is InstanceMirror); | |
269 Expect.isFalse(metadata.hasReflectee); | |
270 Expect.throws(() => metadata.reflectee, (_) => true); | |
271 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
272 data = metadata.getField(#data); | |
273 Expect.isNotNull(data); | |
274 Expect.isTrue(data.hasReflectee); | |
275 Expect.equals(1.5, data.reflectee); | |
276 | |
277 // @Metadata("Foo") | |
278 metadata = metadataList[metadataListIndex++]; | |
279 Expect.isTrue(metadata is InstanceMirror); | |
280 Expect.isFalse(metadata.hasReflectee); | |
281 Expect.throws(() => metadata.reflectee, (_) => true); | |
282 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
283 data = metadata.getField(#data); | |
284 Expect.isNotNull(data); | |
285 Expect.isTrue(data.hasReflectee); | |
286 Expect.stringEquals("Foo", data.reflectee); | |
287 | |
288 // @Metadata(const ["Foo"]) | |
289 metadata = metadataList[metadataListIndex++]; | |
290 Expect.isTrue(metadata is InstanceMirror); | |
291 Expect.isFalse(metadata.hasReflectee); | |
292 Expect.throws(() => metadata.reflectee, (_) => true); | |
293 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
294 data = metadata.getField(#data); | |
295 Expect.isTrue(data is ListInstanceMirror); | |
296 Expect.isFalse(data.hasReflectee); | |
297 Expect.throws(() => data.reflectee, (_) => true); | |
298 ListInstanceMirror listData = data; | |
299 Expect.equals(1, listData.length); | |
300 InstanceMirror element = listData.getElement(0); | |
301 Expect.isNotNull(element); | |
302 Expect.isTrue(element.hasReflectee); | |
303 Expect.stringEquals("Foo", element.reflectee); | |
304 | |
305 // @Metadata(/* Inline comment */ const {'foo':"Foo"}) | |
306 metadata = metadataList[metadataListIndex++]; | |
307 Expect.isTrue(metadata is InstanceMirror); | |
308 Expect.isFalse(metadata.hasReflectee); | |
309 Expect.throws(() => metadata.reflectee, (_) => true); | |
310 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
311 data = metadata.getField(#data); | |
312 Expect.isTrue(data is MapInstanceMirror); | |
313 Expect.isFalse(data.hasReflectee); | |
314 Expect.throws(() => data.reflectee, (_) => true); | |
315 MapInstanceMirror mapData = data; | |
316 Expect.equals(1, mapData.length); | |
317 var it = mapData.keys.iterator; | |
318 Expect.isTrue(it.moveNext()); | |
319 Expect.stringEquals('foo', it.current); | |
320 element = mapData.getValue('foo'); | |
321 Expect.isNotNull(element); | |
322 Expect.isTrue(element.hasReflectee); | |
323 Expect.stringEquals("Foo", element.reflectee); | |
324 Expect.isNull(mapData.getValue('bar')); | |
325 | |
326 // @metadata | |
327 var metadataRef = metadata = metadataList[metadataListIndex++]; | |
328 Expect.isTrue(metadata is InstanceMirror); | |
329 Expect.isFalse(metadata.hasReflectee); | |
330 Expect.throws(() => metadata.reflectee, (_) => true); | |
331 Expect.equals(metadataType.originalDeclaration, metadata.type); | |
332 data = metadata.getField(#data); | |
333 Expect.isNotNull(data); | |
334 Expect.isTrue(data.hasReflectee); | |
335 Expect.isNull(data.reflectee); | |
336 | |
337 // /** Multiline doc comment. */ | |
338 metadata = metadataList[metadataListIndex++]; | |
339 Expect.isTrue(metadata is InstanceMirror); | |
340 Expect.isFalse(metadata.hasReflectee); | |
341 Expect.throws(() => metadata.reflectee, (_) => true); | |
342 Expect.isTrue(metadata is CommentInstanceMirror); | |
343 Expect.equals(commentType.originalDeclaration, metadata.type); | |
344 Expect.isTrue(metadata.isDocComment); | |
345 Expect.stringEquals( | |
346 "/** Multiline doc comment. */", metadata.text); | |
347 Expect.stringEquals( | |
348 "Multiline doc comment. ", metadata.trimmedText); | |
349 | |
350 // /* Multiline comment. */ | |
351 metadata = metadataList[metadataListIndex++]; | |
352 Expect.isTrue(metadata is InstanceMirror); | |
353 Expect.isFalse(metadata.hasReflectee); | |
354 Expect.throws(() => metadata.reflectee, (_) => true); | |
355 Expect.isTrue(metadata is CommentInstanceMirror); | |
356 Expect.equals(commentType.originalDeclaration, metadata.type); | |
357 Expect.isFalse(metadata.isDocComment); | |
358 Expect.stringEquals( | |
359 "/* Multiline comment. */", metadata.text); | |
360 Expect.stringEquals( | |
361 "Multiline comment. ", metadata.trimmedText); | |
362 | |
363 Expect.equals(metadataList.length, metadataListIndex); | |
364 | |
365 Expect.isNotNull(fooMa.metadata); | |
366 Expect.equals(1, fooMa.metadata.length); | |
367 Expect.equals(metadataRef, fooMa.metadata[0]); | |
368 | |
369 ////////////////////////////////////////////////////////////////////////////// | |
370 // Location test | |
371 ////////////////////////////////////////////////////////////////////////////// | |
372 | |
373 var fooClassLocation = fooClass.location; | |
374 Expect.isNotNull(fooClassLocation); | |
375 // Expect the location to start with the first metadata, not including the | |
376 // leading comment. | |
377 Expect.equals(376, fooClassLocation.offset, "Unexpected offset"); | |
378 // Expect the location to end with the class body. | |
379 Expect.equals(298, fooClassLocation.length, "Unexpected length"); | |
380 Expect.equals(18, fooClassLocation.line, "Unexpected line"); | |
381 Expect.equals(1, fooClassLocation.column, "Unexpected column"); | |
382 | |
383 } | |
384 | |
385 // Testing abstract class Bar: | |
386 // | |
387 // abstract class Bar<E> { | |
388 // | |
389 // } | |
390 void testBar(MirrorSystem system, LibraryMirror helperLibrary, | |
391 Map<Symbol, DeclarationMirror> classes) { | |
392 var barClass = classes[#Bar]; | |
393 Expect.isNotNull(barClass, "Type 'Bar' not found"); | |
394 Expect.isTrue(barClass is ClassMirror, | |
395 "Unexpected mirror type returned"); | |
396 Expect.equals(#Bar, barClass.simpleName, | |
397 "Unexpected type simple name"); | |
398 Expect.equals(#mirrors_helper.Bar, barClass.qualifiedName, | |
399 "Unexpected type qualified name"); | |
400 | |
401 Expect.equals(helperLibrary, getLibrary(barClass), | |
402 "Unexpected library returned from type"); | |
403 | |
404 Expect.isFalse(isObject(barClass), "Interface is Object"); | |
405 Expect.isFalse(barClass.isDynamic, "Interface is dynamic"); | |
406 Expect.isFalse(barClass.isVoid, "Interface is void"); | |
407 Expect.isFalse(barClass is TypeVariableMirror, "Interface is a type variable")
; | |
408 Expect.isFalse(barClass is TypedefMirror, "Interface is a typedef"); | |
409 Expect.isFalse(barClass is FunctionTypeMirror, "Interface is a function"); | |
410 | |
411 Expect.isTrue(barClass.isOriginalDeclaration); | |
412 Expect.equals(barClass, barClass.originalDeclaration); | |
413 | |
414 Expect.isTrue(barClass is ClassMirror); | |
415 Expect.isTrue(barClass.isAbstract); | |
416 Expect.isFalse(barClass.isPrivate, "Interface is private"); | |
417 | |
418 var objectType = barClass.superclass; | |
419 Expect.isNotNull(objectType, "Superclass is null"); | |
420 Expect.isTrue(isObject(objectType), "Object is not Object"); | |
421 Expect.isTrue(objectType.isOriginalDeclaration); | |
422 Expect.isTrue(containsType(barClass, | |
423 computeSubdeclarations(system, objectType)), | |
424 "Class is not subclass of superclass"); | |
425 | |
426 var barInterfaces = barClass.superinterfaces; | |
427 Expect.isNotNull(barInterfaces, "Interfaces map is null"); | |
428 Expect.isTrue(barInterfaces.isEmpty, "Interfaces map is not empty"); | |
429 | |
430 var barSubdeclarations = computeSubdeclarations(system, barClass); | |
431 Expect.equals(1, count(barSubdeclarations), "Unexpected subtype count"); | |
432 for (var barSubdeclaration in barSubdeclarations) { | |
433 Expect.isTrue(containsType(barClass, | |
434 barSubdeclaration.superinterfaces), | |
435 "Interface is not superinterface of subclass"); | |
436 } | |
437 | |
438 Expect.isTrue(barClass.typeArguments.isEmpty); | |
439 var barInterfaceTypeVariables = barClass.typeVariables; | |
440 Expect.isNotNull(barInterfaceTypeVariables, "Type variable list is null"); | |
441 Expect.isFalse(barInterfaceTypeVariables.isEmpty, | |
442 "Type variable list is empty"); | |
443 Expect.equals(barInterfaceTypeVariables.length, 1, | |
444 "Unexpected number of type variables"); | |
445 | |
446 var barE = barInterfaceTypeVariables[0]; | |
447 Expect.isNotNull(barE, "Type variable is null"); | |
448 Expect.isTrue(barE is TypeVariableMirror); | |
449 | |
450 var barInterfaceMembers = barClass.declarations; | |
451 Expect.isNotNull(barInterfaceMembers, "Declared members map is null"); | |
452 Expect.isTrue(barInterfaceMembers.isEmpty, | |
453 "Declarations map is unempty"); | |
454 | |
455 var metadata = barClass.metadata; | |
456 Expect.isNotNull(metadata); | |
457 Expect.equals(0, metadata.length); | |
458 } | |
459 | |
460 // Testing class Baz: | |
461 // | |
462 // class Baz<E,F extends Foo> implements Bar<E> { | |
463 // Baz(); | |
464 // const Baz.named(); | |
465 // factory Baz.factory() => new Baz<E,F>(); | |
466 // | |
467 // static method1(e) {} | |
468 // void method2(E e, [F f = null]) {} | |
469 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; | |
470 // | |
471 // bool operator==(Object other) => false; | |
472 // int operator -() => 0; | |
473 // operator$foo() {} | |
474 // } | |
475 void testBaz(MirrorSystem system, LibraryMirror helperLibrary, | |
476 Map<Symbol, DeclarationMirror> declarations) { | |
477 var bazClass = declarations[#Baz]; | |
478 Expect.isNotNull(bazClass, "Type 'Baz' not found"); | |
479 Expect.isTrue(bazClass is ClassMirror, | |
480 "Unexpected mirror type returned"); | |
481 Expect.equals(#Baz, bazClass.simpleName, | |
482 "Unexpected type simple name"); | |
483 Expect.equals(#mirrors_helper.Baz, bazClass.qualifiedName, | |
484 "Unexpected type qualified name"); | |
485 | |
486 Expect.equals(helperLibrary, getLibrary(bazClass), | |
487 "Unexpected library returned from type"); | |
488 | |
489 Expect.isFalse(isObject(bazClass), "Class is Object"); | |
490 Expect.isFalse(bazClass.isDynamic, "Class is dynamic"); | |
491 Expect.isFalse(bazClass.isVoid, "Class is void"); | |
492 Expect.isFalse(bazClass is TypeVariableMirror, "Class is a type variable"); | |
493 Expect.isFalse(bazClass is TypedefMirror, "Class is a typedef"); | |
494 Expect.isFalse(bazClass is FunctionTypeMirror, "Class is a function"); | |
495 | |
496 Expect.isTrue(bazClass.isOriginalDeclaration); | |
497 Expect.equals(bazClass, bazClass.originalDeclaration); | |
498 | |
499 Expect.isTrue(bazClass is ClassMirror, "Class is not class"); | |
500 Expect.isFalse(bazClass.isAbstract); | |
501 Expect.isFalse(bazClass.isPrivate, "Class is private"); | |
502 | |
503 var objectType = bazClass.superclass; | |
504 Expect.isNotNull(objectType, "Superclass is null"); | |
505 Expect.isTrue(isObject(objectType), "Object is not Object"); | |
506 Expect.isTrue(objectType.isOriginalDeclaration); | |
507 Expect.isTrue(containsType(bazClass, | |
508 computeSubdeclarations(system, objectType)), | |
509 "Class is not subclass of superclass"); | |
510 | |
511 var bazInterfaces = bazClass.superinterfaces; | |
512 Expect.isNotNull(bazInterfaces, "Interfaces map is null"); | |
513 Expect.isTrue(!bazInterfaces.isEmpty, "Interfaces map is empty"); | |
514 for (var bazInterface in bazInterfaces) { | |
515 Expect.isTrue(containsType(bazClass, | |
516 computeSubdeclarations(system, objectType)), | |
517 "Class is not subclass of superinterface"); | |
518 } | |
519 | |
520 var bazSubdeclarations = computeSubdeclarations(system, bazClass); | |
521 Expect.equals(0, count(bazSubdeclarations), "Unexpected subtype count"); | |
522 | |
523 var barInterface = findMirror(bazInterfaces, #Bar); | |
524 Expect.isNotNull(barInterface, "Interface bar is missing"); | |
525 Expect.isFalse(barInterface.isOriginalDeclaration); | |
526 var barInterfaceTypeArguments = barInterface.typeArguments; | |
527 Expect.isNotNull(barInterfaceTypeArguments, "Type arguments are missing"); | |
528 Expect.equals(1, barInterfaceTypeArguments.length, | |
529 "Type arguments is empty"); | |
530 | |
531 Expect.isTrue(bazClass.typeArguments.isEmpty, "Class has type arguments"); | |
532 var bazClassTypeVariables = bazClass.typeVariables; | |
533 Expect.isNotNull(bazClassTypeVariables, "Type variable list is null"); | |
534 Expect.equals(2, bazClassTypeVariables.length, | |
535 "Type variable list is not empty"); | |
536 | |
537 var bazE = bazClassTypeVariables[0]; | |
538 Expect.isNotNull(bazE, "Type variable is null"); | |
539 Expect.equals(#E, bazE.simpleName, "Unexpected simpleName"); | |
540 Expect.equals(#mirrors_helper.Baz.E, bazE.qualifiedName, | |
541 "Unexpected qualifiedName"); | |
542 Expect.equals(bazClass, bazE.owner, | |
543 "Unexpected type variable declarer"); | |
544 var bazEbound = bazE.upperBound; | |
545 Expect.isNotNull(bazEbound); | |
546 Expect.isTrue(bazEbound.isOriginalDeclaration); | |
547 Expect.isTrue(isObject(bazEbound), "Bound is not object"); | |
548 | |
549 var bazF = bazClassTypeVariables[1]; | |
550 Expect.isNotNull(bazF, "Type variable is null"); | |
551 Expect.equals(#F, bazF.simpleName, "Unexpected simpleName"); | |
552 Expect.equals(#mirrors_helper.Baz.F, bazF.qualifiedName, | |
553 "Unexpected qualifiedName"); | |
554 Expect.equals(bazClass, bazF.owner); | |
555 var bazFbound = bazF.upperBound; | |
556 Expect.isNotNull(bazFbound); | |
557 Expect.isTrue(bazFbound.isOriginalDeclaration); | |
558 Expect.equals(#mirrors_helper.Foo, bazFbound.qualifiedName, | |
559 "Bound is not Foo"); | |
560 | |
561 var bazClassMembers = bazClass.declarations; | |
562 Expect.isNotNull(bazClassMembers, "Declared members map is null"); | |
563 Expect.equals(9, bazClassMembers.length, | |
564 "Unexpected number of declared members"); | |
565 | |
566 //////////////////////////////////////////////////////////////////////////// | |
567 // static method1(e) {} | |
568 //////////////////////////////////////////////////////////////////////////// | |
569 var method1 = bazClassMembers[#method1]; | |
570 Expect.isNotNull(method1, "method1 not found"); | |
571 Expect.equals(#method1, method1.simpleName); | |
572 Expect.equals(#mirrors_helper.Baz.method1, method1.qualifiedName); | |
573 Expect.equals(method1.owner, bazClass); | |
574 Expect.isFalse(method1.isTopLevel); | |
575 Expect.isTrue(method1 is MethodMirror); | |
576 Expect.isFalse(method1.isConstructor); | |
577 Expect.isFalse(method1.isPrivate); | |
578 Expect.isTrue(method1.isStatic); | |
579 Expect.isTrue(method1.isRegularMethod); | |
580 Expect.isFalse(method1.isConstConstructor); | |
581 Expect.isFalse(method1.isGenerativeConstructor); | |
582 Expect.isFalse(method1.isRedirectingConstructor); | |
583 Expect.isFalse(method1.isFactoryConstructor); | |
584 Expect.isFalse(method1.isGetter); | |
585 Expect.isFalse(method1.isSetter); | |
586 Expect.isFalse(method1.isOperator); | |
587 | |
588 var dynamicType = method1.returnType; | |
589 Expect.isNotNull(dynamicType, "Return type was null"); | |
590 Expect.isFalse(isObject(dynamicType), "dynamic is Object"); | |
591 Expect.isTrue(dynamicType.isDynamic, "dynamic is not dynamic"); | |
592 Expect.isFalse(dynamicType.isVoid, "dynamic is void"); | |
593 Expect.isFalse(dynamicType is TypeVariableMirror, "dynamic is a type variable"
); | |
594 Expect.isFalse(dynamicType is TypedefMirror, "dynamic is a typedef"); | |
595 Expect.isFalse(dynamicType is FunctionTypeMirror, "dynamic is a function"); | |
596 | |
597 var method1Parameters = method1.parameters; | |
598 Expect.isNotNull(method1Parameters, "Method parameters is null"); | |
599 Expect.equals(1, method1Parameters.length, "Unexpected parameter count"); | |
600 var method1Parameter1 = method1Parameters[0]; | |
601 Expect.isNotNull(method1Parameter1, "Parameter is null"); | |
602 Expect.equals(dynamicType, method1Parameter1.type); | |
603 Expect.equals(#e, method1Parameter1.simpleName); | |
604 Expect.equals(#mirrors_helper.Baz.method1.e, method1Parameter1.qualifiedName); | |
605 Expect.isFalse(method1Parameter1.hasDefaultValue, | |
606 "Parameter has default value"); | |
607 Expect.isNull(method1Parameter1.defaultValue, | |
608 "Parameter default value is non-null"); | |
609 Expect.isFalse(method1Parameter1.isOptional, "Parameter is optional"); | |
610 | |
611 //////////////////////////////////////////////////////////////////////////// | |
612 // static void method2(E e, [F f = null]) {} | |
613 //////////////////////////////////////////////////////////////////////////// | |
614 var method2 = bazClassMembers[#method2]; | |
615 Expect.isNotNull(method2, "method2 not found"); | |
616 Expect.equals(#method2, method2.simpleName); | |
617 Expect.equals(#mirrors_helper.Baz.method2, method2.qualifiedName); | |
618 Expect.equals(method2.owner, bazClass); | |
619 Expect.isFalse(method2.isTopLevel); | |
620 Expect.isTrue(method2 is MethodMirror); | |
621 Expect.isFalse(method2.isConstructor); | |
622 Expect.isFalse(method2.isPrivate); | |
623 Expect.isFalse(method2.isStatic); | |
624 Expect.isTrue(method2.isRegularMethod); | |
625 Expect.isFalse(method2.isConstConstructor); | |
626 Expect.isFalse(method2.isGenerativeConstructor); | |
627 Expect.isFalse(method2.isRedirectingConstructor); | |
628 Expect.isFalse(method2.isFactoryConstructor); | |
629 Expect.isFalse(method2.isGetter); | |
630 Expect.isFalse(method2.isSetter); | |
631 Expect.isFalse(method2.isOperator); | |
632 | |
633 var voidType = method2.returnType; | |
634 Expect.isNotNull(voidType, "Return type was null"); | |
635 Expect.isFalse(isObject(voidType), "void is Object"); | |
636 Expect.isFalse(voidType.isDynamic, "void is dynamic"); | |
637 Expect.isTrue(voidType.isVoid, "void is not void"); | |
638 Expect.isFalse(voidType is TypeVariableMirror, "void is a type variable"); | |
639 Expect.isFalse(voidType is TypedefMirror, "void is a typedef"); | |
640 Expect.isFalse(voidType is FunctionTypeMirror, "void is a function"); | |
641 | |
642 var method2Parameters = method2.parameters; | |
643 Expect.isNotNull(method2Parameters, "Method parameters is null"); | |
644 Expect.equals(2, method2Parameters.length, "Unexpected parameter count"); | |
645 var method2Parameter1 = method2Parameters[0]; | |
646 Expect.isNotNull(method2Parameter1, "Parameter is null"); | |
647 Expect.equals(bazE, method2Parameter1.type); | |
648 Expect.equals(#e, method2Parameter1.simpleName); | |
649 Expect.equals(#mirrors_helper.Baz.method2.e, method2Parameter1.qualifiedName); | |
650 Expect.isFalse(method2Parameter1.hasDefaultValue, | |
651 "Parameter has default value"); | |
652 Expect.isNull(method2Parameter1.defaultValue, | |
653 "Parameter default value is non-null"); | |
654 Expect.isFalse(method2Parameter1.isOptional, "Parameter is optional"); | |
655 var method2Parameter2 = method2Parameters[1]; | |
656 Expect.isNotNull(method2Parameter2, "Parameter is null"); | |
657 Expect.equals(bazF, method2Parameter2.type); | |
658 Expect.equals(#f, method2Parameter2.simpleName); | |
659 Expect.equals(#mirrors_helper.Baz.method2.f, | |
660 method2Parameter2.qualifiedName); | |
661 Expect.isTrue(method2Parameter2.hasDefaultValue, | |
662 "Parameter has default value"); | |
663 Expect.isNotNull(method2Parameter2.defaultValue, | |
664 "Parameter default value is null"); | |
665 Expect.isTrue(method2Parameter2.isOptional, "Parameter is not optional"); | |
666 | |
667 //////////////////////////////////////////////////////////////////////////// | |
668 // Baz<E,F> method3(E func1(F f), Func<E,F> func2) => null; | |
669 //////////////////////////////////////////////////////////////////////////// | |
670 var method3 = bazClassMembers[#method3]; | |
671 Expect.isNotNull(method3, "method3 not found"); | |
672 Expect.equals(#method3, method3.simpleName); | |
673 Expect.equals(#mirrors_helper.Baz.method3, method3.qualifiedName); | |
674 Expect.equals(method3.owner, bazClass); | |
675 Expect.isFalse(method3.isTopLevel); | |
676 Expect.isTrue(method3 is MethodMirror); | |
677 Expect.isFalse(method3.isConstructor); | |
678 Expect.isFalse(method3.isPrivate); | |
679 Expect.isFalse(method3.isStatic); | |
680 Expect.isTrue(method3.isRegularMethod); | |
681 Expect.isFalse(method3.isConstConstructor); | |
682 Expect.isFalse(method3.isGenerativeConstructor); | |
683 Expect.isFalse(method3.isRedirectingConstructor); | |
684 Expect.isFalse(method3.isFactoryConstructor); | |
685 Expect.isFalse(method3.isGetter); | |
686 Expect.isFalse(method3.isSetter); | |
687 Expect.isFalse(method3.isOperator); | |
688 | |
689 var method3ReturnType = method3.returnType; | |
690 Expect.isNotNull(method3ReturnType, "Return type is null"); | |
691 Expect.isTrue(method3ReturnType is ClassMirror, | |
692 "Return type is not interface"); | |
693 Expect.equals(bazClass, method3ReturnType.originalDeclaration); | |
694 // TODO(johnniwinther): Test type arguments of [method3ReturnType]. | |
695 | |
696 var method3Parameters = method3.parameters; | |
697 Expect.isNotNull(method3Parameters, "Method parameters is null"); | |
698 Expect.equals(2, method3Parameters.length, "Unexpected parameter count"); | |
699 var method3Parameter1 = method3Parameters[0]; | |
700 Expect.isNotNull(method3Parameter1, "Parameter is null"); | |
701 var method3Parameter1type = method3Parameter1.type; | |
702 Expect.isNotNull(method3Parameter1type, "Parameter type of 'func1' is null"); | |
703 Expect.isTrue(method3Parameter1type is FunctionTypeMirror, | |
704 "Parameter type of 'func1' is not a function"); | |
705 Expect.equals(bazE, method3Parameter1type.returnType, | |
706 "Return type of 'func1' is not a E"); | |
707 Expect.isNotNull(method3Parameter1type.parameters, | |
708 "Parameters of 'func1' is null"); | |
709 Expect.equals(1, method3Parameter1type.parameters.length, | |
710 "Unexpected parameter count of 'func1'"); | |
711 Expect.equals(bazE, method3Parameter1type.returnType, | |
712 "Return type of 'func1' is not a E"); | |
713 Expect.isNotNull(method3Parameter1type.parameters[0], | |
714 "Parameter 1 of 'func1' is null"); | |
715 Expect.equals(#f, method3Parameter1type.parameters[0].simpleName); | |
716 Expect.equals(bazF, method3Parameter1type.parameters[0].type, | |
717 "Argument type of 'func1' is not a F"); | |
718 Expect.equals(#func1, method3Parameter1.simpleName); | |
719 Expect.equals(#mirrors_helper.Baz.method3.func1, | |
720 method3Parameter1.qualifiedName); | |
721 Expect.isFalse(method3Parameter1.hasDefaultValue, | |
722 "Parameter has default value"); | |
723 Expect.isNull(method3Parameter1.defaultValue, | |
724 "Parameter default value is non-null"); | |
725 Expect.isFalse(method3Parameter1.isOptional, "Parameter is optional"); | |
726 | |
727 var method3Parameter2 = method3Parameters[1]; | |
728 Expect.isNotNull(method3Parameter2, "Parameter is null"); | |
729 var funcTypedef = method3Parameter2.type; | |
730 Expect.isNotNull(funcTypedef, "Parameter type is null"); | |
731 Expect.equals(#Func, funcTypedef.simpleName); | |
732 Expect.equals(#mirrors_helper.Func, funcTypedef.qualifiedName); | |
733 Expect.isFalse(isObject(funcTypedef), "Typedef is Object"); | |
734 Expect.isFalse(funcTypedef.isDynamic, "Typedef is dynamic"); | |
735 Expect.isFalse(funcTypedef.isVoid, "Typedef is void"); | |
736 Expect.isFalse(funcTypedef is TypeVariableMirror, "Typedef is a type variable"
); | |
737 Expect.isTrue(funcTypedef is TypedefMirror, "Typedef is not a typedef"); | |
738 Expect.isFalse(funcTypedef is FunctionTypeMirror, "Typedef is a function"); | |
739 | |
740 Expect.equals(helperLibrary, getLibrary(funcTypedef), | |
741 "Unexpected typedef library"); | |
742 | |
743 Expect.isFalse(funcTypedef.isOriginalDeclaration); | |
744 Expect.isFalse(funcTypedef is ClassMirror, "Typedef is class"); | |
745 Expect.isFalse(funcTypedef.isPrivate, "Typedef is private"); | |
746 Expect.equals(2, funcTypedef.typeArguments.length); | |
747 var funcTypedefTypeVariables = funcTypedef.typeVariables; | |
748 Expect.isNotNull(funcTypedefTypeVariables); | |
749 Expect.equals(2, funcTypedefTypeVariables.length); | |
750 | |
751 var funcTypedefDefinition = funcTypedef.referent; | |
752 Expect.isNotNull(funcTypedefDefinition); | |
753 Expect.isTrue(funcTypedefDefinition is FunctionTypeMirror); | |
754 | |
755 Expect.equals(#func2, method3Parameter2.simpleName); | |
756 Expect.equals(#mirrors_helper.Baz.method3.func2, | |
757 method3Parameter2.qualifiedName); | |
758 Expect.isFalse(method3Parameter2.hasDefaultValue, | |
759 "Parameter 'func2' has default value: " | |
760 "${method3Parameter2.defaultValue}"); | |
761 Expect.isNull(method3Parameter2.defaultValue, | |
762 "Parameter default value is non-null"); | |
763 Expect.isFalse(method3Parameter2.isOptional, "Parameter is optional"); | |
764 | |
765 //////////////////////////////////////////////////////////////////////////// | |
766 // bool operator==(Object other) => false; | |
767 //////////////////////////////////////////////////////////////////////////// | |
768 var operator_eq = bazClassMembers[const Symbol('==')]; | |
769 Expect.isNotNull(operator_eq, "operator == not found"); | |
770 Expect.equals(const Symbol('=='), operator_eq.simpleName, | |
771 "Unexpected method simpleName"); | |
772 Expect.stringEquals('operator ==', displayName(operator_eq)); | |
773 Expect.equals(const Symbol('mirrors_helper.Baz.=='), | |
774 operator_eq.qualifiedName, | |
775 "Unexpected method qualifiedName"); | |
776 Expect.equals(operator_eq.owner, bazClass); | |
777 Expect.isFalse(operator_eq.isTopLevel); | |
778 Expect.isTrue(operator_eq is MethodMirror); | |
779 Expect.isFalse(operator_eq.isConstructor); | |
780 Expect.isFalse(operator_eq.isPrivate); | |
781 Expect.isFalse(operator_eq.isStatic); | |
782 Expect.isTrue(operator_eq.isRegularMethod); | |
783 Expect.isFalse(operator_eq.isConstConstructor); | |
784 Expect.isFalse(operator_eq.isGenerativeConstructor); | |
785 Expect.isFalse(operator_eq.isRedirectingConstructor); | |
786 Expect.isFalse(operator_eq.isFactoryConstructor); | |
787 Expect.isFalse(operator_eq.isGetter); | |
788 Expect.isFalse(operator_eq.isSetter); | |
789 Expect.isTrue(operator_eq.isOperator); | |
790 Expect.stringEquals('==', operatorName(operator_eq)); | |
791 | |
792 //////////////////////////////////////////////////////////////////////////// | |
793 // int operator -() => 0; | |
794 //////////////////////////////////////////////////////////////////////////// | |
795 var operator_negate = bazClassMembers[const Symbol('unary-')]; | |
796 Expect.isNotNull(operator_negate, "operator < not found"); | |
797 Expect.equals(const Symbol('unary-'), operator_negate.simpleName, | |
798 "Unexpected method simpleName"); | |
799 Expect.stringEquals('operator -', displayName(operator_negate)); | |
800 Expect.equals(const Symbol('mirrors_helper.Baz.unary-'), | |
801 operator_negate.qualifiedName, | |
802 "Unexpected method qualifiedName"); | |
803 Expect.equals(operator_negate.owner, bazClass); | |
804 Expect.isFalse(operator_negate.isTopLevel); | |
805 Expect.isTrue(operator_negate is MethodMirror); | |
806 Expect.isFalse(operator_negate.isConstructor); | |
807 Expect.isFalse(operator_negate.isPrivate); | |
808 Expect.isFalse(operator_negate.isStatic); | |
809 Expect.isTrue(operator_negate.isRegularMethod); | |
810 Expect.isFalse(operator_negate.isConstConstructor); | |
811 Expect.isFalse(operator_negate.isGenerativeConstructor); | |
812 Expect.isFalse(operator_negate.isRedirectingConstructor); | |
813 Expect.isFalse(operator_negate.isFactoryConstructor); | |
814 Expect.isFalse(operator_negate.isGetter); | |
815 Expect.isFalse(operator_negate.isSetter); | |
816 Expect.isTrue(operator_negate.isOperator); | |
817 Expect.stringEquals('-', operatorName(operator_negate)); | |
818 | |
819 | |
820 //////////////////////////////////////////////////////////////////////////// | |
821 // operator$foo() {} | |
822 //////////////////////////////////////////////////////////////////////////// | |
823 var operator$foo = bazClassMembers[#operator$foo]; | |
824 Expect.isNotNull(operator$foo, "operator\$foo not found"); | |
825 Expect.equals(#operator$foo, operator$foo.simpleName); | |
826 Expect.equals(#mirrors_helper.Baz.operator$foo, operator$foo.qualifiedName); | |
827 Expect.equals(operator$foo.owner, bazClass); | |
828 Expect.isFalse(operator$foo.isTopLevel); | |
829 Expect.isTrue(operator$foo is MethodMirror); | |
830 Expect.isFalse(operator$foo.isConstructor); | |
831 Expect.isFalse(operator$foo.isPrivate); | |
832 Expect.isFalse(operator$foo.isStatic); | |
833 Expect.isTrue(operator$foo.isRegularMethod); | |
834 Expect.isFalse(operator$foo.isConstConstructor); | |
835 Expect.isFalse(operator$foo.isGenerativeConstructor); | |
836 Expect.isFalse(operator$foo.isRedirectingConstructor); | |
837 Expect.isFalse(operator$foo.isFactoryConstructor); | |
838 Expect.isFalse(operator$foo.isGetter); | |
839 Expect.isFalse(operator$foo.isSetter); | |
840 Expect.isFalse(operator$foo.isOperator); | |
841 | |
842 Expect.equals(dynamicType, operator$foo.returnType); | |
843 | |
844 var operator$fooParameters = operator$foo.parameters; | |
845 Expect.isNotNull(operator$fooParameters, "Method parameters is null"); | |
846 Expect.equals(0, operator$fooParameters.length, "Unexpected parameter count"); | |
847 | |
848 //////////////////////////////////////////////////////////////////////////// | |
849 // Baz(); | |
850 //////////////////////////////////////////////////////////////////////////// | |
851 var bazClassNonameConstructor = bazClassMembers[const Symbol('')]; | |
852 Expect.isNotNull(bazClassNonameConstructor); | |
853 Expect.isTrue(bazClassNonameConstructor is MethodMirror); | |
854 Expect.isTrue(bazClassNonameConstructor.isConstructor); | |
855 Expect.isFalse(bazClassNonameConstructor.isRegularMethod); | |
856 Expect.isFalse(bazClassNonameConstructor.isConstConstructor); | |
857 Expect.isTrue(bazClassNonameConstructor.isGenerativeConstructor); | |
858 Expect.isFalse(bazClassNonameConstructor.isRedirectingConstructor); | |
859 Expect.isFalse(bazClassNonameConstructor.isFactoryConstructor); | |
860 Expect.equals(const Symbol(''), bazClassNonameConstructor.simpleName); | |
861 Expect.stringEquals('Baz', displayName(bazClassNonameConstructor)); | |
862 Expect.equals(const Symbol('mirrors_helper.Baz.'), | |
863 bazClassNonameConstructor.qualifiedName); | |
864 | |
865 //////////////////////////////////////////////////////////////////////////// | |
866 // const Baz.named(); | |
867 //////////////////////////////////////////////////////////////////////////// | |
868 var bazClassNamedConstructor = bazClassMembers[#named]; | |
869 Expect.isNotNull(bazClassNamedConstructor); | |
870 Expect.isTrue(bazClassNamedConstructor is MethodMirror); | |
871 Expect.isTrue(bazClassNamedConstructor.isConstructor); | |
872 Expect.isFalse(bazClassNamedConstructor.isRegularMethod); | |
873 Expect.isTrue(bazClassNamedConstructor.isConstConstructor); | |
874 Expect.isFalse(bazClassNamedConstructor.isGenerativeConstructor); | |
875 Expect.isFalse(bazClassNamedConstructor.isRedirectingConstructor); | |
876 Expect.isFalse(bazClassNamedConstructor.isFactoryConstructor); | |
877 Expect.equals(#named, bazClassNamedConstructor.simpleName); | |
878 Expect.stringEquals('Baz.named', displayName(bazClassNamedConstructor)); | |
879 Expect.equals(#mirrors_helper.Baz.named, | |
880 bazClassNamedConstructor.qualifiedName); | |
881 | |
882 //////////////////////////////////////////////////////////////////////////// | |
883 // factory Baz.factory() => new Baz<E,F>(); | |
884 //////////////////////////////////////////////////////////////////////////// | |
885 var bazClassFactoryConstructor = bazClassMembers[#factory]; | |
886 Expect.isNotNull(bazClassFactoryConstructor); | |
887 Expect.isTrue(bazClassFactoryConstructor is MethodMirror); | |
888 Expect.isTrue(bazClassFactoryConstructor.isConstructor); | |
889 Expect.isFalse(bazClassFactoryConstructor.isRegularMethod); | |
890 Expect.isFalse(bazClassFactoryConstructor.isConstConstructor); | |
891 Expect.isFalse(bazClassFactoryConstructor.isGenerativeConstructor); | |
892 Expect.isFalse(bazClassFactoryConstructor.isRedirectingConstructor); | |
893 Expect.isTrue(bazClassFactoryConstructor.isFactoryConstructor); | |
894 Expect.equals(#factory, bazClassFactoryConstructor.simpleName); | |
895 Expect.stringEquals('Baz.factory', displayName(bazClassFactoryConstructor)); | |
896 Expect.equals(#mirrors_helper.Baz.factory, | |
897 bazClassFactoryConstructor.qualifiedName); | |
898 | |
899 // TODO(johnniwinther): Add more tests of constructors. | |
900 // TODO(johnniwinther): Add a test for unnamed factory methods. | |
901 | |
902 var metadata = bazClass.metadata; | |
903 Expect.isNotNull(metadata); | |
904 Expect.equals(0, metadata.length); | |
905 } | |
906 | |
907 // class _PrivateClass { | |
908 // var _privateField; | |
909 // get _privateGetter => _privateField; | |
910 // void set _privateSetter(value) => _privateField = value; | |
911 // void _privateMethod() {} | |
912 // _PrivateClass._privateConstructor(); | |
913 // factory _PrivateClass._privateFactoryConstructor() => new _PrivateClass(); | |
914 // } | |
915 void testPrivate(MirrorSystem system, LibraryMirror helperLibrary, | |
916 Map<Symbol, DeclarationMirror> declarations) { | |
917 var privateClass = declarations[const Symbol('_PrivateClass')]; | |
918 Expect.isNotNull(privateClass); | |
919 Expect.isTrue(privateClass is ClassMirror); | |
920 Expect.isFalse(privateClass.isAbstract); | |
921 Expect.isTrue(privateClass.isPrivate); | |
922 | |
923 var privateField = privateClass.declarations[const Symbol('_privateField')]; | |
924 Expect.isNotNull(privateField); | |
925 Expect.isTrue(privateField is VariableMirror); | |
926 Expect.isTrue(privateField.isPrivate); | |
927 | |
928 var privateGetter = privateClass.declarations[const Symbol('_privateGetter')]; | |
929 Expect.isNotNull(privateGetter); | |
930 Expect.isTrue(privateGetter is MethodMirror); | |
931 Expect.isTrue(privateGetter.isGetter); | |
932 Expect.isTrue(privateGetter.isPrivate); | |
933 Expect.isFalse(privateGetter.isRegularMethod); | |
934 | |
935 var privateSetter = | |
936 privateClass.declarations[const Symbol('_privateSetter=')]; | |
937 Expect.isNotNull(privateSetter); | |
938 Expect.isTrue(privateSetter is MethodMirror); | |
939 Expect.isTrue(privateSetter.isSetter); | |
940 Expect.isTrue(privateSetter.isPrivate); | |
941 Expect.isFalse(privateSetter.isRegularMethod); | |
942 | |
943 var privateMethod = privateClass.declarations[const Symbol('_privateMethod')]; | |
944 Expect.isNotNull(privateMethod); | |
945 Expect.isTrue(privateMethod is MethodMirror); | |
946 Expect.isTrue(privateMethod.isPrivate); | |
947 Expect.isTrue(privateMethod.isRegularMethod); | |
948 | |
949 var privateConstructor = | |
950 privateClass.declarations[const Symbol('_privateConstructor')]; | |
951 Expect.isNotNull(privateConstructor); | |
952 Expect.isTrue(privateConstructor is MethodMirror); | |
953 Expect.isTrue(privateConstructor.isConstructor); | |
954 Expect.isTrue(privateConstructor.isPrivate); | |
955 Expect.isFalse(privateConstructor.isConstConstructor); | |
956 Expect.isFalse(privateConstructor.isRedirectingConstructor); | |
957 Expect.isTrue(privateConstructor.isGenerativeConstructor); | |
958 Expect.isFalse(privateConstructor.isFactoryConstructor); | |
959 | |
960 var privateFactoryConstructor = | |
961 privateClass.declarations[const Symbol('_privateFactoryConstructor')]; | |
962 Expect.isNotNull(privateFactoryConstructor); | |
963 Expect.isTrue(privateFactoryConstructor is MethodMirror); | |
964 Expect.isTrue(privateFactoryConstructor.isConstructor); | |
965 Expect.isTrue(privateFactoryConstructor.isPrivate); | |
966 Expect.isFalse(privateFactoryConstructor.isConstConstructor); | |
967 Expect.isFalse(privateFactoryConstructor.isRedirectingConstructor); | |
968 Expect.isFalse(privateFactoryConstructor.isGenerativeConstructor); | |
969 Expect.isTrue(privateFactoryConstructor.isFactoryConstructor); | |
970 | |
971 var metadata = privateClass.metadata; | |
972 Expect.isNotNull(metadata); | |
973 Expect.equals(0, metadata.length); | |
974 } | |
OLD | NEW |