Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1911)

Side by Side Diff: pkg/analyzer/test/generated/inheritance_manager_test.dart

Issue 1782463002: Split resolver_test.dart into smaller files. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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 library analyzer.test.generated.inheritance_manager_test;
6
7 import 'dart:collection';
8
9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/src/dart/element/element.dart';
12 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/error.dart';
14 import 'package:analyzer/src/generated/java_engine_io.dart';
15 import 'package:analyzer/src/generated/resolver.dart';
16 import 'package:analyzer/src/generated/source_io.dart';
17 import 'package:analyzer/src/generated/testing/ast_factory.dart';
18 import 'package:analyzer/src/generated/testing/element_factory.dart';
19 import 'package:analyzer/src/generated/testing/test_type_provider.dart';
20 import 'package:analyzer/src/generated/utilities_dart.dart';
21 import 'package:unittest/unittest.dart';
22
23 import '../reflective_tests.dart';
24 import '../utils.dart';
25 import 'analysis_context_factory.dart';
26 import 'test_support.dart';
27
28 main() {
29 initializeTestEnvironment();
30 runReflectiveTests(InheritanceManagerTest);
31 }
32
33 @reflectiveTest
34 class InheritanceManagerTest {
35 /**
36 * The type provider used to access the types.
37 */
38 TestTypeProvider _typeProvider;
39
40 /**
41 * The library containing the code being resolved.
42 */
43 LibraryElementImpl _definingLibrary;
44
45 /**
46 * The inheritance manager being tested.
47 */
48 InheritanceManager _inheritanceManager;
49
50 /**
51 * The number of members that Object implements (as determined by [TestTypePro vider]).
52 */
53 int _numOfMembersInObject = 0;
54
55 void setUp() {
56 _typeProvider = new TestTypeProvider();
57 _inheritanceManager = _createInheritanceManager();
58 InterfaceType objectType = _typeProvider.objectType;
59 _numOfMembersInObject =
60 objectType.methods.length + objectType.accessors.length;
61 }
62
63 void test_getMapOfMembersInheritedFromClasses_accessor_extends() {
64 // class A { int get g; }
65 // class B extends A {}
66 ClassElementImpl classA = ElementFactory.classElement2("A");
67 String getterName = "g";
68 PropertyAccessorElement getterG =
69 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
70 classA.accessors = <PropertyAccessorElement>[getterG];
71 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
72 MemberMap mapB =
73 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
74 MemberMap mapA =
75 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
76 expect(mapA.size, _numOfMembersInObject);
77 expect(mapB.size, _numOfMembersInObject + 1);
78 expect(mapB.get(getterName), same(getterG));
79 _assertNoErrors(classA);
80 _assertNoErrors(classB);
81 }
82
83 void test_getMapOfMembersInheritedFromClasses_accessor_implements() {
84 // class A { int get g; }
85 // class B implements A {}
86 ClassElementImpl classA = ElementFactory.classElement2("A");
87 String getterName = "g";
88 PropertyAccessorElement getterG =
89 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
90 classA.accessors = <PropertyAccessorElement>[getterG];
91 ClassElementImpl classB = ElementFactory.classElement2("B");
92 classB.interfaces = <InterfaceType>[classA.type];
93 MemberMap mapB =
94 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
95 MemberMap mapA =
96 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
97 expect(mapA.size, _numOfMembersInObject);
98 expect(mapB.size, _numOfMembersInObject);
99 expect(mapB.get(getterName), isNull);
100 _assertNoErrors(classA);
101 _assertNoErrors(classB);
102 }
103
104 void test_getMapOfMembersInheritedFromClasses_accessor_with() {
105 // class A { int get g; }
106 // class B extends Object with A {}
107 ClassElementImpl classA = ElementFactory.classElement2("A");
108 String getterName = "g";
109 PropertyAccessorElement getterG =
110 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
111 classA.accessors = <PropertyAccessorElement>[getterG];
112 ClassElementImpl classB = ElementFactory.classElement2("B");
113 classB.mixins = <InterfaceType>[classA.type];
114 MemberMap mapB =
115 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
116 MemberMap mapA =
117 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
118 expect(mapA.size, _numOfMembersInObject);
119 expect(mapB.size, _numOfMembersInObject + 1);
120 expect(mapB.get(getterName), same(getterG));
121 _assertNoErrors(classA);
122 _assertNoErrors(classB);
123 }
124
125 void test_getMapOfMembersInheritedFromClasses_implicitExtends() {
126 // class A {}
127 ClassElementImpl classA = ElementFactory.classElement2("A");
128 MemberMap mapA =
129 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
130 expect(mapA.size, _numOfMembersInObject);
131 _assertNoErrors(classA);
132 }
133
134 void test_getMapOfMembersInheritedFromClasses_method_extends() {
135 // class A { int g(); }
136 // class B extends A {}
137 ClassElementImpl classA = ElementFactory.classElement2("A");
138 String methodName = "m";
139 MethodElement methodM =
140 ElementFactory.methodElement(methodName, _typeProvider.intType);
141 classA.methods = <MethodElement>[methodM];
142 ClassElementImpl classB = ElementFactory.classElement2("B");
143 classB.supertype = classA.type;
144 MemberMap mapB =
145 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
146 MemberMap mapA =
147 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
148 expect(mapA.size, _numOfMembersInObject);
149 expect(mapB.size, _numOfMembersInObject + 1);
150 expect(mapB.get(methodName), same(methodM));
151 _assertNoErrors(classA);
152 _assertNoErrors(classB);
153 }
154
155 void test_getMapOfMembersInheritedFromClasses_method_implements() {
156 // class A { int g(); }
157 // class B implements A {}
158 ClassElementImpl classA = ElementFactory.classElement2("A");
159 String methodName = "m";
160 MethodElement methodM =
161 ElementFactory.methodElement(methodName, _typeProvider.intType);
162 classA.methods = <MethodElement>[methodM];
163 ClassElementImpl classB = ElementFactory.classElement2("B");
164 classB.interfaces = <InterfaceType>[classA.type];
165 MemberMap mapB =
166 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
167 MemberMap mapA =
168 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
169 expect(mapA.size, _numOfMembersInObject);
170 expect(mapB.size, _numOfMembersInObject);
171 expect(mapB.get(methodName), isNull);
172 _assertNoErrors(classA);
173 _assertNoErrors(classB);
174 }
175
176 void test_getMapOfMembersInheritedFromClasses_method_with() {
177 // class A { int g(); }
178 // class B extends Object with A {}
179 ClassElementImpl classA = ElementFactory.classElement2("A");
180 String methodName = "m";
181 MethodElement methodM =
182 ElementFactory.methodElement(methodName, _typeProvider.intType);
183 classA.methods = <MethodElement>[methodM];
184 ClassElementImpl classB = ElementFactory.classElement2("B");
185 classB.mixins = <InterfaceType>[classA.type];
186 MemberMap mapB =
187 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
188 MemberMap mapA =
189 _inheritanceManager.getMapOfMembersInheritedFromClasses(classA);
190 expect(mapA.size, _numOfMembersInObject);
191 expect(mapB.size, _numOfMembersInObject + 1);
192 expect(mapB.get(methodName), same(methodM));
193 _assertNoErrors(classA);
194 _assertNoErrors(classB);
195 }
196
197 void test_getMapOfMembersInheritedFromClasses_method_with_two_mixins() {
198 // class A1 { int m(); }
199 // class A2 { int m(); }
200 // class B extends Object with A1, A2 {}
201 ClassElementImpl classA1 = ElementFactory.classElement2("A1");
202 String methodName = "m";
203 MethodElement methodA1M =
204 ElementFactory.methodElement(methodName, _typeProvider.intType);
205 classA1.methods = <MethodElement>[methodA1M];
206 ClassElementImpl classA2 = ElementFactory.classElement2("A2");
207 MethodElement methodA2M =
208 ElementFactory.methodElement(methodName, _typeProvider.intType);
209 classA2.methods = <MethodElement>[methodA2M];
210 ClassElementImpl classB = ElementFactory.classElement2("B");
211 classB.mixins = <InterfaceType>[classA1.type, classA2.type];
212 MemberMap mapB =
213 _inheritanceManager.getMapOfMembersInheritedFromClasses(classB);
214 expect(mapB.get(methodName), same(methodA2M));
215 _assertNoErrors(classA1);
216 _assertNoErrors(classA2);
217 _assertNoErrors(classB);
218 }
219
220 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() {
221 // class A { int get g; }
222 // class B extends A {}
223 ClassElementImpl classA = ElementFactory.classElement2("A");
224 String getterName = "g";
225 PropertyAccessorElement getterG =
226 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
227 classA.accessors = <PropertyAccessorElement>[getterG];
228 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
229 MemberMap mapB =
230 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
231 MemberMap mapA =
232 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
233 expect(mapA.size, _numOfMembersInObject);
234 expect(mapB.size, _numOfMembersInObject + 1);
235 expect(mapB.get(getterName), same(getterG));
236 _assertNoErrors(classA);
237 _assertNoErrors(classB);
238 }
239
240 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() {
241 // class A { int get g; }
242 // class B implements A {}
243 ClassElementImpl classA = ElementFactory.classElement2("A");
244 String getterName = "g";
245 PropertyAccessorElement getterG =
246 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
247 classA.accessors = <PropertyAccessorElement>[getterG];
248 ClassElementImpl classB = ElementFactory.classElement2("B");
249 classB.interfaces = <InterfaceType>[classA.type];
250 MemberMap mapB =
251 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
252 MemberMap mapA =
253 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
254 expect(mapA.size, _numOfMembersInObject);
255 expect(mapB.size, _numOfMembersInObject + 1);
256 expect(mapB.get(getterName), same(getterG));
257 _assertNoErrors(classA);
258 _assertNoErrors(classB);
259 }
260
261 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() {
262 // class A { int get g; }
263 // class B extends Object with A {}
264 ClassElementImpl classA = ElementFactory.classElement2("A");
265 String getterName = "g";
266 PropertyAccessorElement getterG =
267 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
268 classA.accessors = <PropertyAccessorElement>[getterG];
269 ClassElementImpl classB = ElementFactory.classElement2("B");
270 classB.mixins = <InterfaceType>[classA.type];
271 MemberMap mapB =
272 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
273 MemberMap mapA =
274 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
275 expect(mapA.size, _numOfMembersInObject);
276 expect(mapB.size, _numOfMembersInObject + 1);
277 expect(mapB.get(getterName), same(getterG));
278 _assertNoErrors(classA);
279 _assertNoErrors(classB);
280 }
281
282 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() {
283 // class A {}
284 ClassElementImpl classA = ElementFactory.classElement2("A");
285 MemberMap mapA =
286 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
287 expect(mapA.size, _numOfMembersInObject);
288 _assertNoErrors(classA);
289 }
290
291 void
292 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_gett er_method() {
293 // class I1 { int m(); }
294 // class I2 { int get m; }
295 // class A implements I2, I1 {}
296 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
297 String methodName = "m";
298 MethodElement methodM =
299 ElementFactory.methodElement(methodName, _typeProvider.intType);
300 classI1.methods = <MethodElement>[methodM];
301 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
302 PropertyAccessorElement getter =
303 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
304 classI2.accessors = <PropertyAccessorElement>[getter];
305 ClassElementImpl classA = ElementFactory.classElement2("A");
306 classA.interfaces = <InterfaceType>[classI2.type, classI1.type];
307 MemberMap mapA =
308 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
309 expect(mapA.size, _numOfMembersInObject);
310 expect(mapA.get(methodName), isNull);
311 _assertErrors(classA,
312 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
313 }
314
315 void
316 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_int_ str() {
317 // class I1 { int m(); }
318 // class I2 { String m(); }
319 // class A implements I1, I2 {}
320 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
321 String methodName = "m";
322 MethodElement methodM1 =
323 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]);
324 classI1.methods = <MethodElement>[methodM1];
325 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
326 MethodElement methodM2 = ElementFactory
327 .methodElement(methodName, null, [_typeProvider.stringType]);
328 classI2.methods = <MethodElement>[methodM2];
329 ClassElementImpl classA = ElementFactory.classElement2("A");
330 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
331 MemberMap mapA =
332 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
333 expect(mapA.size, _numOfMembersInObject);
334 expect(mapA.get(methodName), isNull);
335 _assertErrors(
336 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
337 }
338
339 void
340 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_meth od_getter() {
341 // class I1 { int m(); }
342 // class I2 { int get m; }
343 // class A implements I1, I2 {}
344 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
345 String methodName = "m";
346 MethodElement methodM =
347 ElementFactory.methodElement(methodName, _typeProvider.intType);
348 classI1.methods = <MethodElement>[methodM];
349 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
350 PropertyAccessorElement getter =
351 ElementFactory.getterElement(methodName, false, _typeProvider.intType);
352 classI2.accessors = <PropertyAccessorElement>[getter];
353 ClassElementImpl classA = ElementFactory.classElement2("A");
354 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
355 MemberMap mapA =
356 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
357 expect(mapA.size, _numOfMembersInObject);
358 expect(mapA.get(methodName), isNull);
359 _assertErrors(classA,
360 [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHOD]);
361 }
362
363 void
364 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_numO fRequiredParams() {
365 // class I1 { dynamic m(int, [int]); }
366 // class I2 { dynamic m(int, int, int); }
367 // class A implements I1, I2 {}
368 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
369 String methodName = "m";
370 MethodElementImpl methodM1 =
371 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
372 ParameterElementImpl parameter1 =
373 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
374 parameter1.type = _typeProvider.intType;
375 parameter1.parameterKind = ParameterKind.REQUIRED;
376 ParameterElementImpl parameter2 =
377 new ParameterElementImpl.forNode(AstFactory.identifier3("a2"));
378 parameter2.type = _typeProvider.intType;
379 parameter2.parameterKind = ParameterKind.POSITIONAL;
380 methodM1.parameters = <ParameterElement>[parameter1, parameter2];
381 classI1.methods = <MethodElement>[methodM1];
382 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
383 MethodElementImpl methodM2 =
384 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
385 ParameterElementImpl parameter3 =
386 new ParameterElementImpl.forNode(AstFactory.identifier3("a3"));
387 parameter3.type = _typeProvider.intType;
388 parameter3.parameterKind = ParameterKind.REQUIRED;
389 ParameterElementImpl parameter4 =
390 new ParameterElementImpl.forNode(AstFactory.identifier3("a4"));
391 parameter4.type = _typeProvider.intType;
392 parameter4.parameterKind = ParameterKind.REQUIRED;
393 ParameterElementImpl parameter5 =
394 new ParameterElementImpl.forNode(AstFactory.identifier3("a5"));
395 parameter5.type = _typeProvider.intType;
396 parameter5.parameterKind = ParameterKind.REQUIRED;
397 methodM2.parameters = <ParameterElement>[
398 parameter3,
399 parameter4,
400 parameter5
401 ];
402 classI2.methods = <MethodElement>[methodM2];
403 ClassElementImpl classA = ElementFactory.classElement2("A");
404 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
405 MemberMap mapA =
406 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
407 expect(mapA.size, _numOfMembersInObject);
408 expect(mapA.get(methodName), isNull);
409 _assertErrors(
410 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
411 }
412
413 void
414 test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance_str_ int() {
415 // class I1 { int m(); }
416 // class I2 { String m(); }
417 // class A implements I2, I1 {}
418 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
419 String methodName = "m";
420 MethodElement methodM1 = ElementFactory
421 .methodElement(methodName, null, [_typeProvider.stringType]);
422 classI1.methods = <MethodElement>[methodM1];
423 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
424 MethodElement methodM2 =
425 ElementFactory.methodElement(methodName, null, [_typeProvider.intType]);
426 classI2.methods = <MethodElement>[methodM2];
427 ClassElementImpl classA = ElementFactory.classElement2("A");
428 classA.interfaces = <InterfaceType>[classI2.type, classI1.type];
429 MemberMap mapA =
430 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
431 expect(mapA.size, _numOfMembersInObject);
432 expect(mapA.get(methodName), isNull);
433 _assertErrors(
434 classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
435 }
436
437 void test_getMapOfMembersInheritedFromInterfaces_method_extends() {
438 // class A { int g(); }
439 // class B extends A {}
440 ClassElementImpl classA = ElementFactory.classElement2("A");
441 String methodName = "m";
442 MethodElement methodM =
443 ElementFactory.methodElement(methodName, _typeProvider.intType);
444 classA.methods = <MethodElement>[methodM];
445 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
446 MemberMap mapB =
447 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
448 MemberMap mapA =
449 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
450 expect(mapA.size, _numOfMembersInObject);
451 expect(mapB.size, _numOfMembersInObject + 1);
452 expect(mapB.get(methodName), same(methodM));
453 _assertNoErrors(classA);
454 _assertNoErrors(classB);
455 }
456
457 void test_getMapOfMembersInheritedFromInterfaces_method_implements() {
458 // class A { int g(); }
459 // class B implements A {}
460 ClassElementImpl classA = ElementFactory.classElement2("A");
461 String methodName = "m";
462 MethodElement methodM =
463 ElementFactory.methodElement(methodName, _typeProvider.intType);
464 classA.methods = <MethodElement>[methodM];
465 ClassElementImpl classB = ElementFactory.classElement2("B");
466 classB.interfaces = <InterfaceType>[classA.type];
467 MemberMap mapB =
468 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
469 MemberMap mapA =
470 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
471 expect(mapA.size, _numOfMembersInObject);
472 expect(mapB.size, _numOfMembersInObject + 1);
473 expect(mapB.get(methodName), same(methodM));
474 _assertNoErrors(classA);
475 _assertNoErrors(classB);
476 }
477
478 void test_getMapOfMembersInheritedFromInterfaces_method_with() {
479 // class A { int g(); }
480 // class B extends Object with A {}
481 ClassElementImpl classA = ElementFactory.classElement2("A");
482 String methodName = "m";
483 MethodElement methodM =
484 ElementFactory.methodElement(methodName, _typeProvider.intType);
485 classA.methods = <MethodElement>[methodM];
486 ClassElementImpl classB = ElementFactory.classElement2("B");
487 classB.mixins = <InterfaceType>[classA.type];
488 MemberMap mapB =
489 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classB);
490 MemberMap mapA =
491 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
492 expect(mapA.size, _numOfMembersInObject);
493 expect(mapB.size, _numOfMembersInObject + 1);
494 expect(mapB.get(methodName), same(methodM));
495 _assertNoErrors(classA);
496 _assertNoErrors(classB);
497 }
498
499 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() {
500 // class I1 { int m1(); }
501 // class I2 { int m2(); }
502 // class A implements I1, I2 {}
503 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
504 String methodName1 = "m1";
505 MethodElement methodM1 =
506 ElementFactory.methodElement(methodName1, _typeProvider.intType);
507 classI1.methods = <MethodElement>[methodM1];
508 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
509 String methodName2 = "m2";
510 MethodElement methodM2 =
511 ElementFactory.methodElement(methodName2, _typeProvider.intType);
512 classI2.methods = <MethodElement>[methodM2];
513 ClassElementImpl classA = ElementFactory.classElement2("A");
514 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
515 MemberMap mapA =
516 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
517 expect(mapA.size, _numOfMembersInObject + 2);
518 expect(mapA.get(methodName1), same(methodM1));
519 expect(mapA.get(methodName2), same(methodM2));
520 _assertNoErrors(classA);
521 }
522
523 void
524 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_getters() {
525 // class I1 { int get g; }
526 // class I2 { num get g; }
527 // class A implements I1, I2 {}
528 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
529 String accessorName = "g";
530 PropertyAccessorElement getter1 = ElementFactory.getterElement(
531 accessorName, false, _typeProvider.intType);
532 classI1.accessors = <PropertyAccessorElement>[getter1];
533 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
534 PropertyAccessorElement getter2 = ElementFactory.getterElement(
535 accessorName, false, _typeProvider.numType);
536 classI2.accessors = <PropertyAccessorElement>[getter2];
537 ClassElementImpl classA = ElementFactory.classElement2("A");
538 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
539 MemberMap mapA =
540 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
541 expect(mapA.size, _numOfMembersInObject + 1);
542 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
543 accessorName, false, _typeProvider.dynamicType);
544 expect(mapA.get(accessorName).type, syntheticAccessor.type);
545 _assertNoErrors(classA);
546 }
547
548 void
549 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_methods() {
550 // class I1 { dynamic m(int); }
551 // class I2 { dynamic m(num); }
552 // class A implements I1, I2 {}
553 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
554 String methodName = "m";
555 MethodElementImpl methodM1 =
556 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
557 ParameterElementImpl parameter1 =
558 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
559 parameter1.type = _typeProvider.intType;
560 parameter1.parameterKind = ParameterKind.REQUIRED;
561 methodM1.parameters = <ParameterElement>[parameter1];
562 classI1.methods = <MethodElement>[methodM1];
563 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
564 MethodElementImpl methodM2 =
565 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
566 ParameterElementImpl parameter2 =
567 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
568 parameter2.type = _typeProvider.numType;
569 parameter2.parameterKind = ParameterKind.REQUIRED;
570 methodM2.parameters = <ParameterElement>[parameter2];
571 classI2.methods = <MethodElement>[methodM2];
572 ClassElementImpl classA = ElementFactory.classElement2("A");
573 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
574 MemberMap mapA =
575 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
576 expect(mapA.size, _numOfMembersInObject + 1);
577 MethodElement syntheticMethod = ElementFactory.methodElement(
578 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
579 expect(mapA.get(methodName).type, syntheticMethod.type);
580 _assertNoErrors(classA);
581 }
582
583 void
584 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_setters() {
585 // class I1 { set s(int); }
586 // class I2 { set s(num); }
587 // class A implements I1, I2 {}
588 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
589 String accessorName = "s";
590 PropertyAccessorElement setter1 = ElementFactory.setterElement(
591 accessorName, false, _typeProvider.intType);
592 classI1.accessors = <PropertyAccessorElement>[setter1];
593 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
594 PropertyAccessorElement setter2 = ElementFactory.setterElement(
595 accessorName, false, _typeProvider.numType);
596 classI2.accessors = <PropertyAccessorElement>[setter2];
597 ClassElementImpl classA = ElementFactory.classElement2("A");
598 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
599 MemberMap mapA =
600 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
601 expect(mapA.size, _numOfMembersInObject + 1);
602 PropertyAccessorElementImpl syntheticAccessor = ElementFactory
603 .setterElement(accessorName, false, _typeProvider.dynamicType);
604 syntheticAccessor.returnType = _typeProvider.dynamicType;
605 expect(mapA.get("$accessorName=").type, syntheticAccessor.type);
606 _assertNoErrors(classA);
607 }
608
609 void
610 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_getters() {
611 // class A {}
612 // class B extends A {}
613 // class C extends B {}
614 // class I1 { A get g; }
615 // class I2 { B get g; }
616 // class I3 { C get g; }
617 // class D implements I1, I2, I3 {}
618 ClassElementImpl classA = ElementFactory.classElement2("A");
619 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
620 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
621 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
622 String accessorName = "g";
623 PropertyAccessorElement getter1 =
624 ElementFactory.getterElement(accessorName, false, classA.type);
625 classI1.accessors = <PropertyAccessorElement>[getter1];
626 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
627 PropertyAccessorElement getter2 =
628 ElementFactory.getterElement(accessorName, false, classB.type);
629 classI2.accessors = <PropertyAccessorElement>[getter2];
630 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
631 PropertyAccessorElement getter3 =
632 ElementFactory.getterElement(accessorName, false, classC.type);
633 classI3.accessors = <PropertyAccessorElement>[getter3];
634 ClassElementImpl classD = ElementFactory.classElement2("D");
635 classD.interfaces = <InterfaceType>[
636 classI1.type,
637 classI2.type,
638 classI3.type
639 ];
640 MemberMap mapD =
641 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
642 expect(mapD.size, _numOfMembersInObject + 1);
643 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(
644 accessorName, false, _typeProvider.dynamicType);
645 expect(mapD.get(accessorName).type, syntheticAccessor.type);
646 _assertNoErrors(classD);
647 }
648
649 void
650 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_methods() {
651 // class A {}
652 // class B extends A {}
653 // class C extends B {}
654 // class I1 { dynamic m(A a); }
655 // class I2 { dynamic m(B b); }
656 // class I3 { dynamic m(C c); }
657 // class D implements I1, I2, I3 {}
658 ClassElementImpl classA = ElementFactory.classElement2("A");
659 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
660 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
661 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
662 String methodName = "m";
663 MethodElementImpl methodM1 =
664 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
665 ParameterElementImpl parameter1 =
666 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
667 parameter1.type = classA.type;
668 parameter1.parameterKind = ParameterKind.REQUIRED;
669 methodM1.parameters = <ParameterElement>[parameter1];
670 classI1.methods = <MethodElement>[methodM1];
671 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
672 MethodElementImpl methodM2 =
673 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
674 ParameterElementImpl parameter2 =
675 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
676 parameter2.type = classB.type;
677 parameter2.parameterKind = ParameterKind.REQUIRED;
678 methodM2.parameters = <ParameterElement>[parameter2];
679 classI2.methods = <MethodElement>[methodM2];
680 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
681 MethodElementImpl methodM3 =
682 ElementFactory.methodElement(methodName, _typeProvider.dynamicType);
683 ParameterElementImpl parameter3 =
684 new ParameterElementImpl.forNode(AstFactory.identifier3("a0"));
685 parameter3.type = classC.type;
686 parameter3.parameterKind = ParameterKind.REQUIRED;
687 methodM3.parameters = <ParameterElement>[parameter3];
688 classI3.methods = <MethodElement>[methodM3];
689 ClassElementImpl classD = ElementFactory.classElement2("D");
690 classD.interfaces = <InterfaceType>[
691 classI1.type,
692 classI2.type,
693 classI3.type
694 ];
695 MemberMap mapD =
696 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
697 expect(mapD.size, _numOfMembersInObject + 1);
698 MethodElement syntheticMethod = ElementFactory.methodElement(
699 methodName, _typeProvider.dynamicType, [_typeProvider.dynamicType]);
700 expect(mapD.get(methodName).type, syntheticMethod.type);
701 _assertNoErrors(classD);
702 }
703
704 void
705 test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_setters() {
706 // class A {}
707 // class B extends A {}
708 // class C extends B {}
709 // class I1 { set s(A); }
710 // class I2 { set s(B); }
711 // class I3 { set s(C); }
712 // class D implements I1, I2, I3 {}
713 ClassElementImpl classA = ElementFactory.classElement2("A");
714 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
715 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
716 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
717 String accessorName = "s";
718 PropertyAccessorElement setter1 =
719 ElementFactory.setterElement(accessorName, false, classA.type);
720 classI1.accessors = <PropertyAccessorElement>[setter1];
721 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
722 PropertyAccessorElement setter2 =
723 ElementFactory.setterElement(accessorName, false, classB.type);
724 classI2.accessors = <PropertyAccessorElement>[setter2];
725 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
726 PropertyAccessorElement setter3 =
727 ElementFactory.setterElement(accessorName, false, classC.type);
728 classI3.accessors = <PropertyAccessorElement>[setter3];
729 ClassElementImpl classD = ElementFactory.classElement2("D");
730 classD.interfaces = <InterfaceType>[
731 classI1.type,
732 classI2.type,
733 classI3.type
734 ];
735 MemberMap mapD =
736 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classD);
737 expect(mapD.size, _numOfMembersInObject + 1);
738 PropertyAccessorElementImpl syntheticAccessor = ElementFactory
739 .setterElement(accessorName, false, _typeProvider.dynamicType);
740 syntheticAccessor.returnType = _typeProvider.dynamicType;
741 expect(mapD.get("$accessorName=").type, syntheticAccessor.type);
742 _assertNoErrors(classD);
743 }
744
745 void
746 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods() {
747 // class I1 { int m(); }
748 // class I2 { int m([int]); }
749 // class A implements I1, I2 {}
750 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
751 String methodName = "m";
752 MethodElement methodM1 =
753 ElementFactory.methodElement(methodName, _typeProvider.intType);
754 classI1.methods = <MethodElement>[methodM1];
755 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
756 MethodElementImpl methodM2 =
757 ElementFactory.methodElement(methodName, _typeProvider.intType);
758 ParameterElementImpl parameter1 =
759 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
760 parameter1.type = _typeProvider.intType;
761 parameter1.parameterKind = ParameterKind.POSITIONAL;
762 methodM2.parameters = <ParameterElement>[parameter1];
763 classI2.methods = <MethodElement>[methodM2];
764 ClassElementImpl classA = ElementFactory.classElement2("A");
765 classA.interfaces = <InterfaceType>[classI1.type, classI2.type];
766 MemberMap mapA =
767 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
768 expect(mapA.size, _numOfMembersInObject + 1);
769 expect(mapA.get(methodName), same(methodM2));
770 _assertNoErrors(classA);
771 }
772
773 void
774 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods() {
775 // class I1 { int m(); }
776 // class I2 { int m([int]); }
777 // class I3 { int m([int, int]); }
778 // class A implements I1, I2, I3 {}
779 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
780 String methodName = "m";
781 MethodElementImpl methodM1 =
782 ElementFactory.methodElement(methodName, _typeProvider.intType);
783 classI1.methods = <MethodElement>[methodM1];
784 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
785 MethodElementImpl methodM2 =
786 ElementFactory.methodElement(methodName, _typeProvider.intType);
787 ParameterElementImpl parameter1 =
788 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
789 parameter1.type = _typeProvider.intType;
790 parameter1.parameterKind = ParameterKind.POSITIONAL;
791 methodM1.parameters = <ParameterElement>[parameter1];
792 classI2.methods = <MethodElement>[methodM2];
793 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
794 MethodElementImpl methodM3 =
795 ElementFactory.methodElement(methodName, _typeProvider.intType);
796 ParameterElementImpl parameter2 =
797 new ParameterElementImpl.forNode(AstFactory.identifier3("a2"));
798 parameter2.type = _typeProvider.intType;
799 parameter2.parameterKind = ParameterKind.POSITIONAL;
800 ParameterElementImpl parameter3 =
801 new ParameterElementImpl.forNode(AstFactory.identifier3("a3"));
802 parameter3.type = _typeProvider.intType;
803 parameter3.parameterKind = ParameterKind.POSITIONAL;
804 methodM3.parameters = <ParameterElement>[parameter2, parameter3];
805 classI3.methods = <MethodElement>[methodM3];
806 ClassElementImpl classA = ElementFactory.classElement2("A");
807 classA.interfaces = <InterfaceType>[
808 classI1.type,
809 classI2.type,
810 classI3.type
811 ];
812 MemberMap mapA =
813 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
814 expect(mapA.size, _numOfMembersInObject + 1);
815 expect(mapA.get(methodName), same(methodM3));
816 _assertNoErrors(classA);
817 }
818
819 void
820 test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods() {
821 // class I1 { int m(); }
822 // class I2 { int m(); }
823 // class I3 { int m([int]); }
824 // class I4 { int m([int, int]); }
825 // class A implements I1, I2, I3, I4 {}
826 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
827 String methodName = "m";
828 MethodElement methodM1 =
829 ElementFactory.methodElement(methodName, _typeProvider.intType);
830 classI1.methods = <MethodElement>[methodM1];
831 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
832 MethodElement methodM2 =
833 ElementFactory.methodElement(methodName, _typeProvider.intType);
834 classI2.methods = <MethodElement>[methodM2];
835 ClassElementImpl classI3 = ElementFactory.classElement2("I3");
836 MethodElementImpl methodM3 =
837 ElementFactory.methodElement(methodName, _typeProvider.intType);
838 ParameterElementImpl parameter1 =
839 new ParameterElementImpl.forNode(AstFactory.identifier3("a1"));
840 parameter1.type = _typeProvider.intType;
841 parameter1.parameterKind = ParameterKind.POSITIONAL;
842 methodM3.parameters = <ParameterElement>[parameter1];
843 classI3.methods = <MethodElement>[methodM3];
844 ClassElementImpl classI4 = ElementFactory.classElement2("I4");
845 MethodElementImpl methodM4 =
846 ElementFactory.methodElement(methodName, _typeProvider.intType);
847 ParameterElementImpl parameter2 =
848 new ParameterElementImpl.forNode(AstFactory.identifier3("a2"));
849 parameter2.type = _typeProvider.intType;
850 parameter2.parameterKind = ParameterKind.POSITIONAL;
851 ParameterElementImpl parameter3 =
852 new ParameterElementImpl.forNode(AstFactory.identifier3("a3"));
853 parameter3.type = _typeProvider.intType;
854 parameter3.parameterKind = ParameterKind.POSITIONAL;
855 methodM4.parameters = <ParameterElement>[parameter2, parameter3];
856 classI4.methods = <MethodElement>[methodM4];
857 ClassElementImpl classA = ElementFactory.classElement2("A");
858 classA.interfaces = <InterfaceType>[
859 classI1.type,
860 classI2.type,
861 classI3.type,
862 classI4.type
863 ];
864 MemberMap mapA =
865 _inheritanceManager.getMapOfMembersInheritedFromInterfaces(classA);
866 expect(mapA.size, _numOfMembersInObject + 1);
867 expect(mapA.get(methodName), same(methodM4));
868 _assertNoErrors(classA);
869 }
870
871 void test_lookupInheritance_interface_getter() {
872 ClassElementImpl classA = ElementFactory.classElement2("A");
873 String getterName = "g";
874 PropertyAccessorElement getterG =
875 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
876 classA.accessors = <PropertyAccessorElement>[getterG];
877 ClassElementImpl classB = ElementFactory.classElement2("B");
878 classB.interfaces = <InterfaceType>[classA.type];
879 expect(_inheritanceManager.lookupInheritance(classB, getterName),
880 same(getterG));
881 _assertNoErrors(classA);
882 _assertNoErrors(classB);
883 }
884
885 void test_lookupInheritance_interface_method() {
886 ClassElementImpl classA = ElementFactory.classElement2("A");
887 String methodName = "m";
888 MethodElement methodM =
889 ElementFactory.methodElement(methodName, _typeProvider.intType);
890 classA.methods = <MethodElement>[methodM];
891 ClassElementImpl classB = ElementFactory.classElement2("B");
892 classB.interfaces = <InterfaceType>[classA.type];
893 expect(_inheritanceManager.lookupInheritance(classB, methodName),
894 same(methodM));
895 _assertNoErrors(classA);
896 _assertNoErrors(classB);
897 }
898
899 void test_lookupInheritance_interface_setter() {
900 ClassElementImpl classA = ElementFactory.classElement2("A");
901 String setterName = "s";
902 PropertyAccessorElement setterS =
903 ElementFactory.setterElement(setterName, false, _typeProvider.intType);
904 classA.accessors = <PropertyAccessorElement>[setterS];
905 ClassElementImpl classB = ElementFactory.classElement2("B");
906 classB.interfaces = <InterfaceType>[classA.type];
907 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="),
908 same(setterS));
909 _assertNoErrors(classA);
910 _assertNoErrors(classB);
911 }
912
913 void test_lookupInheritance_interface_staticMember() {
914 ClassElementImpl classA = ElementFactory.classElement2("A");
915 String methodName = "m";
916 MethodElement methodM =
917 ElementFactory.methodElement(methodName, _typeProvider.intType);
918 (methodM as MethodElementImpl).static = true;
919 classA.methods = <MethodElement>[methodM];
920 ClassElementImpl classB = ElementFactory.classElement2("B");
921 classB.interfaces = <InterfaceType>[classA.type];
922 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
923 _assertNoErrors(classA);
924 _assertNoErrors(classB);
925 }
926
927 void test_lookupInheritance_interfaces_infiniteLoop() {
928 ClassElementImpl classA = ElementFactory.classElement2("A");
929 classA.interfaces = <InterfaceType>[classA.type];
930 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
931 _assertNoErrors(classA);
932 }
933
934 void test_lookupInheritance_interfaces_infiniteLoop2() {
935 ClassElementImpl classA = ElementFactory.classElement2("A");
936 ClassElementImpl classB = ElementFactory.classElement2("B");
937 classA.interfaces = <InterfaceType>[classB.type];
938 classB.interfaces = <InterfaceType>[classA.type];
939 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
940 _assertNoErrors(classA);
941 _assertNoErrors(classB);
942 }
943
944 void test_lookupInheritance_interfaces_union2() {
945 ClassElementImpl classI1 = ElementFactory.classElement2("I1");
946 String methodName1 = "m1";
947 MethodElement methodM1 =
948 ElementFactory.methodElement(methodName1, _typeProvider.intType);
949 classI1.methods = <MethodElement>[methodM1];
950 ClassElementImpl classI2 = ElementFactory.classElement2("I2");
951 String methodName2 = "m2";
952 MethodElement methodM2 =
953 ElementFactory.methodElement(methodName2, _typeProvider.intType);
954 classI2.methods = <MethodElement>[methodM2];
955 classI2.interfaces = <InterfaceType>[classI1.type];
956 ClassElementImpl classA = ElementFactory.classElement2("A");
957 classA.interfaces = <InterfaceType>[classI2.type];
958 expect(_inheritanceManager.lookupInheritance(classA, methodName1),
959 same(methodM1));
960 expect(_inheritanceManager.lookupInheritance(classA, methodName2),
961 same(methodM2));
962 _assertNoErrors(classI1);
963 _assertNoErrors(classI2);
964 _assertNoErrors(classA);
965 }
966
967 void test_lookupInheritance_mixin_getter() {
968 ClassElementImpl classA = ElementFactory.classElement2("A");
969 String getterName = "g";
970 PropertyAccessorElement getterG =
971 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
972 classA.accessors = <PropertyAccessorElement>[getterG];
973 ClassElementImpl classB = ElementFactory.classElement2("B");
974 classB.mixins = <InterfaceType>[classA.type];
975 expect(_inheritanceManager.lookupInheritance(classB, getterName),
976 same(getterG));
977 _assertNoErrors(classA);
978 _assertNoErrors(classB);
979 }
980
981 void test_lookupInheritance_mixin_method() {
982 ClassElementImpl classA = ElementFactory.classElement2("A");
983 String methodName = "m";
984 MethodElement methodM =
985 ElementFactory.methodElement(methodName, _typeProvider.intType);
986 classA.methods = <MethodElement>[methodM];
987 ClassElementImpl classB = ElementFactory.classElement2("B");
988 classB.mixins = <InterfaceType>[classA.type];
989 expect(_inheritanceManager.lookupInheritance(classB, methodName),
990 same(methodM));
991 _assertNoErrors(classA);
992 _assertNoErrors(classB);
993 }
994
995 void test_lookupInheritance_mixin_setter() {
996 ClassElementImpl classA = ElementFactory.classElement2("A");
997 String setterName = "s";
998 PropertyAccessorElement setterS =
999 ElementFactory.setterElement(setterName, false, _typeProvider.intType);
1000 classA.accessors = <PropertyAccessorElement>[setterS];
1001 ClassElementImpl classB = ElementFactory.classElement2("B");
1002 classB.mixins = <InterfaceType>[classA.type];
1003 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="),
1004 same(setterS));
1005 _assertNoErrors(classA);
1006 _assertNoErrors(classB);
1007 }
1008
1009 void test_lookupInheritance_mixin_staticMember() {
1010 ClassElementImpl classA = ElementFactory.classElement2("A");
1011 String methodName = "m";
1012 MethodElement methodM =
1013 ElementFactory.methodElement(methodName, _typeProvider.intType);
1014 (methodM as MethodElementImpl).static = true;
1015 classA.methods = <MethodElement>[methodM];
1016 ClassElementImpl classB = ElementFactory.classElement2("B");
1017 classB.mixins = <InterfaceType>[classA.type];
1018 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
1019 _assertNoErrors(classA);
1020 _assertNoErrors(classB);
1021 }
1022
1023 void test_lookupInheritance_noMember() {
1024 ClassElementImpl classA = ElementFactory.classElement2("A");
1025 expect(_inheritanceManager.lookupInheritance(classA, "a"), isNull);
1026 _assertNoErrors(classA);
1027 }
1028
1029 void test_lookupInheritance_superclass_getter() {
1030 ClassElementImpl classA = ElementFactory.classElement2("A");
1031 String getterName = "g";
1032 PropertyAccessorElement getterG =
1033 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
1034 classA.accessors = <PropertyAccessorElement>[getterG];
1035 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
1036 expect(_inheritanceManager.lookupInheritance(classB, getterName),
1037 same(getterG));
1038 _assertNoErrors(classA);
1039 _assertNoErrors(classB);
1040 }
1041
1042 void test_lookupInheritance_superclass_infiniteLoop() {
1043 ClassElementImpl classA = ElementFactory.classElement2("A");
1044 classA.supertype = classA.type;
1045 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
1046 _assertNoErrors(classA);
1047 }
1048
1049 void test_lookupInheritance_superclass_infiniteLoop2() {
1050 ClassElementImpl classA = ElementFactory.classElement2("A");
1051 ClassElementImpl classB = ElementFactory.classElement2("B");
1052 classA.supertype = classB.type;
1053 classB.supertype = classA.type;
1054 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull);
1055 _assertNoErrors(classA);
1056 _assertNoErrors(classB);
1057 }
1058
1059 void test_lookupInheritance_superclass_method() {
1060 ClassElementImpl classA = ElementFactory.classElement2("A");
1061 String methodName = "m";
1062 MethodElement methodM =
1063 ElementFactory.methodElement(methodName, _typeProvider.intType);
1064 classA.methods = <MethodElement>[methodM];
1065 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
1066 expect(_inheritanceManager.lookupInheritance(classB, methodName),
1067 same(methodM));
1068 _assertNoErrors(classA);
1069 _assertNoErrors(classB);
1070 }
1071
1072 void test_lookupInheritance_superclass_setter() {
1073 ClassElementImpl classA = ElementFactory.classElement2("A");
1074 String setterName = "s";
1075 PropertyAccessorElement setterS =
1076 ElementFactory.setterElement(setterName, false, _typeProvider.intType);
1077 classA.accessors = <PropertyAccessorElement>[setterS];
1078 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
1079 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="),
1080 same(setterS));
1081 _assertNoErrors(classA);
1082 _assertNoErrors(classB);
1083 }
1084
1085 void test_lookupInheritance_superclass_staticMember() {
1086 ClassElementImpl classA = ElementFactory.classElement2("A");
1087 String methodName = "m";
1088 MethodElement methodM =
1089 ElementFactory.methodElement(methodName, _typeProvider.intType);
1090 (methodM as MethodElementImpl).static = true;
1091 classA.methods = <MethodElement>[methodM];
1092 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
1093 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull);
1094 _assertNoErrors(classA);
1095 _assertNoErrors(classB);
1096 }
1097
1098 void test_lookupMember_getter() {
1099 ClassElementImpl classA = ElementFactory.classElement2("A");
1100 String getterName = "g";
1101 PropertyAccessorElement getterG =
1102 ElementFactory.getterElement(getterName, false, _typeProvider.intType);
1103 classA.accessors = <PropertyAccessorElement>[getterG];
1104 expect(_inheritanceManager.lookupMember(classA, getterName), same(getterG));
1105 _assertNoErrors(classA);
1106 }
1107
1108 void test_lookupMember_getter_static() {
1109 ClassElementImpl classA = ElementFactory.classElement2("A");
1110 String getterName = "g";
1111 PropertyAccessorElement getterG =
1112 ElementFactory.getterElement(getterName, true, _typeProvider.intType);
1113 classA.accessors = <PropertyAccessorElement>[getterG];
1114 expect(_inheritanceManager.lookupMember(classA, getterName), isNull);
1115 _assertNoErrors(classA);
1116 }
1117
1118 void test_lookupMember_method() {
1119 ClassElementImpl classA = ElementFactory.classElement2("A");
1120 String methodName = "m";
1121 MethodElement methodM =
1122 ElementFactory.methodElement(methodName, _typeProvider.intType);
1123 classA.methods = <MethodElement>[methodM];
1124 expect(_inheritanceManager.lookupMember(classA, methodName), same(methodM));
1125 _assertNoErrors(classA);
1126 }
1127
1128 void test_lookupMember_method_static() {
1129 ClassElementImpl classA = ElementFactory.classElement2("A");
1130 String methodName = "m";
1131 MethodElement methodM =
1132 ElementFactory.methodElement(methodName, _typeProvider.intType);
1133 (methodM as MethodElementImpl).static = true;
1134 classA.methods = <MethodElement>[methodM];
1135 expect(_inheritanceManager.lookupMember(classA, methodName), isNull);
1136 _assertNoErrors(classA);
1137 }
1138
1139 void test_lookupMember_noMember() {
1140 ClassElementImpl classA = ElementFactory.classElement2("A");
1141 expect(_inheritanceManager.lookupMember(classA, "a"), isNull);
1142 _assertNoErrors(classA);
1143 }
1144
1145 void test_lookupMember_setter() {
1146 ClassElementImpl classA = ElementFactory.classElement2("A");
1147 String setterName = "s";
1148 PropertyAccessorElement setterS =
1149 ElementFactory.setterElement(setterName, false, _typeProvider.intType);
1150 classA.accessors = <PropertyAccessorElement>[setterS];
1151 expect(_inheritanceManager.lookupMember(classA, "$setterName="),
1152 same(setterS));
1153 _assertNoErrors(classA);
1154 }
1155
1156 void test_lookupMember_setter_static() {
1157 ClassElementImpl classA = ElementFactory.classElement2("A");
1158 String setterName = "s";
1159 PropertyAccessorElement setterS =
1160 ElementFactory.setterElement(setterName, true, _typeProvider.intType);
1161 classA.accessors = <PropertyAccessorElement>[setterS];
1162 expect(_inheritanceManager.lookupMember(classA, setterName), isNull);
1163 _assertNoErrors(classA);
1164 }
1165
1166 void test_lookupOverrides_noParentClasses() {
1167 ClassElementImpl classA = ElementFactory.classElement2("A");
1168 String methodName = "m";
1169 MethodElementImpl methodM =
1170 ElementFactory.methodElement(methodName, _typeProvider.intType);
1171 classA.methods = <MethodElement>[methodM];
1172 expect(
1173 _inheritanceManager.lookupOverrides(classA, methodName), hasLength(0));
1174 _assertNoErrors(classA);
1175 }
1176
1177 void test_lookupOverrides_overrideBaseClass() {
1178 ClassElementImpl classA = ElementFactory.classElement2("A");
1179 String methodName = "m";
1180 MethodElementImpl methodMinA =
1181 ElementFactory.methodElement(methodName, _typeProvider.intType);
1182 classA.methods = <MethodElement>[methodMinA];
1183 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
1184 MethodElementImpl methodMinB =
1185 ElementFactory.methodElement(methodName, _typeProvider.intType);
1186 classB.methods = <MethodElement>[methodMinB];
1187 List<ExecutableElement> overrides =
1188 _inheritanceManager.lookupOverrides(classB, methodName);
1189 expect(overrides, unorderedEquals([methodMinA]));
1190 _assertNoErrors(classA);
1191 _assertNoErrors(classB);
1192 }
1193
1194 void test_lookupOverrides_overrideInterface() {
1195 ClassElementImpl classA = ElementFactory.classElement2("A");
1196 String methodName = "m";
1197 MethodElementImpl methodMinA =
1198 ElementFactory.methodElement(methodName, _typeProvider.intType);
1199 classA.methods = <MethodElement>[methodMinA];
1200 ClassElementImpl classB = ElementFactory.classElement2("B");
1201 classB.interfaces = <InterfaceType>[classA.type];
1202 MethodElementImpl methodMinB =
1203 ElementFactory.methodElement(methodName, _typeProvider.intType);
1204 classB.methods = <MethodElement>[methodMinB];
1205 List<ExecutableElement> overrides =
1206 _inheritanceManager.lookupOverrides(classB, methodName);
1207 expect(overrides, unorderedEquals([methodMinA]));
1208 _assertNoErrors(classA);
1209 _assertNoErrors(classB);
1210 }
1211
1212 void test_lookupOverrides_overrideTwoInterfaces() {
1213 ClassElementImpl classA = ElementFactory.classElement2("A");
1214 String methodName = "m";
1215 MethodElementImpl methodMinA =
1216 ElementFactory.methodElement(methodName, _typeProvider.intType);
1217 classA.methods = <MethodElement>[methodMinA];
1218 ClassElementImpl classB = ElementFactory.classElement2("B");
1219 MethodElementImpl methodMinB =
1220 ElementFactory.methodElement(methodName, _typeProvider.doubleType);
1221 classB.methods = <MethodElement>[methodMinB];
1222 ClassElementImpl classC = ElementFactory.classElement2("C");
1223 classC.interfaces = <InterfaceType>[classA.type, classB.type];
1224 MethodElementImpl methodMinC =
1225 ElementFactory.methodElement(methodName, _typeProvider.numType);
1226 classC.methods = <MethodElement>[methodMinC];
1227 List<ExecutableElement> overrides =
1228 _inheritanceManager.lookupOverrides(classC, methodName);
1229 expect(overrides, unorderedEquals([methodMinA, methodMinB]));
1230 _assertNoErrors(classA);
1231 _assertNoErrors(classB);
1232 _assertNoErrors(classC);
1233 }
1234
1235 void _assertErrors(ClassElement classElt,
1236 [List<ErrorCode> expectedErrorCodes = ErrorCode.EMPTY_LIST]) {
1237 GatheringErrorListener errorListener = new GatheringErrorListener();
1238 HashSet<AnalysisError> actualErrors =
1239 _inheritanceManager.getErrors(classElt);
1240 if (actualErrors != null) {
1241 for (AnalysisError error in actualErrors) {
1242 errorListener.onError(error);
1243 }
1244 }
1245 errorListener.assertErrorsWithCodes(expectedErrorCodes);
1246 }
1247
1248 void _assertNoErrors(ClassElement classElt) {
1249 _assertErrors(classElt);
1250 }
1251
1252 /**
1253 * Create the inheritance manager used by the tests.
1254 *
1255 * @return the inheritance manager that was created
1256 */
1257 InheritanceManager _createInheritanceManager() {
1258 AnalysisContext context = AnalysisContextFactory.contextWithCore();
1259 FileBasedSource source =
1260 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
1261 CompilationUnitElementImpl definingCompilationUnit =
1262 new CompilationUnitElementImpl("test.dart");
1263 definingCompilationUnit.librarySource =
1264 definingCompilationUnit.source = source;
1265 _definingLibrary = ElementFactory.library(context, "test");
1266 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
1267 return new InheritanceManager(_definingLibrary);
1268 }
1269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698