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

Side by Side Diff: pkg/analyzer-experimental/test/generated/element_test.dart

Issue 12253009: Fresh drop of analyzer-experimental. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information.
3
4 library engine.element_test;
5
6 import 'dart:collection';
7 import 'package:analyzer-experimental/src/generated/java_core.dart';
8 import 'package:analyzer-experimental/src/generated/java_engine.dart';
9 import 'package:analyzer-experimental/src/generated/java_junit.dart';
10 import 'package:analyzer-experimental/src/generated/source.dart';
11 import 'package:analyzer-experimental/src/generated/error.dart';
12 import 'package:analyzer-experimental/src/generated/scanner.dart';
13 import 'package:analyzer-experimental/src/generated/ast.dart' hide Annotation;
14 import 'package:analyzer-experimental/src/generated/element.dart' hide Annotatio n;
15 import 'package:analyzer-experimental/src/generated/engine.dart' show AnalysisCo ntext, AnalysisContextImpl;
16 import 'package:unittest/unittest.dart' as _ut;
17 import 'test_support.dart';
18 import 'scanner_test.dart' show TokenFactory;
19 import 'ast_test.dart' show ASTFactory;
20
21 class ElementLocationImplTest extends EngineTestCase {
22 void test_create_encoding() {
23 String encoding = "a;b;c";
24 ElementLocationImpl location = new ElementLocationImpl.con2(encoding);
25 JUnitTestCase.assertEquals(encoding, location.encoding);
26 }
27 void test_equals_equal() {
28 String encoding = "a;b;c";
29 ElementLocationImpl first = new ElementLocationImpl.con2(encoding);
30 ElementLocationImpl second = new ElementLocationImpl.con2(encoding);
31 JUnitTestCase.assertTrue(first == second);
32 }
33 void test_equals_notEqual_differentLengths() {
34 ElementLocationImpl first = new ElementLocationImpl.con2("a;b;c");
35 ElementLocationImpl second = new ElementLocationImpl.con2("a;b;c;d");
36 JUnitTestCase.assertFalse(first == second);
37 }
38 void test_equals_notEqual_notLocation() {
39 ElementLocationImpl first = new ElementLocationImpl.con2("a;b;c");
40 JUnitTestCase.assertFalse(first == "a;b;d");
41 }
42 void test_equals_notEqual_sameLengths() {
43 ElementLocationImpl first = new ElementLocationImpl.con2("a;b;c");
44 ElementLocationImpl second = new ElementLocationImpl.con2("a;b;d");
45 JUnitTestCase.assertFalse(first == second);
46 }
47 void test_getComponents() {
48 String encoding = "a;b;c";
49 ElementLocationImpl location = new ElementLocationImpl.con2(encoding);
50 List<String> components2 = location.components;
51 EngineTestCase.assertLength(3, components2);
52 JUnitTestCase.assertEquals("a", components2[0]);
53 JUnitTestCase.assertEquals("b", components2[1]);
54 JUnitTestCase.assertEquals("c", components2[2]);
55 }
56 void test_getEncoding() {
57 String encoding = "a;b;c;;d";
58 ElementLocationImpl location = new ElementLocationImpl.con2(encoding);
59 JUnitTestCase.assertEquals(encoding, location.encoding);
60 }
61 static dartSuite() {
62 _ut.group('ElementLocationImplTest', () {
63 _ut.test('test_create_encoding', () {
64 final __test = new ElementLocationImplTest();
65 runJUnitTest(__test, __test.test_create_encoding);
66 });
67 _ut.test('test_equals_equal', () {
68 final __test = new ElementLocationImplTest();
69 runJUnitTest(__test, __test.test_equals_equal);
70 });
71 _ut.test('test_equals_notEqual_differentLengths', () {
72 final __test = new ElementLocationImplTest();
73 runJUnitTest(__test, __test.test_equals_notEqual_differentLengths);
74 });
75 _ut.test('test_equals_notEqual_notLocation', () {
76 final __test = new ElementLocationImplTest();
77 runJUnitTest(__test, __test.test_equals_notEqual_notLocation);
78 });
79 _ut.test('test_equals_notEqual_sameLengths', () {
80 final __test = new ElementLocationImplTest();
81 runJUnitTest(__test, __test.test_equals_notEqual_sameLengths);
82 });
83 _ut.test('test_getComponents', () {
84 final __test = new ElementLocationImplTest();
85 runJUnitTest(__test, __test.test_getComponents);
86 });
87 _ut.test('test_getEncoding', () {
88 final __test = new ElementLocationImplTest();
89 runJUnitTest(__test, __test.test_getEncoding);
90 });
91 });
92 }
93 }
94 class FunctionTypeImplTest extends EngineTestCase {
95 void test_creation() {
96 JUnitTestCase.assertNotNull(new FunctionTypeImpl.con1(new FunctionElementImp l.con1(ASTFactory.identifier2("f"))));
97 }
98 void test_getElement() {
99 FunctionElementImpl typeElement = new FunctionElementImpl.con1(ASTFactory.id entifier2("f"));
100 FunctionTypeImpl type = new FunctionTypeImpl.con1(typeElement);
101 JUnitTestCase.assertEquals(typeElement, type.element);
102 }
103 void test_getNamedParameterTypes() {
104 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
105 Map<String, Type2> types = type.namedParameterTypes;
106 EngineTestCase.assertSize2(0, types);
107 }
108 void test_getNormalParameterTypes() {
109 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
110 List<Type2> types = type.normalParameterTypes;
111 EngineTestCase.assertLength(0, types);
112 }
113 void test_getReturnType() {
114 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
115 Type2 returnType5 = type.returnType;
116 JUnitTestCase.assertEquals(VoidTypeImpl.instance, returnType5);
117 }
118 void test_getTypeArguments() {
119 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
120 List<Type2> types = type.typeArguments;
121 EngineTestCase.assertLength(0, types);
122 }
123 void test_hashCode_element() {
124 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
125 type.hashCode;
126 }
127 void test_hashCode_noElement() {
128 FunctionTypeImpl type = new FunctionTypeImpl.con1((null as ExecutableElement ));
129 type.hashCode;
130 }
131 void test_isSubtypeOf_baseCase_notFunctionType() {
132 FunctionType f = ElementFactory.functionElement("f").type;
133 InterfaceType t = ElementFactory.classElement2("C", []).type;
134 JUnitTestCase.assertFalse(f.isSubtypeOf(t));
135 }
136 void test_isSubtypeOf_baseCase_null() {
137 FunctionType f = ElementFactory.functionElement("f").type;
138 JUnitTestCase.assertFalse(f.isSubtypeOf(null));
139 }
140 void test_isSubtypeOf_baseCase_self() {
141 FunctionType f = ElementFactory.functionElement("f").type;
142 JUnitTestCase.assertTrue(f.isSubtypeOf(f));
143 }
144 void test_isSubtypeOf_namedParameters_isAssignable() {
145 ClassElement a = ElementFactory.classElement2("A", []);
146 ClassElement b = ElementFactory.classElement("B", a.type, []);
147 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "name"], <ClassElement> [a]).type;
148 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "name"], <ClassElement> [b]).type;
149 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
150 JUnitTestCase.assertTrue(s.isSubtypeOf(t));
151 }
152 void test_isSubtypeOf_namedParameters_isNotAssignable() {
153 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "name"], <ClassElement> [ElementFactory.classElement2("A", [])]).type;
154 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "name"], <ClassElement> [ElementFactory.classElement2("B", [])]).type;
155 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
156 }
157 void test_isSubtypeOf_namedParameters_namesDifferent() {
158 ClassElement a = ElementFactory.classElement2("A", []);
159 ClassElement b = ElementFactory.classElement("B", a.type, []);
160 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "name"], <ClassElement> [a]).type;
161 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "diff"], <ClassElement> [b]).type;
162 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
163 JUnitTestCase.assertFalse(s.isSubtypeOf(t));
164 }
165 void test_isSubtypeOf_namedParameters_orderOfParams() {
166 ClassElement a = ElementFactory.classElement2("A", []);
167 ClassElement b = ElementFactory.classElement("B", a.type, []);
168 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "A", "B"], <ClassElement> [a, b]).type;
169 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "B", "A"], <ClassElement> [b, a]).type;
170 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
171 }
172 void test_isSubtypeOf_namedParameters_orderOfParams2() {
173 ClassElement a = ElementFactory.classElement2("A", []);
174 ClassElement b = ElementFactory.classElement("B", a.type, []);
175 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "B"], <ClassElement> [b]).type;
176 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "B", "A"], <ClassElement> [b, a]).type;
177 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
178 }
179 void test_isSubtypeOf_namedParameters_orderOfParams3() {
180 ClassElement a = ElementFactory.classElement2("A", []);
181 ClassElement b = ElementFactory.classElement("B", a.type, []);
182 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "A", "B"], <ClassElement> [a, b]).type;
183 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "B"], <ClassElement> [b]).type;
184 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
185 }
186 void test_isSubtypeOf_namedParameters_sHasMoreParams() {
187 ClassElement a = ElementFactory.classElement2("A", []);
188 ClassElement b = ElementFactory.classElement("B", a.type, []);
189 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "name"], <ClassElement> [a]).type;
190 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "name", "name2"], <ClassElement> [b, b]).type;
191 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
192 }
193 void test_isSubtypeOf_namedParameters_tHasMoreParams() {
194 ClassElement a = ElementFactory.classElement2("A", []);
195 ClassElement b = ElementFactory.classElement("B", a.type, []);
196 FunctionType t = ElementFactory.functionElement4("t", null, null, <String> [ "name", "name2"], <ClassElement> [a, a]).type;
197 FunctionType s = ElementFactory.functionElement4("s", null, null, <String> [ "name"], <ClassElement> [b]).type;
198 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
199 }
200 void test_isSubtypeOf_normalParameters_isAssignable() {
201 ClassElement a = ElementFactory.classElement2("A", []);
202 ClassElement b = ElementFactory.classElement("B", a.type, []);
203 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [a]).ty pe;
204 FunctionType s = ElementFactory.functionElement5("s", <ClassElement> [b]).ty pe;
205 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
206 JUnitTestCase.assertTrue(s.isSubtypeOf(t));
207 }
208 void test_isSubtypeOf_normalParameters_isNotAssignable() {
209 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [Elemen tFactory.classElement2("A", [])]).type;
210 FunctionType s = ElementFactory.functionElement5("s", <ClassElement> [Elemen tFactory.classElement2("B", [])]).type;
211 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
212 }
213 void test_isSubtypeOf_normalParameters_sHasMoreParams() {
214 ClassElement a = ElementFactory.classElement2("A", []);
215 ClassElement b = ElementFactory.classElement("B", a.type, []);
216 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [a]).ty pe;
217 FunctionType s = ElementFactory.functionElement5("s", <ClassElement> [b, b]) .type;
218 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
219 }
220 void test_isSubtypeOf_normalParameters_tHasMoreParams() {
221 ClassElement a = ElementFactory.classElement2("A", []);
222 ClassElement b = ElementFactory.classElement("B", a.type, []);
223 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [a, a]) .type;
224 FunctionType s = ElementFactory.functionElement5("s", <ClassElement> [b]).ty pe;
225 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
226 }
227 void test_isSubtypeOf_optionalParameters_isAssignable() {
228 ClassElement a = ElementFactory.classElement2("A", []);
229 ClassElement b = ElementFactory.classElement("B", a.type, []);
230 FunctionType t = ElementFactory.functionElement6("t", null, <ClassElement> [ a]).type;
231 FunctionType s = ElementFactory.functionElement6("s", null, <ClassElement> [ b]).type;
232 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
233 JUnitTestCase.assertTrue(s.isSubtypeOf(t));
234 }
235 void test_isSubtypeOf_optionalParameters_isNotAssignable() {
236 FunctionType t = ElementFactory.functionElement6("t", null, <ClassElement> [ ElementFactory.classElement2("A", [])]).type;
237 FunctionType s = ElementFactory.functionElement6("s", null, <ClassElement> [ ElementFactory.classElement2("B", [])]).type;
238 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
239 }
240 void test_isSubtypeOf_optionalParameters_sHasMoreParams() {
241 ClassElement a = ElementFactory.classElement2("A", []);
242 ClassElement b = ElementFactory.classElement("B", a.type, []);
243 FunctionType t = ElementFactory.functionElement6("t", null, <ClassElement> [ a]).type;
244 FunctionType s = ElementFactory.functionElement6("s", null, <ClassElement> [ b, b]).type;
245 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
246 }
247 void test_isSubtypeOf_optionalParameters_tHasMoreParams() {
248 ClassElement a = ElementFactory.classElement2("A", []);
249 ClassElement b = ElementFactory.classElement("B", a.type, []);
250 FunctionType t = ElementFactory.functionElement6("t", null, <ClassElement> [ a, a]).type;
251 FunctionType s = ElementFactory.functionElement6("s", null, <ClassElement> [ b]).type;
252 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
253 }
254 void test_isSubtypeOf_returnType_sIsVoid() {
255 FunctionType t = ElementFactory.functionElement2("t", ElementFactory.classEl ement2("A", [])).type;
256 FunctionType s = ElementFactory.functionElement("s").type;
257 JUnitTestCase.assertTrue(VoidTypeImpl.instance == s.returnType);
258 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
259 }
260 void test_isSubtypeOf_returnType_tAssignableToS() {
261 ClassElement a = ElementFactory.classElement2("A", []);
262 ClassElement b = ElementFactory.classElement("B", a.type, []);
263 FunctionType t = ElementFactory.functionElement2("t", a).type;
264 FunctionType s = ElementFactory.functionElement2("s", b).type;
265 JUnitTestCase.assertTrue(t.isSubtypeOf(s));
266 JUnitTestCase.assertTrue(s.isSubtypeOf(t));
267 }
268 void test_isSubtypeOf_returnType_tNotAssignableToS() {
269 FunctionType t = ElementFactory.functionElement2("t", ElementFactory.classEl ement2("A", [])).type;
270 FunctionType s = ElementFactory.functionElement2("s", ElementFactory.classEl ement2("B", [])).type;
271 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
272 }
273 void test_isSubtypeOf_wrongFunctionType_normal_named() {
274 ClassElement a = ElementFactory.classElement2("A", []);
275 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [a]).ty pe;
276 FunctionType s = ElementFactory.functionElement7("s", null, <String> ["name" ], <ClassElement> [a]).type;
277 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
278 JUnitTestCase.assertFalse(s.isSubtypeOf(t));
279 }
280 void test_isSubtypeOf_wrongFunctionType_normal_optional() {
281 ClassElement a = ElementFactory.classElement2("A", []);
282 FunctionType t = ElementFactory.functionElement5("t", <ClassElement> [a]).ty pe;
283 FunctionType s = ElementFactory.functionElement6("s", null, <ClassElement> [ a]).type;
284 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
285 JUnitTestCase.assertFalse(s.isSubtypeOf(t));
286 }
287 void test_isSubtypeOf_wrongFunctionType_optional_named() {
288 ClassElement a = ElementFactory.classElement2("A", []);
289 FunctionType t = ElementFactory.functionElement6("t", null, <ClassElement> [ a]).type;
290 FunctionType s = ElementFactory.functionElement7("s", null, <String> ["name" ], <ClassElement> [a]).type;
291 JUnitTestCase.assertFalse(t.isSubtypeOf(s));
292 JUnitTestCase.assertFalse(s.isSubtypeOf(t));
293 }
294 void test_setNamedParameterTypes() {
295 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
296 LinkedHashMap<String, Type2> expectedTypes = new LinkedHashMap<String, Type2 >();
297 expectedTypes["a"] = new InterfaceTypeImpl.con1(new ClassElementImpl(ASTFact ory.identifier2("C")));
298 type.namedParameterTypes = expectedTypes;
299 Map<String, Type2> types = type.namedParameterTypes;
300 JUnitTestCase.assertEquals(expectedTypes, types);
301 }
302 void test_setNormalParameterTypes() {
303 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
304 List<Type2> expectedTypes = <Type2> [new InterfaceTypeImpl.con1(new ClassEle mentImpl(ASTFactory.identifier2("C")))];
305 type.normalParameterTypes = expectedTypes;
306 List<Type2> types = type.normalParameterTypes;
307 JUnitTestCase.assertEquals(expectedTypes, types);
308 }
309 void test_setReturnType() {
310 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
311 Type2 expectedType = new InterfaceTypeImpl.con1(new ClassElementImpl(ASTFact ory.identifier2("C")));
312 type.returnType = expectedType;
313 Type2 returnType6 = type.returnType;
314 JUnitTestCase.assertEquals(expectedType, returnType6);
315 }
316 void test_setTypeArguments() {
317 FunctionTypeImpl type = new FunctionTypeImpl.con1(new FunctionElementImpl.co n1(ASTFactory.identifier2("f")));
318 Type2 expectedType = new TypeVariableTypeImpl(new TypeVariableElementImpl(AS TFactory.identifier2("C")));
319 type.typeArguments = <Type2> [expectedType];
320 List<Type2> arguments = type.typeArguments;
321 EngineTestCase.assertLength(1, arguments);
322 JUnitTestCase.assertEquals(expectedType, arguments[0]);
323 }
324 void test_substitute2_equal() {
325 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(new FunctionElemen tImpl.con1(ASTFactory.identifier2("f")));
326 TypeVariableTypeImpl parameterType = new TypeVariableTypeImpl(new TypeVariab leElementImpl(ASTFactory.identifier2("E")));
327 functionType.returnType = parameterType;
328 functionType.normalParameterTypes = <Type2> [parameterType];
329 functionType.optionalParameterTypes = <Type2> [parameterType];
330 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
331 String namedParameterName = "c";
332 namedParameterTypes[namedParameterName] = parameterType;
333 functionType.namedParameterTypes = namedParameterTypes;
334 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(ASTFactory.identifier2("D")));
335 FunctionType result = functionType.substitute2(<Type2> [argumentType], <Type 2> [parameterType]);
336 JUnitTestCase.assertEquals(argumentType, result.returnType);
337 List<Type2> normalParameters = result.normalParameterTypes;
338 EngineTestCase.assertLength(1, normalParameters);
339 JUnitTestCase.assertEquals(argumentType, normalParameters[0]);
340 List<Type2> optionalParameters = result.optionalParameterTypes;
341 EngineTestCase.assertLength(1, optionalParameters);
342 JUnitTestCase.assertEquals(argumentType, optionalParameters[0]);
343 Map<String, Type2> namedParameters = result.namedParameterTypes;
344 EngineTestCase.assertSize2(1, namedParameters);
345 JUnitTestCase.assertEquals(argumentType, namedParameters[namedParameterName] );
346 }
347 void test_substitute2_notEqual() {
348 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(new FunctionElemen tImpl.con1(ASTFactory.identifier2("f")));
349 Type2 returnType = new InterfaceTypeImpl.con1(new ClassElementImpl(ASTFactor y.identifier2("R")));
350 Type2 normalParameterType = new InterfaceTypeImpl.con1(new ClassElementImpl( ASTFactory.identifier2("A")));
351 Type2 optionalParameterType = new InterfaceTypeImpl.con1(new ClassElementImp l(ASTFactory.identifier2("B")));
352 Type2 namedParameterType = new InterfaceTypeImpl.con1(new ClassElementImpl(A STFactory.identifier2("C")));
353 functionType.returnType = returnType;
354 functionType.normalParameterTypes = <Type2> [normalParameterType];
355 functionType.optionalParameterTypes = <Type2> [optionalParameterType];
356 LinkedHashMap<String, Type2> namedParameterTypes = new LinkedHashMap<String, Type2>();
357 String namedParameterName = "c";
358 namedParameterTypes[namedParameterName] = namedParameterType;
359 functionType.namedParameterTypes = namedParameterTypes;
360 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(ASTFactory.identifier2("D")));
361 TypeVariableTypeImpl parameterType = new TypeVariableTypeImpl(new TypeVariab leElementImpl(ASTFactory.identifier2("E")));
362 FunctionType result = functionType.substitute2(<Type2> [argumentType], <Type 2> [parameterType]);
363 JUnitTestCase.assertEquals(returnType, result.returnType);
364 List<Type2> normalParameters = result.normalParameterTypes;
365 EngineTestCase.assertLength(1, normalParameters);
366 JUnitTestCase.assertEquals(normalParameterType, normalParameters[0]);
367 List<Type2> optionalParameters = result.optionalParameterTypes;
368 EngineTestCase.assertLength(1, optionalParameters);
369 JUnitTestCase.assertEquals(optionalParameterType, optionalParameters[0]);
370 Map<String, Type2> namedParameters = result.namedParameterTypes;
371 EngineTestCase.assertSize2(1, namedParameters);
372 JUnitTestCase.assertEquals(namedParameterType, namedParameters[namedParamete rName]);
373 }
374 static dartSuite() {
375 _ut.group('FunctionTypeImplTest', () {
376 _ut.test('test_creation', () {
377 final __test = new FunctionTypeImplTest();
378 runJUnitTest(__test, __test.test_creation);
379 });
380 _ut.test('test_getElement', () {
381 final __test = new FunctionTypeImplTest();
382 runJUnitTest(__test, __test.test_getElement);
383 });
384 _ut.test('test_getNamedParameterTypes', () {
385 final __test = new FunctionTypeImplTest();
386 runJUnitTest(__test, __test.test_getNamedParameterTypes);
387 });
388 _ut.test('test_getNormalParameterTypes', () {
389 final __test = new FunctionTypeImplTest();
390 runJUnitTest(__test, __test.test_getNormalParameterTypes);
391 });
392 _ut.test('test_getReturnType', () {
393 final __test = new FunctionTypeImplTest();
394 runJUnitTest(__test, __test.test_getReturnType);
395 });
396 _ut.test('test_getTypeArguments', () {
397 final __test = new FunctionTypeImplTest();
398 runJUnitTest(__test, __test.test_getTypeArguments);
399 });
400 _ut.test('test_hashCode_element', () {
401 final __test = new FunctionTypeImplTest();
402 runJUnitTest(__test, __test.test_hashCode_element);
403 });
404 _ut.test('test_hashCode_noElement', () {
405 final __test = new FunctionTypeImplTest();
406 runJUnitTest(__test, __test.test_hashCode_noElement);
407 });
408 _ut.test('test_isSubtypeOf_baseCase_notFunctionType', () {
409 final __test = new FunctionTypeImplTest();
410 runJUnitTest(__test, __test.test_isSubtypeOf_baseCase_notFunctionType);
411 });
412 _ut.test('test_isSubtypeOf_baseCase_null', () {
413 final __test = new FunctionTypeImplTest();
414 runJUnitTest(__test, __test.test_isSubtypeOf_baseCase_null);
415 });
416 _ut.test('test_isSubtypeOf_baseCase_self', () {
417 final __test = new FunctionTypeImplTest();
418 runJUnitTest(__test, __test.test_isSubtypeOf_baseCase_self);
419 });
420 _ut.test('test_isSubtypeOf_namedParameters_isAssignable', () {
421 final __test = new FunctionTypeImplTest();
422 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_isAssignabl e);
423 });
424 _ut.test('test_isSubtypeOf_namedParameters_isNotAssignable', () {
425 final __test = new FunctionTypeImplTest();
426 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_isNotAssign able);
427 });
428 _ut.test('test_isSubtypeOf_namedParameters_namesDifferent', () {
429 final __test = new FunctionTypeImplTest();
430 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_namesDiffer ent);
431 });
432 _ut.test('test_isSubtypeOf_namedParameters_orderOfParams', () {
433 final __test = new FunctionTypeImplTest();
434 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_orderOfPara ms);
435 });
436 _ut.test('test_isSubtypeOf_namedParameters_orderOfParams2', () {
437 final __test = new FunctionTypeImplTest();
438 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_orderOfPara ms2);
439 });
440 _ut.test('test_isSubtypeOf_namedParameters_orderOfParams3', () {
441 final __test = new FunctionTypeImplTest();
442 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_orderOfPara ms3);
443 });
444 _ut.test('test_isSubtypeOf_namedParameters_sHasMoreParams', () {
445 final __test = new FunctionTypeImplTest();
446 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_sHasMorePar ams);
447 });
448 _ut.test('test_isSubtypeOf_namedParameters_tHasMoreParams', () {
449 final __test = new FunctionTypeImplTest();
450 runJUnitTest(__test, __test.test_isSubtypeOf_namedParameters_tHasMorePar ams);
451 });
452 _ut.test('test_isSubtypeOf_normalParameters_isAssignable', () {
453 final __test = new FunctionTypeImplTest();
454 runJUnitTest(__test, __test.test_isSubtypeOf_normalParameters_isAssignab le);
455 });
456 _ut.test('test_isSubtypeOf_normalParameters_isNotAssignable', () {
457 final __test = new FunctionTypeImplTest();
458 runJUnitTest(__test, __test.test_isSubtypeOf_normalParameters_isNotAssig nable);
459 });
460 _ut.test('test_isSubtypeOf_normalParameters_sHasMoreParams', () {
461 final __test = new FunctionTypeImplTest();
462 runJUnitTest(__test, __test.test_isSubtypeOf_normalParameters_sHasMorePa rams);
463 });
464 _ut.test('test_isSubtypeOf_normalParameters_tHasMoreParams', () {
465 final __test = new FunctionTypeImplTest();
466 runJUnitTest(__test, __test.test_isSubtypeOf_normalParameters_tHasMorePa rams);
467 });
468 _ut.test('test_isSubtypeOf_optionalParameters_isAssignable', () {
469 final __test = new FunctionTypeImplTest();
470 runJUnitTest(__test, __test.test_isSubtypeOf_optionalParameters_isAssign able);
471 });
472 _ut.test('test_isSubtypeOf_optionalParameters_isNotAssignable', () {
473 final __test = new FunctionTypeImplTest();
474 runJUnitTest(__test, __test.test_isSubtypeOf_optionalParameters_isNotAss ignable);
475 });
476 _ut.test('test_isSubtypeOf_optionalParameters_sHasMoreParams', () {
477 final __test = new FunctionTypeImplTest();
478 runJUnitTest(__test, __test.test_isSubtypeOf_optionalParameters_sHasMore Params);
479 });
480 _ut.test('test_isSubtypeOf_optionalParameters_tHasMoreParams', () {
481 final __test = new FunctionTypeImplTest();
482 runJUnitTest(__test, __test.test_isSubtypeOf_optionalParameters_tHasMore Params);
483 });
484 _ut.test('test_isSubtypeOf_returnType_sIsVoid', () {
485 final __test = new FunctionTypeImplTest();
486 runJUnitTest(__test, __test.test_isSubtypeOf_returnType_sIsVoid);
487 });
488 _ut.test('test_isSubtypeOf_returnType_tAssignableToS', () {
489 final __test = new FunctionTypeImplTest();
490 runJUnitTest(__test, __test.test_isSubtypeOf_returnType_tAssignableToS);
491 });
492 _ut.test('test_isSubtypeOf_returnType_tNotAssignableToS', () {
493 final __test = new FunctionTypeImplTest();
494 runJUnitTest(__test, __test.test_isSubtypeOf_returnType_tNotAssignableTo S);
495 });
496 _ut.test('test_isSubtypeOf_wrongFunctionType_normal_named', () {
497 final __test = new FunctionTypeImplTest();
498 runJUnitTest(__test, __test.test_isSubtypeOf_wrongFunctionType_normal_na med);
499 });
500 _ut.test('test_isSubtypeOf_wrongFunctionType_normal_optional', () {
501 final __test = new FunctionTypeImplTest();
502 runJUnitTest(__test, __test.test_isSubtypeOf_wrongFunctionType_normal_op tional);
503 });
504 _ut.test('test_isSubtypeOf_wrongFunctionType_optional_named', () {
505 final __test = new FunctionTypeImplTest();
506 runJUnitTest(__test, __test.test_isSubtypeOf_wrongFunctionType_optional_ named);
507 });
508 _ut.test('test_setNamedParameterTypes', () {
509 final __test = new FunctionTypeImplTest();
510 runJUnitTest(__test, __test.test_setNamedParameterTypes);
511 });
512 _ut.test('test_setNormalParameterTypes', () {
513 final __test = new FunctionTypeImplTest();
514 runJUnitTest(__test, __test.test_setNormalParameterTypes);
515 });
516 _ut.test('test_setReturnType', () {
517 final __test = new FunctionTypeImplTest();
518 runJUnitTest(__test, __test.test_setReturnType);
519 });
520 _ut.test('test_setTypeArguments', () {
521 final __test = new FunctionTypeImplTest();
522 runJUnitTest(__test, __test.test_setTypeArguments);
523 });
524 _ut.test('test_substitute2_equal', () {
525 final __test = new FunctionTypeImplTest();
526 runJUnitTest(__test, __test.test_substitute2_equal);
527 });
528 _ut.test('test_substitute2_notEqual', () {
529 final __test = new FunctionTypeImplTest();
530 runJUnitTest(__test, __test.test_substitute2_notEqual);
531 });
532 });
533 }
534 }
535 class LibraryElementImplTest extends EngineTestCase {
536 void test_creation() {
537 JUnitTestCase.assertNotNull(new LibraryElementImpl(new AnalysisContextImpl() , ASTFactory.libraryIdentifier2(["l"])));
538 }
539 void test_getImportedLibraries() {
540 AnalysisContext context = new AnalysisContextImpl();
541 LibraryElementImpl library1 = ElementFactory.library(context, "l1");
542 LibraryElementImpl library2 = ElementFactory.library(context, "l2");
543 LibraryElementImpl library3 = ElementFactory.library(context, "l3");
544 LibraryElementImpl library4 = ElementFactory.library(context, "l4");
545 PrefixElement prefixA = new PrefixElementImpl(ASTFactory.identifier2("a"));
546 PrefixElement prefixB = new PrefixElementImpl(ASTFactory.identifier2("b"));
547 List<ImportElementImpl> imports = [ElementFactory.importFor(library2, null, []), ElementFactory.importFor(library2, prefixB, []), ElementFactory.importFor(l ibrary3, null, []), ElementFactory.importFor(library3, prefixA, []), ElementFact ory.importFor(library3, prefixB, []), ElementFactory.importFor(library4, prefixA , [])];
548 library1.imports = imports;
549 List<LibraryElement> libraries = library1.importedLibraries;
550 EngineTestCase.assertEqualsIgnoreOrder(<LibraryElement> [library2, library3, library4], libraries);
551 }
552 void test_getPrefixes() {
553 AnalysisContext context = new AnalysisContextImpl();
554 LibraryElementImpl library17 = ElementFactory.library(context, "l1");
555 PrefixElement prefixA = new PrefixElementImpl(ASTFactory.identifier2("a"));
556 PrefixElement prefixB = new PrefixElementImpl(ASTFactory.identifier2("b"));
557 List<ImportElementImpl> imports = [ElementFactory.importFor(ElementFactory.l ibrary(context, "l2"), null, []), ElementFactory.importFor(ElementFactory.librar y(context, "l3"), null, []), ElementFactory.importFor(ElementFactory.library(con text, "l4"), prefixA, []), ElementFactory.importFor(ElementFactory.library(conte xt, "l5"), prefixA, []), ElementFactory.importFor(ElementFactory.library(context , "l6"), prefixB, [])];
558 library17.imports = imports;
559 List<PrefixElement> prefixes2 = library17.prefixes;
560 EngineTestCase.assertLength(2, prefixes2);
561 if (identical(prefixA, prefixes2[0])) {
562 JUnitTestCase.assertEquals(prefixB, prefixes2[1]);
563 } else {
564 JUnitTestCase.assertEquals(prefixB, prefixes2[0]);
565 JUnitTestCase.assertEquals(prefixA, prefixes2[1]);
566 }
567 }
568 void test_setImports() {
569 AnalysisContext context = new AnalysisContextImpl();
570 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2(["l1"]));
571 List<ImportElementImpl> expectedImports = [ElementFactory.importFor(ElementF actory.library(context, "l2"), null, []), ElementFactory.importFor(ElementFactor y.library(context, "l3"), null, [])];
572 library.imports = expectedImports;
573 List<ImportElement> actualImports = library.imports;
574 EngineTestCase.assertLength(expectedImports.length, actualImports);
575 for (int i = 0; i < actualImports.length; i++) {
576 JUnitTestCase.assertEquals(expectedImports[i], actualImports[i]);
577 }
578 }
579 static dartSuite() {
580 _ut.group('LibraryElementImplTest', () {
581 _ut.test('test_creation', () {
582 final __test = new LibraryElementImplTest();
583 runJUnitTest(__test, __test.test_creation);
584 });
585 _ut.test('test_getImportedLibraries', () {
586 final __test = new LibraryElementImplTest();
587 runJUnitTest(__test, __test.test_getImportedLibraries);
588 });
589 _ut.test('test_getPrefixes', () {
590 final __test = new LibraryElementImplTest();
591 runJUnitTest(__test, __test.test_getPrefixes);
592 });
593 _ut.test('test_setImports', () {
594 final __test = new LibraryElementImplTest();
595 runJUnitTest(__test, __test.test_setImports);
596 });
597 });
598 }
599 }
600 /**
601 * The class {@code ElementFactory} defines utility methods used to create eleme nts for testing
602 * purposes.
603 */
604 class ElementFactory {
605 /**
606 * The element representing the class 'Object'.
607 */
608 static ClassElement _objectElement;
609 static ClassElement classElement(String typeName, InterfaceType superclassType , List<String> parameterNames) {
610 ClassElementImpl element = new ClassElementImpl(ASTFactory.identifier2(typeN ame));
611 element.supertype = superclassType;
612 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element);
613 element.type = type;
614 int count = parameterNames.length;
615 if (count > 0) {
616 List<TypeVariableElementImpl> typeVariables = new List<TypeVariableElement Impl>.fixedLength(count);
617 List<TypeVariableTypeImpl> typeArguments = new List<TypeVariableTypeImpl>. fixedLength(count);
618 for (int i = 0; i < count; i++) {
619 TypeVariableElementImpl variable = new TypeVariableElementImpl(ASTFactor y.identifier2(parameterNames[i]));
620 typeVariables[i] = variable;
621 typeArguments[i] = new TypeVariableTypeImpl(variable);
622 variable.type = typeArguments[i];
623 }
624 element.typeVariables = typeVariables;
625 type.typeArguments = typeArguments;
626 }
627 return element;
628 }
629 static ClassElement classElement2(String typeName, List<String> parameterNames ) => classElement(typeName, object.type, parameterNames);
630 static ConstructorElement constructorElement(String name) => new ConstructorEl ementImpl(name == null ? null : ASTFactory.identifier2(name));
631 static FieldElement fieldElement(String name, bool isStatic, bool isFinal, boo l isConst, Type2 type27) {
632 FieldElementImpl field = new FieldElementImpl.con1(ASTFactory.identifier2(na me));
633 field.const2 = isConst;
634 field.final2 = isFinal;
635 field.static = isStatic;
636 field.type = type27;
637 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con1(fi eld);
638 getter.getter = true;
639 getter.synthetic = true;
640 field.getter = getter;
641 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
642 getterType.returnType = type27;
643 getter.type = getterType;
644 if (!isConst && !isFinal) {
645 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con1( field);
646 setter.setter = true;
647 setter.synthetic = true;
648 field.setter = setter;
649 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(getter);
650 setterType.normalParameterTypes = <Type2> [type27];
651 setterType.returnType = VoidTypeImpl.instance;
652 setter.type = setterType;
653 }
654 return field;
655 }
656 static FunctionElement functionElement(String functionName) => functionElement 4(functionName, null, null, null, null);
657 static FunctionElement functionElement2(String functionName, ClassElement retu rnElement) => functionElement3(functionName, returnElement, null, null);
658 static FunctionElement functionElement3(String functionName, ClassElement retu rnElement, List<ClassElement> normalParameters, List<ClassElement> optionalParam eters) {
659 FunctionElementImpl functionElement = new FunctionElementImpl.con1(ASTFactor y.identifier2(functionName));
660 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
661 functionElement.type = functionType;
662 if (returnElement != null) {
663 functionType.returnType = returnElement.type;
664 }
665 int count = normalParameters == null ? 0 : normalParameters.length;
666 if (count > 0) {
667 List<InterfaceType> normalParameterTypes = new List<InterfaceType>.fixedLe ngth(count);
668 for (int i = 0; i < count; i++) {
669 normalParameterTypes[i] = normalParameters[i].type;
670 }
671 functionType.normalParameterTypes = normalParameterTypes;
672 }
673 count = optionalParameters == null ? 0 : optionalParameters.length;
674 if (count > 0) {
675 List<InterfaceType> optionalParameterTypes = new List<InterfaceType>.fixed Length(count);
676 for (int i = 0; i < count; i++) {
677 optionalParameterTypes[i] = optionalParameters[i].type;
678 }
679 functionType.optionalParameterTypes = optionalParameterTypes;
680 }
681 return functionElement;
682 }
683 static FunctionElement functionElement4(String functionName, ClassElement retu rnElement, List<ClassElement> normalParameters, List<String> names, List<ClassEl ement> namedParameters) {
684 FunctionElementImpl functionElement = new FunctionElementImpl.con1(ASTFactor y.identifier2(functionName));
685 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(functionElement);
686 functionElement.type = functionType;
687 if (returnElement != null) {
688 functionType.returnType = returnElement.type;
689 }
690 int count = normalParameters == null ? 0 : normalParameters.length;
691 if (count > 0) {
692 List<InterfaceType> normalParameterTypes = new List<InterfaceType>.fixedLe ngth(count);
693 for (int i = 0; i < count; i++) {
694 normalParameterTypes[i] = normalParameters[i].type;
695 }
696 functionType.normalParameterTypes = normalParameterTypes;
697 }
698 if (names != null && names.length > 0 && names.length == namedParameters.len gth) {
699 LinkedHashMap<String, Type2> map = new LinkedHashMap<String, Type2>();
700 for (int i = 0; i < names.length; i++) {
701 map[names[i]] = namedParameters[i].type;
702 }
703 functionType.namedParameterTypes = map;
704 } else if (names != null) {
705 throw new IllegalStateException("The passed String[] and ClassElement[] ar rays had different lengths.");
706 }
707 return functionElement;
708 }
709 static FunctionElement functionElement5(String functionName, List<ClassElement > normalParameters) => functionElement3(functionName, null, normalParameters, nu ll);
710 static FunctionElement functionElement6(String functionName, List<ClassElement > normalParameters, List<ClassElement> optionalParameters) => functionElement3(f unctionName, null, normalParameters, optionalParameters);
711 static FunctionElement functionElement7(String functionName, List<ClassElement > normalParameters, List<String> names, List<ClassElement> namedParameters) => f unctionElement4(functionName, null, normalParameters, names, namedParameters);
712 static ClassElement get object {
713 if (_objectElement == null) {
714 _objectElement = classElement("Object", (null as InterfaceType), []);
715 }
716 return _objectElement;
717 }
718 static PropertyAccessorElement getterElement(String name, bool isStatic, Type2 type28) {
719 FieldElementImpl field = new FieldElementImpl.con1(ASTFactory.identifier2(na me));
720 field.static = isStatic;
721 field.synthetic = true;
722 field.type = type28;
723 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con1(fi eld);
724 getter.getter = true;
725 field.getter = getter;
726 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
727 getterType.returnType = type28;
728 getter.type = getterType;
729 return getter;
730 }
731 static ImportElementImpl importFor(LibraryElement importedLibrary4, PrefixElem ent prefix12, List<NamespaceCombinator> combinators4) {
732 ImportElementImpl spec = new ImportElementImpl();
733 spec.importedLibrary = importedLibrary4;
734 spec.prefix = prefix12;
735 spec.combinators = combinators4;
736 return spec;
737 }
738 static LibraryElementImpl library(AnalysisContext context, String libraryName) {
739 String fileName = "${libraryName}.dart";
740 FileBasedSource source = new FileBasedSource.con1(null, createFile(fileName) );
741 CompilationUnitElementImpl unit = new CompilationUnitElementImpl(fileName);
742 unit.source = source;
743 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2([libraryName]));
744 library.definingCompilationUnit = unit;
745 return library;
746 }
747 static MethodElement methodElement(String methodName, Type2 returnType9, List< Type2> argumentTypes) {
748 MethodElementImpl method = new MethodElementImpl.con1(ASTFactory.identifier2 (methodName));
749 int count = argumentTypes.length;
750 List<ParameterElement> parameters = new List<ParameterElement>.fixedLength(c ount);
751 for (int i = 0; i < count; i++) {
752 ParameterElementImpl parameter = new ParameterElementImpl(ASTFactory.ident ifier2("a${i}"));
753 parameter.type = argumentTypes[i];
754 parameters[i] = parameter;
755 }
756 method.parameters = parameters;
757 FunctionTypeImpl methodType = new FunctionTypeImpl.con1(method);
758 methodType.normalParameterTypes = argumentTypes;
759 methodType.returnType = returnType9;
760 method.type = methodType;
761 return method;
762 }
763 static PropertyAccessorElement setterElement(String name, bool isStatic, Type2 type29) {
764 FieldElementImpl field = new FieldElementImpl.con1(ASTFactory.identifier2(na me));
765 field.static = isStatic;
766 field.synthetic = true;
767 field.type = type29;
768 PropertyAccessorElementImpl getter = new PropertyAccessorElementImpl.con1(fi eld);
769 getter.getter = true;
770 field.getter = getter;
771 FunctionTypeImpl getterType = new FunctionTypeImpl.con1(getter);
772 getterType.returnType = type29;
773 getter.type = getterType;
774 PropertyAccessorElementImpl setter = new PropertyAccessorElementImpl.con1(fi eld);
775 setter.setter = true;
776 setter.synthetic = true;
777 field.setter = setter;
778 FunctionTypeImpl setterType = new FunctionTypeImpl.con1(getter);
779 setterType.normalParameterTypes = <Type2> [type29];
780 setterType.returnType = VoidTypeImpl.instance;
781 setter.type = setterType;
782 return setter;
783 }
784 static VariableElement variableElement(String name) => new VariableElementImpl .con2(name, -1);
785 /**
786 * Prevent the creation of instances of this class.
787 */
788 ElementFactory() {
789 }
790 }
791 class ElementImplTest extends EngineTestCase {
792 void test_isAccessibleIn_private_differentLibrary() {
793 AnalysisContextImpl context = new AnalysisContextImpl();
794 LibraryElementImpl library1 = ElementFactory.library(context, "lib1");
795 ClassElement classElement = ElementFactory.classElement2("_C", []);
796 ((library1.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classElement];
797 LibraryElementImpl library2 = ElementFactory.library(context, "lib2");
798 JUnitTestCase.assertFalse(classElement.isAccessibleIn(library2));
799 }
800 void test_isAccessibleIn_private_sameLibrary() {
801 LibraryElementImpl library15 = ElementFactory.library(new AnalysisContextImp l(), "lib");
802 ClassElement classElement = ElementFactory.classElement2("_C", []);
803 ((library15.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classElement];
804 JUnitTestCase.assertTrue(classElement.isAccessibleIn(library15));
805 }
806 void test_isAccessibleIn_public_differentLibrary() {
807 AnalysisContextImpl context = new AnalysisContextImpl();
808 LibraryElementImpl library1 = ElementFactory.library(context, "lib1");
809 ClassElement classElement = ElementFactory.classElement2("C", []);
810 ((library1.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classElement];
811 LibraryElementImpl library2 = ElementFactory.library(context, "lib2");
812 JUnitTestCase.assertTrue(classElement.isAccessibleIn(library2));
813 }
814 void test_isAccessibleIn_public_sameLibrary() {
815 LibraryElementImpl library16 = ElementFactory.library(new AnalysisContextImp l(), "lib");
816 ClassElement classElement = ElementFactory.classElement2("C", []);
817 ((library16.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classElement];
818 JUnitTestCase.assertTrue(classElement.isAccessibleIn(library16));
819 }
820 static dartSuite() {
821 _ut.group('ElementImplTest', () {
822 _ut.test('test_isAccessibleIn_private_differentLibrary', () {
823 final __test = new ElementImplTest();
824 runJUnitTest(__test, __test.test_isAccessibleIn_private_differentLibrary );
825 });
826 _ut.test('test_isAccessibleIn_private_sameLibrary', () {
827 final __test = new ElementImplTest();
828 runJUnitTest(__test, __test.test_isAccessibleIn_private_sameLibrary);
829 });
830 _ut.test('test_isAccessibleIn_public_differentLibrary', () {
831 final __test = new ElementImplTest();
832 runJUnitTest(__test, __test.test_isAccessibleIn_public_differentLibrary) ;
833 });
834 _ut.test('test_isAccessibleIn_public_sameLibrary', () {
835 final __test = new ElementImplTest();
836 runJUnitTest(__test, __test.test_isAccessibleIn_public_sameLibrary);
837 });
838 });
839 }
840 }
841 class InterfaceTypeImplTest extends EngineTestCase {
842 void test_computeLongestInheritancePathToObject_multipleInterfacePaths() {
843 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
844 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
845 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
846 ClassElementImpl elementD = (ElementFactory.classElement2("D", []) as ClassE lementImpl);
847 ClassElementImpl elementE = (ElementFactory.classElement2("E", []) as ClassE lementImpl);
848 elementB.interfaces = <InterfaceType> [elementA.type];
849 elementC.interfaces = <InterfaceType> [elementA.type];
850 elementD.interfaces = <InterfaceType> [elementC.type];
851 elementE.interfaces = <InterfaceType> [elementB.type, elementD.type];
852 JUnitTestCase.assertEquals(2, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementB.type));
853 JUnitTestCase.assertEquals(4, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementE.type));
854 }
855 void test_computeLongestInheritancePathToObject_multipleSuperclassPaths() {
856 ClassElement elementA = ElementFactory.classElement2("A", []);
857 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
858 ClassElement elementC = ElementFactory.classElement("C", elementA.type, []);
859 ClassElement elementD = ElementFactory.classElement("D", elementC.type, []);
860 ClassElementImpl elementE = (ElementFactory.classElement("E", elementB.type, []) as ClassElementImpl);
861 elementE.interfaces = <InterfaceType> [elementD.type];
862 JUnitTestCase.assertEquals(2, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementB.type));
863 JUnitTestCase.assertEquals(4, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementE.type));
864 }
865 void test_computeLongestInheritancePathToObject_object() {
866 ClassElement elementA = ElementFactory.classElement2("A", []);
867 InterfaceType object = elementA.supertype;
868 JUnitTestCase.assertEquals(0, InterfaceTypeImpl.computeLongestInheritancePat hToObject(object));
869 }
870 void test_computeLongestInheritancePathToObject_singleInterfacePath() {
871 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
872 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
873 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
874 elementB.interfaces = <InterfaceType> [elementA.type];
875 elementC.interfaces = <InterfaceType> [elementB.type];
876 JUnitTestCase.assertEquals(1, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementA.type));
877 JUnitTestCase.assertEquals(2, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementB.type));
878 JUnitTestCase.assertEquals(3, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementC.type));
879 }
880 void test_computeLongestInheritancePathToObject_singleSuperclassPath() {
881 ClassElement elementA = ElementFactory.classElement2("A", []);
882 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
883 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
884 JUnitTestCase.assertEquals(1, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementA.type));
885 JUnitTestCase.assertEquals(2, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementB.type));
886 JUnitTestCase.assertEquals(3, InterfaceTypeImpl.computeLongestInheritancePat hToObject(elementC.type));
887 }
888 void test_computeSuperinterfaceSet_multipleInterfacePaths() {
889 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
890 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
891 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
892 ClassElementImpl elementD = (ElementFactory.classElement2("D", []) as ClassE lementImpl);
893 ClassElementImpl elementE = (ElementFactory.classElement2("E", []) as ClassE lementImpl);
894 elementB.interfaces = <InterfaceType> [elementA.type];
895 elementC.interfaces = <InterfaceType> [elementA.type];
896 elementD.interfaces = <InterfaceType> [elementC.type];
897 elementE.interfaces = <InterfaceType> [elementB.type, elementD.type];
898 Set<InterfaceType> superinterfacesOfD = InterfaceTypeImpl.computeSuperinterf aceSet(elementD.type);
899 JUnitTestCase.assertNotNull(superinterfacesOfD);
900 JUnitTestCase.assertTrue(superinterfacesOfD.contains(ElementFactory.object.t ype));
901 JUnitTestCase.assertTrue(superinterfacesOfD.contains(elementA.type));
902 JUnitTestCase.assertTrue(superinterfacesOfD.contains(elementC.type));
903 JUnitTestCase.assertEquals(3, superinterfacesOfD.length);
904 Set<InterfaceType> superinterfacesOfE = InterfaceTypeImpl.computeSuperinterf aceSet(elementE.type);
905 JUnitTestCase.assertNotNull(superinterfacesOfE);
906 JUnitTestCase.assertTrue(superinterfacesOfE.contains(ElementFactory.object.t ype));
907 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementA.type));
908 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementB.type));
909 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementC.type));
910 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementD.type));
911 JUnitTestCase.assertEquals(5, superinterfacesOfE.length);
912 }
913 void test_computeSuperinterfaceSet_multipleSuperclassPaths() {
914 ClassElement elementA = ElementFactory.classElement2("A", []);
915 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
916 ClassElement elementC = ElementFactory.classElement("C", elementA.type, []);
917 ClassElement elementD = ElementFactory.classElement("D", elementC.type, []);
918 ClassElementImpl elementE = (ElementFactory.classElement("E", elementB.type, []) as ClassElementImpl);
919 elementE.interfaces = <InterfaceType> [elementD.type];
920 Set<InterfaceType> superinterfacesOfD = InterfaceTypeImpl.computeSuperinterf aceSet(elementD.type);
921 JUnitTestCase.assertNotNull(superinterfacesOfD);
922 JUnitTestCase.assertTrue(superinterfacesOfD.contains(ElementFactory.object.t ype));
923 JUnitTestCase.assertTrue(superinterfacesOfD.contains(elementA.type));
924 JUnitTestCase.assertTrue(superinterfacesOfD.contains(elementC.type));
925 JUnitTestCase.assertEquals(3, superinterfacesOfD.length);
926 Set<InterfaceType> superinterfacesOfE = InterfaceTypeImpl.computeSuperinterf aceSet(elementE.type);
927 JUnitTestCase.assertNotNull(superinterfacesOfE);
928 JUnitTestCase.assertTrue(superinterfacesOfE.contains(ElementFactory.object.t ype));
929 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementA.type));
930 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementB.type));
931 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementC.type));
932 JUnitTestCase.assertTrue(superinterfacesOfE.contains(elementD.type));
933 JUnitTestCase.assertEquals(5, superinterfacesOfE.length);
934 }
935 void test_computeSuperinterfaceSet_singleInterfacePath() {
936 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
937 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
938 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
939 elementB.interfaces = <InterfaceType> [elementA.type];
940 elementC.interfaces = <InterfaceType> [elementB.type];
941 Set<InterfaceType> superinterfacesOfA = InterfaceTypeImpl.computeSuperinterf aceSet(elementA.type);
942 JUnitTestCase.assertNotNull(superinterfacesOfA);
943 JUnitTestCase.assertTrue(superinterfacesOfA.contains(ElementFactory.object.t ype));
944 JUnitTestCase.assertEquals(1, superinterfacesOfA.length);
945 Set<InterfaceType> superinterfacesOfB = InterfaceTypeImpl.computeSuperinterf aceSet(elementB.type);
946 JUnitTestCase.assertNotNull(superinterfacesOfB);
947 JUnitTestCase.assertTrue(superinterfacesOfB.contains(ElementFactory.object.t ype));
948 JUnitTestCase.assertTrue(superinterfacesOfB.contains(elementA.type));
949 JUnitTestCase.assertEquals(2, superinterfacesOfB.length);
950 Set<InterfaceType> superinterfacesOfC = InterfaceTypeImpl.computeSuperinterf aceSet(elementC.type);
951 JUnitTestCase.assertNotNull(superinterfacesOfC);
952 JUnitTestCase.assertTrue(superinterfacesOfC.contains(ElementFactory.object.t ype));
953 JUnitTestCase.assertTrue(superinterfacesOfC.contains(elementA.type));
954 JUnitTestCase.assertTrue(superinterfacesOfC.contains(elementB.type));
955 JUnitTestCase.assertEquals(3, superinterfacesOfC.length);
956 }
957 void test_computeSuperinterfaceSet_singleSuperclassPath() {
958 ClassElement elementA = ElementFactory.classElement2("A", []);
959 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
960 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
961 Set<InterfaceType> superinterfacesOfA = InterfaceTypeImpl.computeSuperinterf aceSet(elementA.type);
962 JUnitTestCase.assertNotNull(superinterfacesOfA);
963 JUnitTestCase.assertTrue(superinterfacesOfA.contains(ElementFactory.object.t ype));
964 JUnitTestCase.assertEquals(1, superinterfacesOfA.length);
965 Set<InterfaceType> superinterfacesOfB = InterfaceTypeImpl.computeSuperinterf aceSet(elementB.type);
966 JUnitTestCase.assertNotNull(superinterfacesOfB);
967 JUnitTestCase.assertTrue(superinterfacesOfB.contains(ElementFactory.object.t ype));
968 JUnitTestCase.assertTrue(superinterfacesOfB.contains(elementA.type));
969 JUnitTestCase.assertEquals(2, superinterfacesOfB.length);
970 Set<InterfaceType> superinterfacesOfC = InterfaceTypeImpl.computeSuperinterf aceSet(elementC.type);
971 JUnitTestCase.assertNotNull(superinterfacesOfC);
972 JUnitTestCase.assertTrue(superinterfacesOfC.contains(ElementFactory.object.t ype));
973 JUnitTestCase.assertTrue(superinterfacesOfC.contains(elementA.type));
974 JUnitTestCase.assertTrue(superinterfacesOfC.contains(elementB.type));
975 JUnitTestCase.assertEquals(3, superinterfacesOfC.length);
976 }
977 void test_creation() {
978 JUnitTestCase.assertNotNull(new InterfaceTypeImpl.con1(new ClassElementImpl( ASTFactory.identifier2("A"))));
979 }
980 void test_getElement() {
981 ClassElementImpl typeElement = new ClassElementImpl(ASTFactory.identifier2(" A"));
982 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(typeElement);
983 JUnitTestCase.assertEquals(typeElement, type.element);
984 }
985 void test_getLeastUpperBound_directInterfaceCase() {
986 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
987 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
988 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
989 InterfaceType typeA = elementA.type;
990 InterfaceType typeB = elementB.type;
991 InterfaceType typeC = elementC.type;
992 elementB.interfaces = <InterfaceType> [typeA];
993 elementC.interfaces = <InterfaceType> [typeB];
994 JUnitTestCase.assertEquals(typeB, typeB.getLeastUpperBound(typeC));
995 JUnitTestCase.assertEquals(typeB, typeC.getLeastUpperBound(typeB));
996 }
997 void test_getLeastUpperBound_directSubclassCase() {
998 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
999 ClassElementImpl elementB = (ElementFactory.classElement("B", elementA.type, []) as ClassElementImpl);
1000 ClassElementImpl elementC = (ElementFactory.classElement("C", elementB.type, []) as ClassElementImpl);
1001 InterfaceType typeB = elementB.type;
1002 InterfaceType typeC = elementC.type;
1003 JUnitTestCase.assertEquals(typeB, typeB.getLeastUpperBound(typeC));
1004 JUnitTestCase.assertEquals(typeB, typeC.getLeastUpperBound(typeB));
1005 }
1006 void test_getLeastUpperBound_functionType() {
1007 Type2 interfaceType = ElementFactory.classElement2("A", []).type;
1008 FunctionTypeImpl functionType = new FunctionTypeImpl.con1(new FunctionElemen tImpl.con1(ASTFactory.identifier2("f")));
1009 JUnitTestCase.assertNull(interfaceType.getLeastUpperBound(functionType));
1010 }
1011 void test_getLeastUpperBound_mixinCase() {
1012 ClassElement elementA = ElementFactory.classElement2("A", []);
1013 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1014 ClassElement elementC = ElementFactory.classElement("C", elementA.type, []);
1015 ClassElementImpl elementD = (ElementFactory.classElement("D", elementB.type, []) as ClassElementImpl);
1016 InterfaceType typeA = elementA.type;
1017 InterfaceType typeC = elementC.type;
1018 InterfaceType typeD = elementD.type;
1019 elementD.mixins = <InterfaceType> [ElementFactory.classElement2("M", []).typ e, ElementFactory.classElement2("N", []).type, ElementFactory.classElement2("O", []).type, ElementFactory.classElement2("P", []).type];
1020 JUnitTestCase.assertEquals(typeA, typeD.getLeastUpperBound(typeC));
1021 JUnitTestCase.assertEquals(typeA, typeC.getLeastUpperBound(typeD));
1022 }
1023 void test_getLeastUpperBound_null() {
1024 Type2 interfaceType = ElementFactory.classElement2("A", []).type;
1025 JUnitTestCase.assertNull(interfaceType.getLeastUpperBound(null));
1026 }
1027 void test_getLeastUpperBound_object() {
1028 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1029 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
1030 InterfaceType typeA = elementA.type;
1031 InterfaceType typeB = elementB.type;
1032 Type2 typeObject = typeA.element.supertype;
1033 JUnitTestCase.assertNull(((typeObject.element as ClassElement)).supertype);
1034 JUnitTestCase.assertEquals(typeObject, typeB.element.supertype);
1035 JUnitTestCase.assertEquals(typeObject, typeA.getLeastUpperBound(typeB));
1036 }
1037 void test_getLeastUpperBound_self() {
1038 ClassElement elementA = ElementFactory.classElement2("A", []);
1039 InterfaceType typeA = elementA.type;
1040 JUnitTestCase.assertEquals(typeA, typeA.getLeastUpperBound(typeA));
1041 }
1042 void test_getLeastUpperBound_sharedSuperclass1() {
1043 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1044 ClassElementImpl elementB = (ElementFactory.classElement("B", elementA.type, []) as ClassElementImpl);
1045 ClassElementImpl elementC = (ElementFactory.classElement("C", elementA.type, []) as ClassElementImpl);
1046 InterfaceType typeA = elementA.type;
1047 InterfaceType typeB = elementB.type;
1048 InterfaceType typeC = elementC.type;
1049 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeC));
1050 JUnitTestCase.assertEquals(typeA, typeC.getLeastUpperBound(typeB));
1051 }
1052 void test_getLeastUpperBound_sharedSuperclass2() {
1053 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1054 ClassElementImpl elementB = (ElementFactory.classElement("B", elementA.type, []) as ClassElementImpl);
1055 ClassElementImpl elementC = (ElementFactory.classElement("C", elementA.type, []) as ClassElementImpl);
1056 ClassElementImpl elementD = (ElementFactory.classElement("D", elementC.type, []) as ClassElementImpl);
1057 InterfaceType typeA = elementA.type;
1058 InterfaceType typeB = elementB.type;
1059 InterfaceType typeD = elementD.type;
1060 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeD));
1061 JUnitTestCase.assertEquals(typeA, typeD.getLeastUpperBound(typeB));
1062 }
1063 void test_getLeastUpperBound_sharedSuperclass3() {
1064 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1065 ClassElementImpl elementB = (ElementFactory.classElement("B", elementA.type, []) as ClassElementImpl);
1066 ClassElementImpl elementC = (ElementFactory.classElement("C", elementB.type, []) as ClassElementImpl);
1067 ClassElementImpl elementD = (ElementFactory.classElement("D", elementB.type, []) as ClassElementImpl);
1068 InterfaceType typeB = elementB.type;
1069 InterfaceType typeC = elementC.type;
1070 InterfaceType typeD = elementD.type;
1071 JUnitTestCase.assertEquals(typeB, typeC.getLeastUpperBound(typeD));
1072 JUnitTestCase.assertEquals(typeB, typeD.getLeastUpperBound(typeC));
1073 }
1074 void test_getLeastUpperBound_sharedSuperclass4() {
1075 ClassElement elementA = ElementFactory.classElement2("A", []);
1076 ClassElement elementA2 = ElementFactory.classElement2("A2", []);
1077 ClassElement elementA3 = ElementFactory.classElement2("A3", []);
1078 ClassElementImpl elementB = (ElementFactory.classElement("B", elementA.type, []) as ClassElementImpl);
1079 ClassElementImpl elementC = (ElementFactory.classElement("C", elementA.type, []) as ClassElementImpl);
1080 InterfaceType typeA = elementA.type;
1081 InterfaceType typeA2 = elementA2.type;
1082 InterfaceType typeA3 = elementA3.type;
1083 InterfaceType typeB = elementB.type;
1084 InterfaceType typeC = elementC.type;
1085 elementB.interfaces = <InterfaceType> [typeA2];
1086 elementC.interfaces = <InterfaceType> [typeA3];
1087 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeC));
1088 JUnitTestCase.assertEquals(typeA, typeC.getLeastUpperBound(typeB));
1089 }
1090 void test_getLeastUpperBound_sharedSuperinterface1() {
1091 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1092 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
1093 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1094 InterfaceType typeA = elementA.type;
1095 InterfaceType typeB = elementB.type;
1096 InterfaceType typeC = elementC.type;
1097 elementB.interfaces = <InterfaceType> [typeA];
1098 elementC.interfaces = <InterfaceType> [typeA];
1099 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeC));
1100 JUnitTestCase.assertEquals(typeA, typeC.getLeastUpperBound(typeB));
1101 }
1102 void test_getLeastUpperBound_sharedSuperinterface2() {
1103 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1104 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
1105 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1106 ClassElementImpl elementD = (ElementFactory.classElement2("D", []) as ClassE lementImpl);
1107 InterfaceType typeA = elementA.type;
1108 InterfaceType typeB = elementB.type;
1109 InterfaceType typeC = elementC.type;
1110 InterfaceType typeD = elementD.type;
1111 elementB.interfaces = <InterfaceType> [typeA];
1112 elementC.interfaces = <InterfaceType> [typeA];
1113 elementD.interfaces = <InterfaceType> [typeC];
1114 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeD));
1115 JUnitTestCase.assertEquals(typeA, typeD.getLeastUpperBound(typeB));
1116 }
1117 void test_getLeastUpperBound_sharedSuperinterface3() {
1118 ClassElementImpl elementA = (ElementFactory.classElement2("A", []) as ClassE lementImpl);
1119 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
1120 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1121 ClassElementImpl elementD = (ElementFactory.classElement2("D", []) as ClassE lementImpl);
1122 InterfaceType typeA = elementA.type;
1123 InterfaceType typeB = elementB.type;
1124 InterfaceType typeC = elementC.type;
1125 InterfaceType typeD = elementD.type;
1126 elementB.interfaces = <InterfaceType> [typeA];
1127 elementC.interfaces = <InterfaceType> [typeB];
1128 elementD.interfaces = <InterfaceType> [typeB];
1129 JUnitTestCase.assertEquals(typeB, typeC.getLeastUpperBound(typeD));
1130 JUnitTestCase.assertEquals(typeB, typeD.getLeastUpperBound(typeC));
1131 }
1132 void test_getLeastUpperBound_sharedSuperinterface4() {
1133 ClassElement elementA = ElementFactory.classElement2("A", []);
1134 ClassElement elementA2 = ElementFactory.classElement2("A2", []);
1135 ClassElement elementA3 = ElementFactory.classElement2("A3", []);
1136 ClassElementImpl elementB = (ElementFactory.classElement2("B", []) as ClassE lementImpl);
1137 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1138 InterfaceType typeA = elementA.type;
1139 InterfaceType typeA2 = elementA2.type;
1140 InterfaceType typeA3 = elementA3.type;
1141 InterfaceType typeB = elementB.type;
1142 InterfaceType typeC = elementC.type;
1143 elementB.interfaces = <InterfaceType> [typeA, typeA2];
1144 elementC.interfaces = <InterfaceType> [typeA, typeA3];
1145 JUnitTestCase.assertEquals(typeA, typeB.getLeastUpperBound(typeC));
1146 JUnitTestCase.assertEquals(typeA, typeC.getLeastUpperBound(typeB));
1147 }
1148 void test_getTypeArguments() {
1149 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(new ClassElementImpl(AST Factory.identifier2("A")));
1150 EngineTestCase.assertLength(0, type.typeArguments);
1151 }
1152 void test_isDirectSupertypeOf_extends() {
1153 ClassElement elementA = ElementFactory.classElement2("A", []);
1154 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1155 InterfaceTypeImpl typeA = new InterfaceTypeImpl.con1(elementA);
1156 InterfaceTypeImpl typeB = new InterfaceTypeImpl.con1(elementB);
1157 JUnitTestCase.assertTrue(typeA.isDirectSupertypeOf(typeB));
1158 }
1159 void test_isDirectSupertypeOf_false() {
1160 ClassElement elementA = ElementFactory.classElement2("A", []);
1161 ClassElement elementB = ElementFactory.classElement2("B", []);
1162 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
1163 InterfaceTypeImpl typeA = new InterfaceTypeImpl.con1(elementA);
1164 InterfaceTypeImpl typeC = new InterfaceTypeImpl.con1(elementC);
1165 JUnitTestCase.assertFalse(typeA.isDirectSupertypeOf(typeC));
1166 }
1167 void test_isDirectSupertypeOf_implements() {
1168 ClassElement elementA = ElementFactory.classElement2("A", []);
1169 ClassElement elementB = ElementFactory.classElement2("B", []);
1170 ((elementB as ClassElementImpl)).interfaces = <InterfaceType> [elementA.type ];
1171 InterfaceTypeImpl typeA = new InterfaceTypeImpl.con1(elementA);
1172 InterfaceTypeImpl typeB = new InterfaceTypeImpl.con1(elementB);
1173 JUnitTestCase.assertTrue(typeA.isDirectSupertypeOf(typeB));
1174 }
1175 void test_isDirectSupertypeOf_with() {
1176 ClassElement elementA = ElementFactory.classElement2("A", []);
1177 ClassElement elementB = ElementFactory.classElement2("B", []);
1178 ((elementB as ClassElementImpl)).mixins = <InterfaceType> [elementA.type];
1179 InterfaceTypeImpl typeA = new InterfaceTypeImpl.con1(elementA);
1180 InterfaceTypeImpl typeB = new InterfaceTypeImpl.con1(elementB);
1181 JUnitTestCase.assertTrue(typeA.isDirectSupertypeOf(typeB));
1182 }
1183 void test_isMoreSpecificThan_bottom() {
1184 Type2 type19 = ElementFactory.classElement2("A", []).type;
1185 JUnitTestCase.assertTrue(BottomTypeImpl.instance.isMoreSpecificThan(type19)) ;
1186 }
1187 void test_isMoreSpecificThan_covariance() {
1188 ClassElement elementA = ElementFactory.classElement2("A", ["E"]);
1189 ClassElement elementI = ElementFactory.classElement2("I", []);
1190 ClassElement elementJ = ElementFactory.classElement("J", elementI.type, []);
1191 InterfaceTypeImpl typeAI = new InterfaceTypeImpl.con1(elementA);
1192 InterfaceTypeImpl typeAJ = new InterfaceTypeImpl.con1(elementA);
1193 typeAI.typeArguments = <Type2> [elementI.type];
1194 typeAJ.typeArguments = <Type2> [elementJ.type];
1195 JUnitTestCase.assertTrue(typeAJ.isMoreSpecificThan(typeAI));
1196 JUnitTestCase.assertFalse(typeAI.isMoreSpecificThan(typeAJ));
1197 }
1198 void test_isMoreSpecificThan_directSupertype() {
1199 ClassElement elementA = ElementFactory.classElement2("A", []);
1200 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1201 InterfaceType typeA = elementA.type;
1202 InterfaceType typeB = elementB.type;
1203 JUnitTestCase.assertTrue(typeB.isMoreSpecificThan(typeA));
1204 JUnitTestCase.assertFalse(typeA.isMoreSpecificThan(typeB));
1205 }
1206 void test_isMoreSpecificThan_dynamic() {
1207 InterfaceType type20 = ElementFactory.classElement2("A", []).type;
1208 JUnitTestCase.assertTrue(type20.isMoreSpecificThan(DynamicTypeImpl.instance) );
1209 }
1210 void test_isMoreSpecificThan_indirectSupertype() {
1211 ClassElement elementA = ElementFactory.classElement2("A", []);
1212 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1213 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
1214 InterfaceType typeA = elementA.type;
1215 InterfaceType typeC = elementC.type;
1216 JUnitTestCase.assertTrue(typeC.isMoreSpecificThan(typeA));
1217 }
1218 void test_isMoreSpecificThan_self() {
1219 InterfaceType type21 = ElementFactory.classElement2("A", []).type;
1220 JUnitTestCase.assertTrue(type21.isMoreSpecificThan(type21));
1221 }
1222 void test_isSubtypeOf_directSubtype() {
1223 ClassElement elementA = ElementFactory.classElement2("A", []);
1224 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1225 InterfaceType typeA = elementA.type;
1226 InterfaceType typeB = elementB.type;
1227 JUnitTestCase.assertTrue(typeB.isSubtypeOf(typeA));
1228 JUnitTestCase.assertFalse(typeA.isSubtypeOf(typeB));
1229 }
1230 void test_isSubtypeOf_dynamic() {
1231 ClassElement elementA = ElementFactory.classElement2("A", []);
1232 InterfaceType typeA = elementA.type;
1233 Type2 dynamicType = DynamicTypeImpl.instance;
1234 JUnitTestCase.assertFalse(dynamicType.isSubtypeOf(typeA));
1235 JUnitTestCase.assertTrue(typeA.isSubtypeOf(dynamicType));
1236 }
1237 void test_isSubtypeOf_indirectSubtype() {
1238 ClassElement elementA = ElementFactory.classElement2("A", []);
1239 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1240 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
1241 InterfaceType typeA = elementA.type;
1242 InterfaceType typeC = elementC.type;
1243 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeA));
1244 JUnitTestCase.assertFalse(typeA.isSubtypeOf(typeC));
1245 }
1246 void test_isSubtypeOf_interface() {
1247 ClassElement elementA = ElementFactory.classElement2("A", []);
1248 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1249 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1250 InterfaceType typeObject = elementA.supertype;
1251 InterfaceType typeA = elementA.type;
1252 InterfaceType typeB = elementB.type;
1253 InterfaceType typeC = elementC.type;
1254 elementC.interfaces = <InterfaceType> [typeB];
1255 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeB));
1256 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeObject));
1257 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeA));
1258 JUnitTestCase.assertFalse(typeA.isSubtypeOf(typeC));
1259 }
1260 void test_isSubtypeOf_mixins() {
1261 ClassElement elementA = ElementFactory.classElement2("A", []);
1262 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1263 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1264 InterfaceType typeObject = elementA.supertype;
1265 InterfaceType typeA = elementA.type;
1266 InterfaceType typeB = elementB.type;
1267 InterfaceType typeC = elementC.type;
1268 elementC.mixins = <InterfaceType> [typeB];
1269 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeB));
1270 JUnitTestCase.assertTrue(typeC.isSubtypeOf(typeObject));
1271 JUnitTestCase.assertFalse(typeC.isSubtypeOf(typeA));
1272 JUnitTestCase.assertFalse(typeA.isSubtypeOf(typeC));
1273 }
1274 void test_isSubtypeOf_object() {
1275 ClassElement elementA = ElementFactory.classElement2("A", []);
1276 InterfaceType typeA = elementA.type;
1277 InterfaceType typeObject = elementA.supertype;
1278 JUnitTestCase.assertTrue(typeA.isSubtypeOf(typeObject));
1279 JUnitTestCase.assertFalse(typeObject.isSubtypeOf(typeA));
1280 }
1281 void test_isSubtypeOf_self() {
1282 ClassElement elementA = ElementFactory.classElement2("A", []);
1283 InterfaceType typeA = elementA.type;
1284 JUnitTestCase.assertTrue(typeA.isSubtypeOf(typeA));
1285 }
1286 void test_isSubtypeOf_typeArguments() {
1287 ClassElement elementA = ElementFactory.classElement2("A", ["E"]);
1288 ClassElement elementI = ElementFactory.classElement2("I", []);
1289 ClassElement elementJ = ElementFactory.classElement("J", elementI.type, []);
1290 ClassElement elementK = ElementFactory.classElement2("K", []);
1291 InterfaceType typeA = elementA.type;
1292 InterfaceTypeImpl typeAI = new InterfaceTypeImpl.con1(elementA);
1293 InterfaceTypeImpl typeAJ = new InterfaceTypeImpl.con1(elementA);
1294 InterfaceTypeImpl typeAK = new InterfaceTypeImpl.con1(elementA);
1295 typeAI.typeArguments = <Type2> [elementI.type];
1296 typeAJ.typeArguments = <Type2> [elementJ.type];
1297 typeAK.typeArguments = <Type2> [elementK.type];
1298 JUnitTestCase.assertTrue(typeAJ.isSubtypeOf(typeAI));
1299 JUnitTestCase.assertFalse(typeAI.isSubtypeOf(typeAJ));
1300 JUnitTestCase.assertTrue(typeAI.isSubtypeOf(typeAI));
1301 JUnitTestCase.assertTrue(typeA.isSubtypeOf(typeAI));
1302 JUnitTestCase.assertTrue(typeA.isSubtypeOf(typeAJ));
1303 JUnitTestCase.assertTrue(typeAI.isSubtypeOf(typeA));
1304 JUnitTestCase.assertTrue(typeAJ.isSubtypeOf(typeA));
1305 JUnitTestCase.assertFalse(typeAI.isSubtypeOf(typeAK));
1306 JUnitTestCase.assertFalse(typeAK.isSubtypeOf(typeAI));
1307 }
1308 void test_isSupertypeOf_directSupertype() {
1309 ClassElement elementA = ElementFactory.classElement2("A", []);
1310 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1311 InterfaceType typeA = elementA.type;
1312 InterfaceType typeB = elementB.type;
1313 JUnitTestCase.assertFalse(typeB.isSupertypeOf(typeA));
1314 JUnitTestCase.assertTrue(typeA.isSupertypeOf(typeB));
1315 }
1316 void test_isSupertypeOf_dynamic() {
1317 ClassElement elementA = ElementFactory.classElement2("A", []);
1318 InterfaceType typeA = elementA.type;
1319 Type2 dynamicType = DynamicTypeImpl.instance;
1320 JUnitTestCase.assertTrue(dynamicType.isSupertypeOf(typeA));
1321 JUnitTestCase.assertFalse(typeA.isSupertypeOf(dynamicType));
1322 }
1323 void test_isSupertypeOf_indirectSupertype() {
1324 ClassElement elementA = ElementFactory.classElement2("A", []);
1325 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1326 ClassElement elementC = ElementFactory.classElement("C", elementB.type, []);
1327 InterfaceType typeA = elementA.type;
1328 InterfaceType typeC = elementC.type;
1329 JUnitTestCase.assertFalse(typeC.isSupertypeOf(typeA));
1330 JUnitTestCase.assertTrue(typeA.isSupertypeOf(typeC));
1331 }
1332 void test_isSupertypeOf_interface() {
1333 ClassElement elementA = ElementFactory.classElement2("A", []);
1334 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1335 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1336 InterfaceType typeObject = elementA.supertype;
1337 InterfaceType typeA = elementA.type;
1338 InterfaceType typeB = elementB.type;
1339 InterfaceType typeC = elementC.type;
1340 elementC.interfaces = <InterfaceType> [typeB];
1341 JUnitTestCase.assertTrue(typeB.isSupertypeOf(typeC));
1342 JUnitTestCase.assertTrue(typeObject.isSupertypeOf(typeC));
1343 JUnitTestCase.assertTrue(typeA.isSupertypeOf(typeC));
1344 JUnitTestCase.assertFalse(typeC.isSupertypeOf(typeA));
1345 }
1346 void test_isSupertypeOf_mixins() {
1347 ClassElement elementA = ElementFactory.classElement2("A", []);
1348 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1349 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1350 InterfaceType typeObject = elementA.supertype;
1351 InterfaceType typeA = elementA.type;
1352 InterfaceType typeB = elementB.type;
1353 InterfaceType typeC = elementC.type;
1354 elementC.mixins = <InterfaceType> [typeB];
1355 JUnitTestCase.assertTrue(typeB.isSupertypeOf(typeC));
1356 JUnitTestCase.assertTrue(typeObject.isSupertypeOf(typeC));
1357 JUnitTestCase.assertFalse(typeA.isSupertypeOf(typeC));
1358 JUnitTestCase.assertFalse(typeC.isSupertypeOf(typeA));
1359 }
1360 void test_isSupertypeOf_object() {
1361 ClassElement elementA = ElementFactory.classElement2("A", []);
1362 InterfaceType typeA = elementA.type;
1363 InterfaceType typeObject = elementA.supertype;
1364 JUnitTestCase.assertFalse(typeA.isSupertypeOf(typeObject));
1365 JUnitTestCase.assertTrue(typeObject.isSupertypeOf(typeA));
1366 }
1367 void test_isSupertypeOf_self() {
1368 ClassElement elementA = ElementFactory.classElement2("A", []);
1369 InterfaceType typeA = elementA.type;
1370 JUnitTestCase.assertTrue(typeA.isSupertypeOf(typeA));
1371 }
1372 void test_setTypeArguments() {
1373 InterfaceTypeImpl type22 = (ElementFactory.classElement2("A", []).type as In terfaceTypeImpl);
1374 List<Type2> typeArguments = <Type2> [new InterfaceTypeImpl.con1(ElementFacto ry.classElement2("B", [])), new InterfaceTypeImpl.con1(ElementFactory.classEleme nt2("C", []))];
1375 type22.typeArguments = typeArguments;
1376 JUnitTestCase.assertEquals(typeArguments, type22.typeArguments);
1377 }
1378 void test_substitute_equal() {
1379 ClassElementImpl classElement = new ClassElementImpl(ASTFactory.identifier2( "A"));
1380 TypeVariableElementImpl parameterElement = new TypeVariableElementImpl(ASTFa ctory.identifier2("E"));
1381 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classElement);
1382 TypeVariableTypeImpl parameter = new TypeVariableTypeImpl(parameterElement);
1383 type.typeArguments = <Type2> [parameter];
1384 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(ASTFactory.identifier2("B")));
1385 InterfaceType result = type.substitute2(<Type2> [argumentType], <Type2> [par ameter]);
1386 JUnitTestCase.assertEquals(classElement, result.element);
1387 List<Type2> resultArguments = result.typeArguments;
1388 EngineTestCase.assertLength(1, resultArguments);
1389 JUnitTestCase.assertEquals(argumentType, resultArguments[0]);
1390 }
1391 void test_substitute_notEqual() {
1392 ClassElementImpl classElement = new ClassElementImpl(ASTFactory.identifier2( "A"));
1393 TypeVariableElementImpl parameterElement = new TypeVariableElementImpl(ASTFa ctory.identifier2("E"));
1394 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(classElement);
1395 TypeVariableTypeImpl parameter = new TypeVariableTypeImpl(parameterElement);
1396 type.typeArguments = <Type2> [parameter];
1397 InterfaceTypeImpl argumentType = new InterfaceTypeImpl.con1(new ClassElement Impl(ASTFactory.identifier2("B")));
1398 TypeVariableTypeImpl parameterType = new TypeVariableTypeImpl(new TypeVariab leElementImpl(ASTFactory.identifier2("F")));
1399 InterfaceType result = type.substitute2(<Type2> [argumentType], <Type2> [par ameterType]);
1400 JUnitTestCase.assertEquals(classElement, result.element);
1401 List<Type2> resultArguments = result.typeArguments;
1402 EngineTestCase.assertLength(1, resultArguments);
1403 JUnitTestCase.assertEquals(parameter, resultArguments[0]);
1404 }
1405 static dartSuite() {
1406 _ut.group('InterfaceTypeImplTest', () {
1407 _ut.test('test_computeLongestInheritancePathToObject_multipleInterfacePath s', () {
1408 final __test = new InterfaceTypeImplTest();
1409 runJUnitTest(__test, __test.test_computeLongestInheritancePathToObject_m ultipleInterfacePaths);
1410 });
1411 _ut.test('test_computeLongestInheritancePathToObject_multipleSuperclassPat hs', () {
1412 final __test = new InterfaceTypeImplTest();
1413 runJUnitTest(__test, __test.test_computeLongestInheritancePathToObject_m ultipleSuperclassPaths);
1414 });
1415 _ut.test('test_computeLongestInheritancePathToObject_object', () {
1416 final __test = new InterfaceTypeImplTest();
1417 runJUnitTest(__test, __test.test_computeLongestInheritancePathToObject_o bject);
1418 });
1419 _ut.test('test_computeLongestInheritancePathToObject_singleInterfacePath', () {
1420 final __test = new InterfaceTypeImplTest();
1421 runJUnitTest(__test, __test.test_computeLongestInheritancePathToObject_s ingleInterfacePath);
1422 });
1423 _ut.test('test_computeLongestInheritancePathToObject_singleSuperclassPath' , () {
1424 final __test = new InterfaceTypeImplTest();
1425 runJUnitTest(__test, __test.test_computeLongestInheritancePathToObject_s ingleSuperclassPath);
1426 });
1427 _ut.test('test_computeSuperinterfaceSet_multipleInterfacePaths', () {
1428 final __test = new InterfaceTypeImplTest();
1429 runJUnitTest(__test, __test.test_computeSuperinterfaceSet_multipleInterf acePaths);
1430 });
1431 _ut.test('test_computeSuperinterfaceSet_multipleSuperclassPaths', () {
1432 final __test = new InterfaceTypeImplTest();
1433 runJUnitTest(__test, __test.test_computeSuperinterfaceSet_multipleSuperc lassPaths);
1434 });
1435 _ut.test('test_computeSuperinterfaceSet_singleInterfacePath', () {
1436 final __test = new InterfaceTypeImplTest();
1437 runJUnitTest(__test, __test.test_computeSuperinterfaceSet_singleInterfac ePath);
1438 });
1439 _ut.test('test_computeSuperinterfaceSet_singleSuperclassPath', () {
1440 final __test = new InterfaceTypeImplTest();
1441 runJUnitTest(__test, __test.test_computeSuperinterfaceSet_singleSupercla ssPath);
1442 });
1443 _ut.test('test_creation', () {
1444 final __test = new InterfaceTypeImplTest();
1445 runJUnitTest(__test, __test.test_creation);
1446 });
1447 _ut.test('test_getElement', () {
1448 final __test = new InterfaceTypeImplTest();
1449 runJUnitTest(__test, __test.test_getElement);
1450 });
1451 _ut.test('test_getLeastUpperBound_directInterfaceCase', () {
1452 final __test = new InterfaceTypeImplTest();
1453 runJUnitTest(__test, __test.test_getLeastUpperBound_directInterfaceCase) ;
1454 });
1455 _ut.test('test_getLeastUpperBound_directSubclassCase', () {
1456 final __test = new InterfaceTypeImplTest();
1457 runJUnitTest(__test, __test.test_getLeastUpperBound_directSubclassCase);
1458 });
1459 _ut.test('test_getLeastUpperBound_functionType', () {
1460 final __test = new InterfaceTypeImplTest();
1461 runJUnitTest(__test, __test.test_getLeastUpperBound_functionType);
1462 });
1463 _ut.test('test_getLeastUpperBound_mixinCase', () {
1464 final __test = new InterfaceTypeImplTest();
1465 runJUnitTest(__test, __test.test_getLeastUpperBound_mixinCase);
1466 });
1467 _ut.test('test_getLeastUpperBound_null', () {
1468 final __test = new InterfaceTypeImplTest();
1469 runJUnitTest(__test, __test.test_getLeastUpperBound_null);
1470 });
1471 _ut.test('test_getLeastUpperBound_object', () {
1472 final __test = new InterfaceTypeImplTest();
1473 runJUnitTest(__test, __test.test_getLeastUpperBound_object);
1474 });
1475 _ut.test('test_getLeastUpperBound_self', () {
1476 final __test = new InterfaceTypeImplTest();
1477 runJUnitTest(__test, __test.test_getLeastUpperBound_self);
1478 });
1479 _ut.test('test_getLeastUpperBound_sharedSuperclass1', () {
1480 final __test = new InterfaceTypeImplTest();
1481 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperclass1);
1482 });
1483 _ut.test('test_getLeastUpperBound_sharedSuperclass2', () {
1484 final __test = new InterfaceTypeImplTest();
1485 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperclass2);
1486 });
1487 _ut.test('test_getLeastUpperBound_sharedSuperclass3', () {
1488 final __test = new InterfaceTypeImplTest();
1489 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperclass3);
1490 });
1491 _ut.test('test_getLeastUpperBound_sharedSuperclass4', () {
1492 final __test = new InterfaceTypeImplTest();
1493 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperclass4);
1494 });
1495 _ut.test('test_getLeastUpperBound_sharedSuperinterface1', () {
1496 final __test = new InterfaceTypeImplTest();
1497 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperinterface 1);
1498 });
1499 _ut.test('test_getLeastUpperBound_sharedSuperinterface2', () {
1500 final __test = new InterfaceTypeImplTest();
1501 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperinterface 2);
1502 });
1503 _ut.test('test_getLeastUpperBound_sharedSuperinterface3', () {
1504 final __test = new InterfaceTypeImplTest();
1505 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperinterface 3);
1506 });
1507 _ut.test('test_getLeastUpperBound_sharedSuperinterface4', () {
1508 final __test = new InterfaceTypeImplTest();
1509 runJUnitTest(__test, __test.test_getLeastUpperBound_sharedSuperinterface 4);
1510 });
1511 _ut.test('test_getTypeArguments', () {
1512 final __test = new InterfaceTypeImplTest();
1513 runJUnitTest(__test, __test.test_getTypeArguments);
1514 });
1515 _ut.test('test_isDirectSupertypeOf_extends', () {
1516 final __test = new InterfaceTypeImplTest();
1517 runJUnitTest(__test, __test.test_isDirectSupertypeOf_extends);
1518 });
1519 _ut.test('test_isDirectSupertypeOf_false', () {
1520 final __test = new InterfaceTypeImplTest();
1521 runJUnitTest(__test, __test.test_isDirectSupertypeOf_false);
1522 });
1523 _ut.test('test_isDirectSupertypeOf_implements', () {
1524 final __test = new InterfaceTypeImplTest();
1525 runJUnitTest(__test, __test.test_isDirectSupertypeOf_implements);
1526 });
1527 _ut.test('test_isDirectSupertypeOf_with', () {
1528 final __test = new InterfaceTypeImplTest();
1529 runJUnitTest(__test, __test.test_isDirectSupertypeOf_with);
1530 });
1531 _ut.test('test_isMoreSpecificThan_bottom', () {
1532 final __test = new InterfaceTypeImplTest();
1533 runJUnitTest(__test, __test.test_isMoreSpecificThan_bottom);
1534 });
1535 _ut.test('test_isMoreSpecificThan_covariance', () {
1536 final __test = new InterfaceTypeImplTest();
1537 runJUnitTest(__test, __test.test_isMoreSpecificThan_covariance);
1538 });
1539 _ut.test('test_isMoreSpecificThan_directSupertype', () {
1540 final __test = new InterfaceTypeImplTest();
1541 runJUnitTest(__test, __test.test_isMoreSpecificThan_directSupertype);
1542 });
1543 _ut.test('test_isMoreSpecificThan_dynamic', () {
1544 final __test = new InterfaceTypeImplTest();
1545 runJUnitTest(__test, __test.test_isMoreSpecificThan_dynamic);
1546 });
1547 _ut.test('test_isMoreSpecificThan_indirectSupertype', () {
1548 final __test = new InterfaceTypeImplTest();
1549 runJUnitTest(__test, __test.test_isMoreSpecificThan_indirectSupertype);
1550 });
1551 _ut.test('test_isMoreSpecificThan_self', () {
1552 final __test = new InterfaceTypeImplTest();
1553 runJUnitTest(__test, __test.test_isMoreSpecificThan_self);
1554 });
1555 _ut.test('test_isSubtypeOf_directSubtype', () {
1556 final __test = new InterfaceTypeImplTest();
1557 runJUnitTest(__test, __test.test_isSubtypeOf_directSubtype);
1558 });
1559 _ut.test('test_isSubtypeOf_dynamic', () {
1560 final __test = new InterfaceTypeImplTest();
1561 runJUnitTest(__test, __test.test_isSubtypeOf_dynamic);
1562 });
1563 _ut.test('test_isSubtypeOf_indirectSubtype', () {
1564 final __test = new InterfaceTypeImplTest();
1565 runJUnitTest(__test, __test.test_isSubtypeOf_indirectSubtype);
1566 });
1567 _ut.test('test_isSubtypeOf_interface', () {
1568 final __test = new InterfaceTypeImplTest();
1569 runJUnitTest(__test, __test.test_isSubtypeOf_interface);
1570 });
1571 _ut.test('test_isSubtypeOf_mixins', () {
1572 final __test = new InterfaceTypeImplTest();
1573 runJUnitTest(__test, __test.test_isSubtypeOf_mixins);
1574 });
1575 _ut.test('test_isSubtypeOf_object', () {
1576 final __test = new InterfaceTypeImplTest();
1577 runJUnitTest(__test, __test.test_isSubtypeOf_object);
1578 });
1579 _ut.test('test_isSubtypeOf_self', () {
1580 final __test = new InterfaceTypeImplTest();
1581 runJUnitTest(__test, __test.test_isSubtypeOf_self);
1582 });
1583 _ut.test('test_isSubtypeOf_typeArguments', () {
1584 final __test = new InterfaceTypeImplTest();
1585 runJUnitTest(__test, __test.test_isSubtypeOf_typeArguments);
1586 });
1587 _ut.test('test_isSupertypeOf_directSupertype', () {
1588 final __test = new InterfaceTypeImplTest();
1589 runJUnitTest(__test, __test.test_isSupertypeOf_directSupertype);
1590 });
1591 _ut.test('test_isSupertypeOf_dynamic', () {
1592 final __test = new InterfaceTypeImplTest();
1593 runJUnitTest(__test, __test.test_isSupertypeOf_dynamic);
1594 });
1595 _ut.test('test_isSupertypeOf_indirectSupertype', () {
1596 final __test = new InterfaceTypeImplTest();
1597 runJUnitTest(__test, __test.test_isSupertypeOf_indirectSupertype);
1598 });
1599 _ut.test('test_isSupertypeOf_interface', () {
1600 final __test = new InterfaceTypeImplTest();
1601 runJUnitTest(__test, __test.test_isSupertypeOf_interface);
1602 });
1603 _ut.test('test_isSupertypeOf_mixins', () {
1604 final __test = new InterfaceTypeImplTest();
1605 runJUnitTest(__test, __test.test_isSupertypeOf_mixins);
1606 });
1607 _ut.test('test_isSupertypeOf_object', () {
1608 final __test = new InterfaceTypeImplTest();
1609 runJUnitTest(__test, __test.test_isSupertypeOf_object);
1610 });
1611 _ut.test('test_isSupertypeOf_self', () {
1612 final __test = new InterfaceTypeImplTest();
1613 runJUnitTest(__test, __test.test_isSupertypeOf_self);
1614 });
1615 _ut.test('test_setTypeArguments', () {
1616 final __test = new InterfaceTypeImplTest();
1617 runJUnitTest(__test, __test.test_setTypeArguments);
1618 });
1619 _ut.test('test_substitute_equal', () {
1620 final __test = new InterfaceTypeImplTest();
1621 runJUnitTest(__test, __test.test_substitute_equal);
1622 });
1623 _ut.test('test_substitute_notEqual', () {
1624 final __test = new InterfaceTypeImplTest();
1625 runJUnitTest(__test, __test.test_substitute_notEqual);
1626 });
1627 });
1628 }
1629 }
1630 class ClassElementImplTest extends EngineTestCase {
1631 void test_allSupertypes_interface() {
1632 ClassElement elementA = ElementFactory.classElement2("A", []);
1633 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1634 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1635 InterfaceType typeObject = elementA.supertype;
1636 InterfaceType typeA = elementA.type;
1637 InterfaceType typeB = elementB.type;
1638 InterfaceType typeC = elementC.type;
1639 elementC.interfaces = <InterfaceType> [typeB];
1640 List<InterfaceType> supers = elementC.allSupertypes;
1641 List<InterfaceType> types = new List<InterfaceType>();
1642 types.addAll(supers);
1643 JUnitTestCase.assertTrue(types.contains(typeA));
1644 JUnitTestCase.assertTrue(types.contains(typeB));
1645 JUnitTestCase.assertTrue(types.contains(typeObject));
1646 JUnitTestCase.assertFalse(types.contains(typeC));
1647 }
1648 void test_allSupertypes_mixins() {
1649 ClassElement elementA = ElementFactory.classElement2("A", []);
1650 ClassElement elementB = ElementFactory.classElement("B", elementA.type, []);
1651 ClassElementImpl elementC = (ElementFactory.classElement2("C", []) as ClassE lementImpl);
1652 InterfaceType typeObject = elementA.supertype;
1653 InterfaceType typeA = elementA.type;
1654 InterfaceType typeB = elementB.type;
1655 InterfaceType typeC = elementC.type;
1656 elementC.mixins = <InterfaceType> [typeB];
1657 List<InterfaceType> supers = elementC.allSupertypes;
1658 List<InterfaceType> types = new List<InterfaceType>();
1659 types.addAll(supers);
1660 JUnitTestCase.assertFalse(types.contains(typeA));
1661 JUnitTestCase.assertTrue(types.contains(typeB));
1662 JUnitTestCase.assertTrue(types.contains(typeObject));
1663 JUnitTestCase.assertFalse(types.contains(typeC));
1664 }
1665 void test_lookUpGetter_declared() {
1666 LibraryElementImpl library6 = ElementFactory.library(new AnalysisContextImpl (), "lib");
1667 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1668 String getterName = "g";
1669 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, null);
1670 classA.accessors = <PropertyAccessorElement> [getter];
1671 ((library6.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classA];
1672 JUnitTestCase.assertSame(getter, classA.lookUpGetter(getterName, library6));
1673 }
1674 void test_lookUpGetter_inherited() {
1675 LibraryElementImpl library7 = ElementFactory.library(new AnalysisContextImpl (), "lib");
1676 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1677 String getterName = "g";
1678 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, null);
1679 classA.accessors = <PropertyAccessorElement> [getter];
1680 ClassElementImpl classB = (ElementFactory.classElement("B", classA.type, []) as ClassElementImpl);
1681 ((library7.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classA, classB];
1682 JUnitTestCase.assertSame(getter, classB.lookUpGetter(getterName, library7));
1683 }
1684 void test_lookUpGetter_undeclared() {
1685 LibraryElementImpl library8 = ElementFactory.library(new AnalysisContextImpl (), "lib");
1686 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1687 ((library8.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classA];
1688 JUnitTestCase.assertNull(classA.lookUpGetter("g", library8));
1689 }
1690 void test_lookUpMethod_declared() {
1691 LibraryElementImpl library9 = ElementFactory.library(new AnalysisContextImpl (), "lib");
1692 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1693 String methodName = "m";
1694 MethodElement method = ElementFactory.methodElement(methodName, null, []);
1695 classA.methods = <MethodElement> [method];
1696 ((library9.definingCompilationUnit as CompilationUnitElementImpl)).types = < ClassElement> [classA];
1697 JUnitTestCase.assertSame(method, classA.lookUpMethod(methodName, library9));
1698 }
1699 void test_lookUpMethod_inherited() {
1700 LibraryElementImpl library10 = ElementFactory.library(new AnalysisContextImp l(), "lib");
1701 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1702 String methodName = "m";
1703 MethodElement method = ElementFactory.methodElement(methodName, null, []);
1704 classA.methods = <MethodElement> [method];
1705 ClassElementImpl classB = (ElementFactory.classElement("B", classA.type, []) as ClassElementImpl);
1706 ((library10.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classA, classB];
1707 JUnitTestCase.assertSame(method, classB.lookUpMethod(methodName, library10)) ;
1708 }
1709 void test_lookUpMethod_undeclared() {
1710 LibraryElementImpl library11 = ElementFactory.library(new AnalysisContextImp l(), "lib");
1711 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1712 ((library11.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classA];
1713 JUnitTestCase.assertNull(classA.lookUpMethod("m", library11));
1714 }
1715 void test_lookUpSetter_declared() {
1716 LibraryElementImpl library12 = ElementFactory.library(new AnalysisContextImp l(), "lib");
1717 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1718 String setterName = "s";
1719 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa lse, null);
1720 classA.accessors = <PropertyAccessorElement> [setter];
1721 ((library12.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classA];
1722 JUnitTestCase.assertSame(setter, classA.lookUpSetter(setterName, library12)) ;
1723 }
1724 void test_lookUpSetter_inherited() {
1725 LibraryElementImpl library13 = ElementFactory.library(new AnalysisContextImp l(), "lib");
1726 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1727 String setterName = "s";
1728 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa lse, null);
1729 classA.accessors = <PropertyAccessorElement> [setter];
1730 ClassElementImpl classB = (ElementFactory.classElement("B", classA.type, []) as ClassElementImpl);
1731 ((library13.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classA, classB];
1732 JUnitTestCase.assertSame(setter, classB.lookUpSetter(setterName, library13)) ;
1733 }
1734 void test_lookUpSetter_undeclared() {
1735 LibraryElementImpl library14 = ElementFactory.library(new AnalysisContextImp l(), "lib");
1736 ClassElementImpl classA = (ElementFactory.classElement2("A", []) as ClassEle mentImpl);
1737 ((library14.definingCompilationUnit as CompilationUnitElementImpl)).types = <ClassElement> [classA];
1738 JUnitTestCase.assertNull(classA.lookUpSetter("s", library14));
1739 }
1740 static dartSuite() {
1741 _ut.group('ClassElementImplTest', () {
1742 _ut.test('test_allSupertypes_interface', () {
1743 final __test = new ClassElementImplTest();
1744 runJUnitTest(__test, __test.test_allSupertypes_interface);
1745 });
1746 _ut.test('test_allSupertypes_mixins', () {
1747 final __test = new ClassElementImplTest();
1748 runJUnitTest(__test, __test.test_allSupertypes_mixins);
1749 });
1750 _ut.test('test_lookUpGetter_declared', () {
1751 final __test = new ClassElementImplTest();
1752 runJUnitTest(__test, __test.test_lookUpGetter_declared);
1753 });
1754 _ut.test('test_lookUpGetter_inherited', () {
1755 final __test = new ClassElementImplTest();
1756 runJUnitTest(__test, __test.test_lookUpGetter_inherited);
1757 });
1758 _ut.test('test_lookUpGetter_undeclared', () {
1759 final __test = new ClassElementImplTest();
1760 runJUnitTest(__test, __test.test_lookUpGetter_undeclared);
1761 });
1762 _ut.test('test_lookUpMethod_declared', () {
1763 final __test = new ClassElementImplTest();
1764 runJUnitTest(__test, __test.test_lookUpMethod_declared);
1765 });
1766 _ut.test('test_lookUpMethod_inherited', () {
1767 final __test = new ClassElementImplTest();
1768 runJUnitTest(__test, __test.test_lookUpMethod_inherited);
1769 });
1770 _ut.test('test_lookUpMethod_undeclared', () {
1771 final __test = new ClassElementImplTest();
1772 runJUnitTest(__test, __test.test_lookUpMethod_undeclared);
1773 });
1774 _ut.test('test_lookUpSetter_declared', () {
1775 final __test = new ClassElementImplTest();
1776 runJUnitTest(__test, __test.test_lookUpSetter_declared);
1777 });
1778 _ut.test('test_lookUpSetter_inherited', () {
1779 final __test = new ClassElementImplTest();
1780 runJUnitTest(__test, __test.test_lookUpSetter_inherited);
1781 });
1782 _ut.test('test_lookUpSetter_undeclared', () {
1783 final __test = new ClassElementImplTest();
1784 runJUnitTest(__test, __test.test_lookUpSetter_undeclared);
1785 });
1786 });
1787 }
1788 }
1789 class TypeVariableTypeImplTest extends EngineTestCase {
1790 void test_creation() {
1791 JUnitTestCase.assertNotNull(new TypeVariableTypeImpl(new TypeVariableElement Impl(ASTFactory.identifier2("E"))));
1792 }
1793 void test_getElement() {
1794 TypeVariableElementImpl element = new TypeVariableElementImpl(ASTFactory.ide ntifier2("E"));
1795 TypeVariableTypeImpl type = new TypeVariableTypeImpl(element);
1796 JUnitTestCase.assertEquals(element, type.element);
1797 }
1798 void test_substitute_equal() {
1799 TypeVariableElementImpl element = new TypeVariableElementImpl(ASTFactory.ide ntifier2("E"));
1800 TypeVariableTypeImpl type = new TypeVariableTypeImpl(element);
1801 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl (ASTFactory.identifier2("A")));
1802 TypeVariableTypeImpl parameter = new TypeVariableTypeImpl(element);
1803 JUnitTestCase.assertSame(argument, type.substitute2(<Type2> [argument], <Typ e2> [parameter]));
1804 }
1805 void test_substitute_notEqual() {
1806 TypeVariableTypeImpl type = new TypeVariableTypeImpl(new TypeVariableElement Impl(ASTFactory.identifier2("E")));
1807 InterfaceTypeImpl argument = new InterfaceTypeImpl.con1(new ClassElementImpl (ASTFactory.identifier2("A")));
1808 TypeVariableTypeImpl parameter = new TypeVariableTypeImpl(new TypeVariableEl ementImpl(ASTFactory.identifier2("F")));
1809 JUnitTestCase.assertSame(type, type.substitute2(<Type2> [argument], <Type2> [parameter]));
1810 }
1811 static dartSuite() {
1812 _ut.group('TypeVariableTypeImplTest', () {
1813 _ut.test('test_creation', () {
1814 final __test = new TypeVariableTypeImplTest();
1815 runJUnitTest(__test, __test.test_creation);
1816 });
1817 _ut.test('test_getElement', () {
1818 final __test = new TypeVariableTypeImplTest();
1819 runJUnitTest(__test, __test.test_getElement);
1820 });
1821 _ut.test('test_substitute_equal', () {
1822 final __test = new TypeVariableTypeImplTest();
1823 runJUnitTest(__test, __test.test_substitute_equal);
1824 });
1825 _ut.test('test_substitute_notEqual', () {
1826 final __test = new TypeVariableTypeImplTest();
1827 runJUnitTest(__test, __test.test_substitute_notEqual);
1828 });
1829 });
1830 }
1831 }
1832 main() {
1833 ClassElementImplTest.dartSuite();
1834 ElementLocationImplTest.dartSuite();
1835 ElementImplTest.dartSuite();
1836 LibraryElementImplTest.dartSuite();
1837 FunctionTypeImplTest.dartSuite();
1838 InterfaceTypeImplTest.dartSuite();
1839 TypeVariableTypeImplTest.dartSuite();
1840 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698