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

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

Issue 12838003: Rename analyzer-experimental to analyzer_experimental. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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.resolver_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_io.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/element.dart';
14 import 'package:analyzer-experimental/src/generated/resolver.dart';
15 import 'package:analyzer-experimental/src/generated/engine.dart';
16 import 'package:analyzer-experimental/src/generated/java_engine_io.dart';
17 import 'package:analyzer-experimental/src/generated/ast.dart' hide Annotation;
18 import 'package:analyzer-experimental/src/generated/sdk.dart' show DartSdk;
19 import 'package:unittest/unittest.dart' as _ut;
20 import 'test_support.dart';
21 import 'ast_test.dart' show ASTFactory;
22 import 'element_test.dart' show ElementFactory;
23
24 class LibraryTest extends EngineTestCase {
25 /**
26 * The error listener to which all errors will be reported.
27 */
28 GatheringErrorListener _errorListener;
29 /**
30 * The source factory used to create libraries.
31 */
32 SourceFactory _sourceFactory;
33 /**
34 * The analysis context to pass in to all libraries created by the tests.
35 */
36 AnalysisContextImpl _analysisContext;
37 /**
38 * The library used by the tests.
39 */
40 Library _library5;
41 void setUp() {
42 _sourceFactory = new SourceFactory.con2([new FileUriResolver()]);
43 _analysisContext = new AnalysisContextImpl();
44 _analysisContext.sourceFactory = _sourceFactory;
45 _errorListener = new GatheringErrorListener();
46 _library5 = library("/lib.dart");
47 }
48 void test_addExport() {
49 Library exportLibrary = library("/exported.dart");
50 _library5.addExport(ASTFactory.exportDirective2("exported.dart", []), export Library);
51 List<Library> exports3 = _library5.exports;
52 EngineTestCase.assertLength(1, exports3);
53 JUnitTestCase.assertSame(exportLibrary, exports3[0]);
54 _errorListener.assertNoErrors();
55 }
56 void test_addImport() {
57 Library importLibrary = library("/imported.dart");
58 _library5.addImport(ASTFactory.importDirective2("imported.dart", null, []), importLibrary);
59 List<Library> imports3 = _library5.imports;
60 EngineTestCase.assertLength(1, imports3);
61 JUnitTestCase.assertSame(importLibrary, imports3[0]);
62 _errorListener.assertNoErrors();
63 }
64 void test_getExplicitlyImportsCore() {
65 JUnitTestCase.assertFalse(_library5.explicitlyImportsCore);
66 _errorListener.assertNoErrors();
67 }
68 void test_getExport() {
69 ExportDirective directive = ASTFactory.exportDirective2("exported.dart", []) ;
70 Library exportLibrary = library("/exported.dart");
71 _library5.addExport(directive, exportLibrary);
72 JUnitTestCase.assertSame(exportLibrary, _library5.getExport(directive));
73 _errorListener.assertNoErrors();
74 }
75 void test_getExports() {
76 EngineTestCase.assertLength(0, _library5.exports);
77 _errorListener.assertNoErrors();
78 }
79 void test_getImport() {
80 ImportDirective directive = ASTFactory.importDirective2("imported.dart", nul l, []);
81 Library importLibrary = library("/imported.dart");
82 _library5.addImport(directive, importLibrary);
83 JUnitTestCase.assertSame(importLibrary, _library5.getImport(directive));
84 _errorListener.assertNoErrors();
85 }
86 void test_getImports() {
87 EngineTestCase.assertLength(0, _library5.imports);
88 _errorListener.assertNoErrors();
89 }
90 void test_getImportsAndExports() {
91 _library5.addImport(ASTFactory.importDirective2("imported.dart", null, []), library("/imported.dart"));
92 _library5.addExport(ASTFactory.exportDirective2("exported.dart", []), librar y("/exported.dart"));
93 EngineTestCase.assertLength(2, _library5.importsAndExports);
94 _errorListener.assertNoErrors();
95 }
96 void test_getLibraryScope() {
97 LibraryElementImpl element = new LibraryElementImpl(_analysisContext, ASTFac tory.libraryIdentifier2(["lib"]));
98 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ;
99 _library5.libraryElement = element;
100 JUnitTestCase.assertNotNull(_library5.libraryScope);
101 _errorListener.assertNoErrors();
102 }
103 void test_getLibrarySource() {
104 JUnitTestCase.assertNotNull(_library5.librarySource);
105 }
106 void test_setExplicitlyImportsCore() {
107 _library5.explicitlyImportsCore = true;
108 JUnitTestCase.assertTrue(_library5.explicitlyImportsCore);
109 _errorListener.assertNoErrors();
110 }
111 void test_setLibraryElement() {
112 LibraryElementImpl element = new LibraryElementImpl(_analysisContext, ASTFac tory.libraryIdentifier2(["lib"]));
113 _library5.libraryElement = element;
114 JUnitTestCase.assertSame(element, _library5.libraryElement);
115 }
116 Library library(String definingCompilationUnitPath) => new Library(_analysisCo ntext, _errorListener, new FileBasedSource.con1(_sourceFactory, FileUtilities2.c reateFile(definingCompilationUnitPath)));
117 static dartSuite() {
118 _ut.group('LibraryTest', () {
119 _ut.test('test_addExport', () {
120 final __test = new LibraryTest();
121 runJUnitTest(__test, __test.test_addExport);
122 });
123 _ut.test('test_addImport', () {
124 final __test = new LibraryTest();
125 runJUnitTest(__test, __test.test_addImport);
126 });
127 _ut.test('test_getExplicitlyImportsCore', () {
128 final __test = new LibraryTest();
129 runJUnitTest(__test, __test.test_getExplicitlyImportsCore);
130 });
131 _ut.test('test_getExport', () {
132 final __test = new LibraryTest();
133 runJUnitTest(__test, __test.test_getExport);
134 });
135 _ut.test('test_getExports', () {
136 final __test = new LibraryTest();
137 runJUnitTest(__test, __test.test_getExports);
138 });
139 _ut.test('test_getImport', () {
140 final __test = new LibraryTest();
141 runJUnitTest(__test, __test.test_getImport);
142 });
143 _ut.test('test_getImports', () {
144 final __test = new LibraryTest();
145 runJUnitTest(__test, __test.test_getImports);
146 });
147 _ut.test('test_getImportsAndExports', () {
148 final __test = new LibraryTest();
149 runJUnitTest(__test, __test.test_getImportsAndExports);
150 });
151 _ut.test('test_getLibraryScope', () {
152 final __test = new LibraryTest();
153 runJUnitTest(__test, __test.test_getLibraryScope);
154 });
155 _ut.test('test_getLibrarySource', () {
156 final __test = new LibraryTest();
157 runJUnitTest(__test, __test.test_getLibrarySource);
158 });
159 _ut.test('test_setExplicitlyImportsCore', () {
160 final __test = new LibraryTest();
161 runJUnitTest(__test, __test.test_setExplicitlyImportsCore);
162 });
163 _ut.test('test_setLibraryElement', () {
164 final __test = new LibraryTest();
165 runJUnitTest(__test, __test.test_setLibraryElement);
166 });
167 });
168 }
169 }
170 class StaticTypeWarningCodeTest extends ResolverTestCase {
171 void fail_inaccessibleSetter() {
172 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
173 resolve(source, []);
174 assertErrors([StaticTypeWarningCode.INACCESSIBLE_SETTER]);
175 verify([source]);
176 }
177 void fail_inconsistentMethodInheritance() {
178 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
179 resolve(source, []);
180 assertErrors([StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE]);
181 verify([source]);
182 }
183 void fail_nonTypeAsTypeArgument() {
184 Source source = addSource("/test.dart", EngineTestCase.createSource(["int A; ", "class B<E> {}", "f(B<A> b) {}"]));
185 resolve(source, []);
186 assertErrors([StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT]);
187 verify([source]);
188 }
189 void fail_redirectWithInvalidTypeParameters() {
190 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
191 resolve(source, []);
192 assertErrors([StaticTypeWarningCode.REDIRECT_WITH_INVALID_TYPE_PARAMETERS]);
193 verify([source]);
194 }
195 void fail_typeArgumentViolatesBounds() {
196 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
197 resolve(source, []);
198 assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_VIOLATES_BOUNDS]);
199 verify([source]);
200 }
201 void test_invalidAssignment_instanceVariable() {
202 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", "}", "f() {", " A a;", " a.x = '0';", "}"]));
203 resolve(source, []);
204 assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
205 verify([source]);
206 }
207 void test_invalidAssignment_localVariable() {
208 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " int x;", " x = '0';", "}"]));
209 resolve(source, []);
210 assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
211 verify([source]);
212 }
213 void test_invalidAssignment_staticVariable() {
214 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int x;", "}", "f() {", " A.x = '0';", "}"]));
215 resolve(source, []);
216 assertErrors([StaticTypeWarningCode.INVALID_ASSIGNMENT]);
217 verify([source]);
218 }
219 void test_invocationOfNonFunction_class() {
220 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m() {", " A();", " }", "}"]));
221 resolve(source, []);
222 assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
223 verify([source]);
224 }
225 void test_invocationOfNonFunction_localVariable() {
226 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " int x;", " return x();", "}"]));
227 resolve(source, []);
228 assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
229 verify([source]);
230 }
231 void test_invocationOfNonFunction_ordinaryInvocation() {
232 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", "}", "class B {", " m() {", " A.x();", " }", "}"]));
233 resolve(source, []);
234 assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
235 }
236 void test_invocationOfNonFunction_staticInvocation() {
237 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int get g => 0;", " f() {", " A.g();", " }", "}"]));
238 resolve(source, []);
239 assertErrors([StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION]);
240 }
241 void test_nonBoolCondition_conditional() {
242 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() { return 3 ? 2 : 1; }"]));
243 resolve(source, []);
244 assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
245 verify([source]);
246 }
247 void test_nonBoolCondition_do() {
248 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " do {} while (3);", "}"]));
249 resolve(source, []);
250 assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
251 verify([source]);
252 }
253 void test_nonBoolCondition_if() {
254 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " if (3) return 2; else return 1;", "}"]));
255 resolve(source, []);
256 assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
257 verify([source]);
258 }
259 void test_nonBoolCondition_while() {
260 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " while (3) {}", "}"]));
261 resolve(source, []);
262 assertErrors([StaticTypeWarningCode.NON_BOOL_CONDITION]);
263 verify([source]);
264 }
265 void test_nonBoolExpression() {
266 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " assert(0);", "}"]));
267 resolve(source, []);
268 assertErrors([StaticTypeWarningCode.NON_BOOL_EXPRESSION]);
269 verify([source]);
270 }
271 void test_returnOfInvalidType_function() {
272 Source source = addSource("/test.dart", EngineTestCase.createSource(["int f( ) { return '0'; }"]));
273 resolve(source, []);
274 assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
275 verify([source]);
276 }
277 void test_returnOfInvalidType_localFunction() {
278 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " String m() {", " int f() { return '0'; }", " }", "}"]));
279 resolve(source, []);
280 assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
281 verify([source]);
282 }
283 void test_returnOfInvalidType_method() {
284 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int f() { return '0'; }", "}"]));
285 resolve(source, []);
286 assertErrors([StaticTypeWarningCode.RETURN_OF_INVALID_TYPE]);
287 verify([source]);
288 }
289 void test_typeArgumentNotMatchingBounds_const() {
290 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "class G<E extends A> {", " const G() {}", "}", "f() { ret urn const G<B>(); }"]));
291 resolve(source, []);
292 assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
293 verify([source]);
294 }
295 void test_typeArgumentNotMatchingBounds_new() {
296 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "class G<E extends A> {}", "f() { return new G<B>(); }"]));
297 resolve(source, []);
298 assertErrors([StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]);
299 verify([source]);
300 }
301 void test_undefinedGetter() {
302 Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {}", "f(T e) { return e.m; }"]));
303 resolve(source, []);
304 assertErrors([StaticTypeWarningCode.UNDEFINED_GETTER]);
305 }
306 void test_undefinedGetter_static() {
307 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "var a = A.B;"]));
308 resolve(source, []);
309 assertErrors([StaticTypeWarningCode.UNDEFINED_GETTER]);
310 }
311 void test_undefinedSetter() {
312 Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {}", "f(T e1) { e1.m = 0; }"]));
313 resolve(source, []);
314 assertErrors([StaticTypeWarningCode.UNDEFINED_SETTER]);
315 }
316 void test_undefinedSetter_static() {
317 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f() { A.B = 0;}"]));
318 resolve(source, []);
319 assertErrors([StaticTypeWarningCode.UNDEFINED_SETTER]);
320 }
321 void test_undefinedSuperMethod() {
322 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {", " m() { return super.m(); }", "}"]));
323 resolve(source, []);
324 assertErrors([StaticTypeWarningCode.UNDEFINED_SUPER_METHOD]);
325 verify([source]);
326 }
327 void test_wrongNumberOfTypeArguments_tooFew() {
328 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E, F> {}", "A<A> a = null;"]));
329 resolve(source, []);
330 assertErrors([StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
331 verify([source]);
332 }
333 void test_wrongNumberOfTypeArguments_tooMany() {
334 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {}", "A<A, A> a = null;"]));
335 resolve(source, []);
336 assertErrors([StaticTypeWarningCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
337 verify([source]);
338 }
339 static dartSuite() {
340 _ut.group('StaticTypeWarningCodeTest', () {
341 _ut.test('test_invalidAssignment_instanceVariable', () {
342 final __test = new StaticTypeWarningCodeTest();
343 runJUnitTest(__test, __test.test_invalidAssignment_instanceVariable);
344 });
345 _ut.test('test_invalidAssignment_localVariable', () {
346 final __test = new StaticTypeWarningCodeTest();
347 runJUnitTest(__test, __test.test_invalidAssignment_localVariable);
348 });
349 _ut.test('test_invalidAssignment_staticVariable', () {
350 final __test = new StaticTypeWarningCodeTest();
351 runJUnitTest(__test, __test.test_invalidAssignment_staticVariable);
352 });
353 _ut.test('test_invocationOfNonFunction_class', () {
354 final __test = new StaticTypeWarningCodeTest();
355 runJUnitTest(__test, __test.test_invocationOfNonFunction_class);
356 });
357 _ut.test('test_invocationOfNonFunction_localVariable', () {
358 final __test = new StaticTypeWarningCodeTest();
359 runJUnitTest(__test, __test.test_invocationOfNonFunction_localVariable);
360 });
361 _ut.test('test_invocationOfNonFunction_ordinaryInvocation', () {
362 final __test = new StaticTypeWarningCodeTest();
363 runJUnitTest(__test, __test.test_invocationOfNonFunction_ordinaryInvocat ion);
364 });
365 _ut.test('test_invocationOfNonFunction_staticInvocation', () {
366 final __test = new StaticTypeWarningCodeTest();
367 runJUnitTest(__test, __test.test_invocationOfNonFunction_staticInvocatio n);
368 });
369 _ut.test('test_nonBoolCondition_conditional', () {
370 final __test = new StaticTypeWarningCodeTest();
371 runJUnitTest(__test, __test.test_nonBoolCondition_conditional);
372 });
373 _ut.test('test_nonBoolCondition_do', () {
374 final __test = new StaticTypeWarningCodeTest();
375 runJUnitTest(__test, __test.test_nonBoolCondition_do);
376 });
377 _ut.test('test_nonBoolCondition_if', () {
378 final __test = new StaticTypeWarningCodeTest();
379 runJUnitTest(__test, __test.test_nonBoolCondition_if);
380 });
381 _ut.test('test_nonBoolCondition_while', () {
382 final __test = new StaticTypeWarningCodeTest();
383 runJUnitTest(__test, __test.test_nonBoolCondition_while);
384 });
385 _ut.test('test_nonBoolExpression', () {
386 final __test = new StaticTypeWarningCodeTest();
387 runJUnitTest(__test, __test.test_nonBoolExpression);
388 });
389 _ut.test('test_returnOfInvalidType_function', () {
390 final __test = new StaticTypeWarningCodeTest();
391 runJUnitTest(__test, __test.test_returnOfInvalidType_function);
392 });
393 _ut.test('test_returnOfInvalidType_localFunction', () {
394 final __test = new StaticTypeWarningCodeTest();
395 runJUnitTest(__test, __test.test_returnOfInvalidType_localFunction);
396 });
397 _ut.test('test_returnOfInvalidType_method', () {
398 final __test = new StaticTypeWarningCodeTest();
399 runJUnitTest(__test, __test.test_returnOfInvalidType_method);
400 });
401 _ut.test('test_typeArgumentNotMatchingBounds_const', () {
402 final __test = new StaticTypeWarningCodeTest();
403 runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_const);
404 });
405 _ut.test('test_typeArgumentNotMatchingBounds_new', () {
406 final __test = new StaticTypeWarningCodeTest();
407 runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_new);
408 });
409 _ut.test('test_undefinedGetter', () {
410 final __test = new StaticTypeWarningCodeTest();
411 runJUnitTest(__test, __test.test_undefinedGetter);
412 });
413 _ut.test('test_undefinedGetter_static', () {
414 final __test = new StaticTypeWarningCodeTest();
415 runJUnitTest(__test, __test.test_undefinedGetter_static);
416 });
417 _ut.test('test_undefinedSetter', () {
418 final __test = new StaticTypeWarningCodeTest();
419 runJUnitTest(__test, __test.test_undefinedSetter);
420 });
421 _ut.test('test_undefinedSetter_static', () {
422 final __test = new StaticTypeWarningCodeTest();
423 runJUnitTest(__test, __test.test_undefinedSetter_static);
424 });
425 _ut.test('test_undefinedSuperMethod', () {
426 final __test = new StaticTypeWarningCodeTest();
427 runJUnitTest(__test, __test.test_undefinedSuperMethod);
428 });
429 _ut.test('test_wrongNumberOfTypeArguments_tooFew', () {
430 final __test = new StaticTypeWarningCodeTest();
431 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_tooFew);
432 });
433 _ut.test('test_wrongNumberOfTypeArguments_tooMany', () {
434 final __test = new StaticTypeWarningCodeTest();
435 runJUnitTest(__test, __test.test_wrongNumberOfTypeArguments_tooMany);
436 });
437 });
438 }
439 }
440 class TypeResolverVisitorTest extends EngineTestCase {
441 /**
442 * The error listener to which errors will be reported.
443 */
444 GatheringErrorListener _listener;
445 /**
446 * The object representing the information about the library in which the type s are being
447 * resolved.
448 */
449 Library _library;
450 /**
451 * The type provider used to access the types.
452 */
453 TestTypeProvider _typeProvider;
454 /**
455 * The visitor used to resolve types needed to form the type hierarchy.
456 */
457 TypeResolverVisitor _visitor;
458 void fail_visitConstructorDeclaration() {
459 JUnitTestCase.fail("Not yet tested");
460 _listener.assertNoErrors();
461 }
462 void fail_visitFieldFormalParameter_noType() {
463 FormalParameter node = ASTFactory.fieldFormalParameter(Keyword.VAR, null, "p ");
464 JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve5(node, []));
465 _listener.assertNoErrors();
466 }
467 void fail_visitFieldFormalParameter_type() {
468 FormalParameter node = ASTFactory.fieldFormalParameter(null, ASTFactory.type Name3("int", []), "p");
469 JUnitTestCase.assertSame(_typeProvider.intType, resolve5(node, []));
470 _listener.assertNoErrors();
471 }
472 void fail_visitFunctionDeclaration() {
473 JUnitTestCase.fail("Not yet tested");
474 _listener.assertNoErrors();
475 }
476 void fail_visitFunctionTypeAlias() {
477 JUnitTestCase.fail("Not yet tested");
478 _listener.assertNoErrors();
479 }
480 void fail_visitFunctionTypedFormalParameter() {
481 JUnitTestCase.fail("Not yet tested");
482 _listener.assertNoErrors();
483 }
484 void fail_visitMethodDeclaration() {
485 JUnitTestCase.fail("Not yet tested");
486 _listener.assertNoErrors();
487 }
488 void fail_visitVariableDeclaration() {
489 JUnitTestCase.fail("Not yet tested");
490 ClassElement type = ElementFactory.classElement2("A", []);
491 VariableDeclaration node = ASTFactory.variableDeclaration("a");
492 ASTFactory.variableDeclarationList(null, ASTFactory.typeName(type, []), [nod e]);
493 JUnitTestCase.assertSame(type.type, node.name.staticType);
494 _listener.assertNoErrors();
495 }
496 void setUp() {
497 _listener = new GatheringErrorListener();
498 SourceFactory factory = new SourceFactory.con2([new FileUriResolver()]);
499 AnalysisContextImpl context = new AnalysisContextImpl();
500 context.sourceFactory = factory;
501 Source librarySource = new FileBasedSource.con1(factory, FileUtilities2.crea teFile("/lib.dart"));
502 _library = new Library(context, _listener, librarySource);
503 LibraryElementImpl element = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2(["lib"]));
504 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ;
505 _library.libraryElement = element;
506 _typeProvider = new TestTypeProvider();
507 _visitor = new TypeResolverVisitor(_library, librarySource, _typeProvider);
508 }
509 void test_visitCatchClause_exception() {
510 CatchClause clause = ASTFactory.catchClause("e", []);
511 resolve(clause, _typeProvider.objectType, null, []);
512 _listener.assertNoErrors();
513 }
514 void test_visitCatchClause_exception_stackTrace() {
515 CatchClause clause = ASTFactory.catchClause2("e", "s", []);
516 resolve(clause, _typeProvider.objectType, _typeProvider.stackTraceType, []);
517 _listener.assertNoErrors();
518 }
519 void test_visitCatchClause_on_exception() {
520 ClassElement exceptionElement = ElementFactory.classElement2("E", []);
521 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []);
522 CatchClause clause = ASTFactory.catchClause4(exceptionType, "e", []);
523 resolve(clause, exceptionElement.type, null, [exceptionElement]);
524 _listener.assertNoErrors();
525 }
526 void test_visitCatchClause_on_exception_stackTrace() {
527 ClassElement exceptionElement = ElementFactory.classElement2("E", []);
528 TypeName exceptionType = ASTFactory.typeName(exceptionElement, []);
529 ((exceptionType.name as SimpleIdentifier)).element = exceptionElement;
530 CatchClause clause = ASTFactory.catchClause5(exceptionType, "e", "s", []);
531 resolve(clause, exceptionElement.type, _typeProvider.stackTraceType, [except ionElement]);
532 _listener.assertNoErrors();
533 }
534 void test_visitClassDeclaration() {
535 ClassElement elementA = ElementFactory.classElement2("A", []);
536 ClassElement elementB = ElementFactory.classElement2("B", []);
537 ClassElement elementC = ElementFactory.classElement2("C", []);
538 ClassElement elementD = ElementFactory.classElement2("D", []);
539 ExtendsClause extendsClause2 = ASTFactory.extendsClause(ASTFactory.typeName( elementB, []));
540 WithClause withClause2 = ASTFactory.withClause([ASTFactory.typeName(elementC , [])]);
541 ImplementsClause implementsClause2 = ASTFactory.implementsClause([ASTFactory .typeName(elementD, [])]);
542 ClassDeclaration declaration = ASTFactory.classDeclaration(null, "A", null, extendsClause2, withClause2, implementsClause2, []);
543 declaration.name.element = elementA;
544 resolveNode(declaration, [elementA, elementB, elementC, elementD]);
545 JUnitTestCase.assertSame(elementB.type, elementA.supertype);
546 List<InterfaceType> mixins3 = elementA.mixins;
547 EngineTestCase.assertLength(1, mixins3);
548 JUnitTestCase.assertSame(elementC.type, mixins3[0]);
549 List<InterfaceType> interfaces3 = elementA.interfaces;
550 EngineTestCase.assertLength(1, interfaces3);
551 JUnitTestCase.assertSame(elementD.type, interfaces3[0]);
552 _listener.assertNoErrors();
553 }
554 void test_visitClassTypeAlias() {
555 ClassElement elementA = ElementFactory.classElement2("A", []);
556 ClassElement elementB = ElementFactory.classElement2("B", []);
557 ClassElement elementC = ElementFactory.classElement2("C", []);
558 ClassElement elementD = ElementFactory.classElement2("D", []);
559 WithClause withClause3 = ASTFactory.withClause([ASTFactory.typeName(elementC , [])]);
560 ImplementsClause implementsClause3 = ASTFactory.implementsClause([ASTFactory .typeName(elementD, [])]);
561 ClassTypeAlias alias = ASTFactory.classTypeAlias("A", null, null, ASTFactory .typeName(elementB, []), withClause3, implementsClause3);
562 alias.name.element = elementA;
563 resolveNode(alias, [elementA, elementB, elementC, elementD]);
564 JUnitTestCase.assertSame(elementB.type, elementA.supertype);
565 List<InterfaceType> mixins4 = elementA.mixins;
566 EngineTestCase.assertLength(1, mixins4);
567 JUnitTestCase.assertSame(elementC.type, mixins4[0]);
568 List<InterfaceType> interfaces4 = elementA.interfaces;
569 EngineTestCase.assertLength(1, interfaces4);
570 JUnitTestCase.assertSame(elementD.type, interfaces4[0]);
571 _listener.assertNoErrors();
572 }
573 void test_visitSimpleFormalParameter_noType() {
574 FormalParameter node = ASTFactory.simpleFormalParameter3("p");
575 node.identifier.element = new ParameterElementImpl(ASTFactory.identifier2("p "));
576 JUnitTestCase.assertSame(_typeProvider.dynamicType, resolve5(node, []));
577 _listener.assertNoErrors();
578 }
579 void test_visitSimpleFormalParameter_type() {
580 InterfaceType intType8 = _typeProvider.intType;
581 ClassElement intElement = intType8.element;
582 FormalParameter node = ASTFactory.simpleFormalParameter4(ASTFactory.typeName (intElement, []), "p");
583 SimpleIdentifier identifier18 = node.identifier;
584 ParameterElementImpl element = new ParameterElementImpl(identifier18);
585 identifier18.element = element;
586 JUnitTestCase.assertSame(intType8, resolve5(node, [intElement]));
587 _listener.assertNoErrors();
588 }
589 void test_visitTypeName_noParameters_noArguments() {
590 ClassElement classA = ElementFactory.classElement2("A", []);
591 TypeName typeName5 = ASTFactory.typeName(classA, []);
592 typeName5.type = null;
593 resolveNode(typeName5, [classA]);
594 JUnitTestCase.assertSame(classA.type, typeName5.type);
595 _listener.assertNoErrors();
596 }
597 void test_visitTypeName_parameters_arguments() {
598 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
599 ClassElement classB = ElementFactory.classElement2("B", []);
600 TypeName typeName6 = ASTFactory.typeName(classA, [ASTFactory.typeName(classB , [])]);
601 typeName6.type = null;
602 resolveNode(typeName6, [classA, classB]);
603 InterfaceType resultType = typeName6.type as InterfaceType;
604 JUnitTestCase.assertSame(classA, resultType.element);
605 List<Type2> resultArguments = resultType.typeArguments;
606 EngineTestCase.assertLength(1, resultArguments);
607 JUnitTestCase.assertSame(classB.type, resultArguments[0]);
608 _listener.assertNoErrors();
609 }
610 void test_visitTypeName_parameters_noArguments() {
611 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
612 TypeName typeName7 = ASTFactory.typeName(classA, []);
613 typeName7.type = null;
614 resolveNode(typeName7, [classA]);
615 InterfaceType resultType = typeName7.type as InterfaceType;
616 JUnitTestCase.assertSame(classA, resultType.element);
617 List<Type2> resultArguments = resultType.typeArguments;
618 EngineTestCase.assertLength(1, resultArguments);
619 JUnitTestCase.assertSame(DynamicTypeImpl.instance, resultArguments[0]);
620 _listener.assertNoErrors();
621 }
622 /**
623 * Analyze the given catch clause and assert that the types of the parameters have been set to the
624 * given types. The types can be null if the catch clause does not have the co rresponding
625 * parameter.
626 * @param node the catch clause to be analyzed
627 * @param exceptionType the expected type of the exception parameter
628 * @param stackTraceType the expected type of the stack trace parameter
629 * @param definedElements the elements that are to be defined in the scope in which the element is
630 * being resolved
631 */
632 void resolve(CatchClause node, InterfaceType exceptionType, InterfaceType stac kTraceType, List<Element> definedElements) {
633 resolveNode(node, definedElements);
634 SimpleIdentifier exceptionParameter3 = node.exceptionParameter;
635 if (exceptionParameter3 != null) {
636 JUnitTestCase.assertSame(exceptionType, exceptionParameter3.staticType);
637 }
638 SimpleIdentifier stackTraceParameter3 = node.stackTraceParameter;
639 if (stackTraceParameter3 != null) {
640 JUnitTestCase.assertSame(stackTraceType, stackTraceParameter3.staticType);
641 }
642 }
643 /**
644 * Return the type associated with the given parameter after the static type a nalyzer has computed
645 * a type for it.
646 * @param node the parameter with which the type is associated
647 * @param definedElements the elements that are to be defined in the scope in which the element is
648 * being resolved
649 * @return the type associated with the parameter
650 */
651 Type2 resolve5(FormalParameter node, List<Element> definedElements) {
652 resolveNode(node, definedElements);
653 return ((node.identifier.element as ParameterElement)).type;
654 }
655 /**
656 * Return the element associated with the given identifier after the resolver has resolved the
657 * identifier.
658 * @param node the expression to be resolved
659 * @param definedElements the elements that are to be defined in the scope in which the element is
660 * being resolved
661 * @return the element to which the expression was resolved
662 */
663 void resolveNode(ASTNode node, List<Element> definedElements) {
664 for (Element element in definedElements) {
665 _library.libraryScope.define(element);
666 }
667 node.accept(_visitor);
668 }
669 static dartSuite() {
670 _ut.group('TypeResolverVisitorTest', () {
671 _ut.test('test_visitCatchClause_exception', () {
672 final __test = new TypeResolverVisitorTest();
673 runJUnitTest(__test, __test.test_visitCatchClause_exception);
674 });
675 _ut.test('test_visitCatchClause_exception_stackTrace', () {
676 final __test = new TypeResolverVisitorTest();
677 runJUnitTest(__test, __test.test_visitCatchClause_exception_stackTrace);
678 });
679 _ut.test('test_visitCatchClause_on_exception', () {
680 final __test = new TypeResolverVisitorTest();
681 runJUnitTest(__test, __test.test_visitCatchClause_on_exception);
682 });
683 _ut.test('test_visitCatchClause_on_exception_stackTrace', () {
684 final __test = new TypeResolverVisitorTest();
685 runJUnitTest(__test, __test.test_visitCatchClause_on_exception_stackTrac e);
686 });
687 _ut.test('test_visitClassDeclaration', () {
688 final __test = new TypeResolverVisitorTest();
689 runJUnitTest(__test, __test.test_visitClassDeclaration);
690 });
691 _ut.test('test_visitClassTypeAlias', () {
692 final __test = new TypeResolverVisitorTest();
693 runJUnitTest(__test, __test.test_visitClassTypeAlias);
694 });
695 _ut.test('test_visitSimpleFormalParameter_noType', () {
696 final __test = new TypeResolverVisitorTest();
697 runJUnitTest(__test, __test.test_visitSimpleFormalParameter_noType);
698 });
699 _ut.test('test_visitSimpleFormalParameter_type', () {
700 final __test = new TypeResolverVisitorTest();
701 runJUnitTest(__test, __test.test_visitSimpleFormalParameter_type);
702 });
703 _ut.test('test_visitTypeName_noParameters_noArguments', () {
704 final __test = new TypeResolverVisitorTest();
705 runJUnitTest(__test, __test.test_visitTypeName_noParameters_noArguments) ;
706 });
707 _ut.test('test_visitTypeName_parameters_arguments', () {
708 final __test = new TypeResolverVisitorTest();
709 runJUnitTest(__test, __test.test_visitTypeName_parameters_arguments);
710 });
711 _ut.test('test_visitTypeName_parameters_noArguments', () {
712 final __test = new TypeResolverVisitorTest();
713 runJUnitTest(__test, __test.test_visitTypeName_parameters_noArguments);
714 });
715 });
716 }
717 }
718 class ResolverTestCase extends EngineTestCase {
719 /**
720 * The source factory used to create {@link Source sources}.
721 */
722 SourceFactory _sourceFactory;
723 /**
724 * The error listener used during resolution.
725 */
726 GatheringErrorListener _errorListener;
727 /**
728 * The analysis context used to parse the compilation units being resolved.
729 */
730 AnalysisContextImpl _analysisContext;
731 /**
732 * Assert that the number of errors that have been gathered matches the number of errors that are
733 * given and that they have the expected error codes. The order in which the e rrors were gathered
734 * is ignored.
735 * @param expectedErrorCodes the error codes of the errors that should have be en gathered
736 * @throws AssertionFailedError if a different number of errors have been gath ered than were
737 * expected
738 */
739 void assertErrors(List<ErrorCode> expectedErrorCodes) {
740 _errorListener.assertErrors2(expectedErrorCodes);
741 }
742 void setUp() {
743 _errorListener = new GatheringErrorListener();
744 _analysisContext = AnalysisContextFactory.contextWithCore();
745 _sourceFactory = _analysisContext.sourceFactory;
746 }
747 /**
748 * Add a source file to the content provider. The file path should be absolute .
749 * @param filePath the path of the file being added
750 * @param contents the contents to be returned by the content provider for the specified file
751 * @return the source object representing the added file
752 */
753 Source addSource(String filePath, String contents) {
754 Source source = new FileBasedSource.con1(_sourceFactory, FileUtilities2.crea teFile(filePath));
755 _sourceFactory.setContents(source, contents);
756 return source;
757 }
758 /**
759 * Assert that no errors have been gathered.
760 * @throws AssertionFailedError if any errors have been gathered
761 */
762 void assertNoErrors() {
763 _errorListener.assertNoErrors();
764 }
765 /**
766 * Create a library element that represents a library named {@code "test"} con taining a single
767 * empty compilation unit.
768 * @return the library element that was created
769 */
770 LibraryElementImpl createTestLibrary() => createTestLibrary2(new AnalysisConte xtImpl(), "test", []);
771 /**
772 * Create a library element that represents a library with the given name cont aining a single
773 * empty compilation unit.
774 * @param libraryName the name of the library to be created
775 * @return the library element that was created
776 */
777 LibraryElementImpl createTestLibrary2(AnalysisContext context, String libraryN ame, List<String> typeNames) {
778 int count = typeNames.length;
779 List<CompilationUnitElementImpl> sourcedCompilationUnits = new List<Compilat ionUnitElementImpl>(count);
780 for (int i = 0; i < count; i++) {
781 String typeName = typeNames[i];
782 ClassElementImpl type = new ClassElementImpl(ASTFactory.identifier2(typeNa me));
783 String fileName = "${typeName}.dart";
784 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImp l(fileName);
785 compilationUnit.source = new FileBasedSource.con1(_sourceFactory, FileUtil ities2.createFile(fileName));
786 compilationUnit.types = <ClassElement> [type];
787 sourcedCompilationUnits[i] = compilationUnit;
788 }
789 String fileName = "${libraryName}.dart";
790 CompilationUnitElementImpl compilationUnit = new CompilationUnitElementImpl( fileName);
791 compilationUnit.source = new FileBasedSource.con1(_sourceFactory, FileUtilit ies2.createFile(fileName));
792 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2([libraryName]));
793 library.definingCompilationUnit = compilationUnit;
794 library.parts = sourcedCompilationUnits;
795 return library;
796 }
797 AnalysisContext get analysisContext => _analysisContext;
798 GatheringErrorListener get errorListener => _errorListener;
799 SourceFactory get sourceFactory => _sourceFactory;
800 /**
801 * Given a library and all of its parts, resolve the contents of the library a nd the contents of
802 * the parts. This assumes that the sources for the library and its parts have already been added
803 * to the content provider using the method {@link #addSource(String,String)}.
804 * @param librarySource the source for the compilation unit that defines the l ibrary
805 * @param unitSources the sources for the compilation units that are part of t he library
806 * @return the element representing the resolved library
807 * @throws AnalysisException if the analysis could not be performed
808 */
809 LibraryElement resolve(Source librarySource, List<Source> unitSources) {
810 LibraryResolver resolver = new LibraryResolver.con2(_analysisContext, _error Listener);
811 return resolver.resolveLibrary(librarySource, true);
812 }
813 /**
814 * Verify that all of the identifiers in the compilation units associated with the given sources
815 * have been resolved.
816 * @param resolvedElementMap a table mapping the AST nodes that have been reso lved to the element
817 * to which they were resolved
818 * @param sources the sources identifying the compilation units to be verified
819 * @throws Exception if the contents of the compilation unit cannot be accesse d
820 */
821 void verify(List<Source> sources) {
822 ResolutionVerifier verifier = new ResolutionVerifier();
823 for (Source source in sources) {
824 _analysisContext.parse3(source, _errorListener).accept(verifier);
825 }
826 verifier.assertResolved();
827 }
828 static dartSuite() {
829 _ut.group('ResolverTestCase', () {
830 });
831 }
832 }
833 class TypeProviderImplTest extends EngineTestCase {
834 void test_creation() {
835 InterfaceType objectType = classElement("Object", null, []).type;
836 InterfaceType boolType = classElement("bool", objectType, []).type;
837 InterfaceType numType = classElement("num", objectType, []).type;
838 InterfaceType doubleType = classElement("double", numType, []).type;
839 InterfaceType functionType = classElement("Function", objectType, []).type;
840 InterfaceType intType = classElement("int", numType, []).type;
841 InterfaceType listType = classElement("List", objectType, ["E"]).type;
842 InterfaceType mapType = classElement("Map", objectType, ["K", "V"]).type;
843 InterfaceType stackTraceType = classElement("StackTrace", objectType, []).ty pe;
844 InterfaceType stringType = classElement("String", objectType, []).type;
845 InterfaceType typeType = classElement("Type", objectType, []).type;
846 CompilationUnitElementImpl unit = new CompilationUnitElementImpl("lib.dart") ;
847 unit.types = <ClassElement> [boolType.element, doubleType.element, functionT ype.element, intType.element, listType.element, mapType.element, objectType.elem ent, stackTraceType.element, stringType.element, typeType.element];
848 LibraryElementImpl library = new LibraryElementImpl(new AnalysisContextImpl( ), ASTFactory.libraryIdentifier2(["lib"]));
849 library.definingCompilationUnit = unit;
850 TypeProviderImpl provider = new TypeProviderImpl(library);
851 JUnitTestCase.assertSame(boolType, provider.boolType);
852 JUnitTestCase.assertNotNull(provider.bottomType);
853 JUnitTestCase.assertSame(doubleType, provider.doubleType);
854 JUnitTestCase.assertNotNull(provider.dynamicType);
855 JUnitTestCase.assertSame(functionType, provider.functionType);
856 JUnitTestCase.assertSame(intType, provider.intType);
857 JUnitTestCase.assertSame(listType, provider.listType);
858 JUnitTestCase.assertSame(mapType, provider.mapType);
859 JUnitTestCase.assertSame(objectType, provider.objectType);
860 JUnitTestCase.assertSame(stackTraceType, provider.stackTraceType);
861 JUnitTestCase.assertSame(stringType, provider.stringType);
862 JUnitTestCase.assertSame(typeType, provider.typeType);
863 }
864 ClassElement classElement(String typeName, InterfaceType superclassType, List< String> parameterNames) {
865 ClassElementImpl element = new ClassElementImpl(ASTFactory.identifier2(typeN ame));
866 element.supertype = superclassType;
867 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element);
868 element.type = type;
869 int count = parameterNames.length;
870 if (count > 0) {
871 List<TypeVariableElementImpl> typeVariables = new List<TypeVariableElement Impl>(count);
872 List<TypeVariableTypeImpl> typeArguments = new List<TypeVariableTypeImpl>( count);
873 for (int i = 0; i < count; i++) {
874 TypeVariableElementImpl variable = new TypeVariableElementImpl(ASTFactor y.identifier2(parameterNames[i]));
875 typeVariables[i] = variable;
876 typeArguments[i] = new TypeVariableTypeImpl(variable);
877 variable.type = typeArguments[i];
878 }
879 element.typeVariables = typeVariables;
880 type.typeArguments = typeArguments;
881 }
882 return element;
883 }
884 static dartSuite() {
885 _ut.group('TypeProviderImplTest', () {
886 _ut.test('test_creation', () {
887 final __test = new TypeProviderImplTest();
888 runJUnitTest(__test, __test.test_creation);
889 });
890 });
891 }
892 }
893 class CompileTimeErrorCodeTest extends ResolverTestCase {
894 void fail_ambiguousExport() {
895 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y L;", "export 'lib1.dart';", "export 'lib2.dart';"]));
896 addSource("/lib1.dart", EngineTestCase.createSource(["class N {}"]));
897 addSource("/lib2.dart", EngineTestCase.createSource(["class N {}"]));
898 resolve(source, []);
899 assertErrors([CompileTimeErrorCode.AMBIGUOUS_EXPORT]);
900 verify([source]);
901 }
902 void fail_ambiguousImport_function() {
903 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y L;", "import 'lib1.dart';", "import 'lib2.dart';", "g() { return f(); }"]));
904 addSource("/lib1.dart", EngineTestCase.createSource(["f() {}"]));
905 addSource("/lib2.dart", EngineTestCase.createSource(["f() {}"]));
906 resolve(source, []);
907 assertErrors([CompileTimeErrorCode.AMBIGUOUS_IMPORT]);
908 verify([source]);
909 }
910 void fail_ambiguousImport_typeAnnotation() {
911 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y L;", "import 'lib1.dart';", "import 'lib2.dart';", "class A extends N {}"]));
912 addSource("/lib1.dart", EngineTestCase.createSource(["class N {}"]));
913 addSource("/lib2.dart", EngineTestCase.createSource(["class N {}"]));
914 resolve(source, []);
915 assertErrors([CompileTimeErrorCode.AMBIGUOUS_IMPORT]);
916 verify([source]);
917 }
918 void fail_caseExpressionTypeImplementsEquals() {
919 Source source = addSource("/test.dart", EngineTestCase.createSource(["class IntWrapper {", " final int value;", " const IntWrapper(this.value);", " bool operator ==(IntWrapper x) {", " return value == x.value;", " }", "}", "", "f (IntWrapper a) {", " switch(a) {", " case(const IntWrapper(1)) : return 1;", " default: return 0;", " }", "}"]));
920 resolve(source, []);
921 assertErrors([CompileTimeErrorCode.CASE_EXPRESSION_TYPE_IMPLEMENTS_EQUALS]);
922 verify([source]);
923 }
924 void fail_compileTimeConstantRaisesException() {
925 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
926 resolve(source, []);
927 assertErrors([CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION]);
928 verify([source]);
929 }
930 void fail_constEvalThrowsException() {
931 Source source = addSource("/test.dart", EngineTestCase.createSource(["class C {", " const C() { throw null; }", "}", "f() { return const C(); }"]));
932 resolve(source, []);
933 assertErrors([CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION]);
934 verify([source]);
935 }
936 void fail_constWithNonConst() {
937 Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {", " T(a, b, {c, d}) {};", "}", "f() { return const T(0, 1, c: 2, d: 3); }"] ));
938 resolve(source, []);
939 assertErrors([CompileTimeErrorCode.CONST_WITH_NON_CONST]);
940 verify([source]);
941 }
942 void fail_constWithNonConstantArgument() {
943 Source source = addSource("/test.dart", EngineTestCase.createSource(["class T {", " T(a) {};", "}", "f(p) { return const T(p); }"]));
944 resolve(source, []);
945 assertErrors([CompileTimeErrorCode.CONST_WITH_NON_CONSTANT_ARGUMENT]);
946 verify([source]);
947 }
948 void fail_constWithNonType() {
949 Source source = addSource("/test.dart", EngineTestCase.createSource(["int A; ", "f() {", " return const A();", "}"]));
950 resolve(source, []);
951 assertErrors([CompileTimeErrorCode.CONST_WITH_NON_TYPE]);
952 verify([source]);
953 }
954 void fail_constWithTypeParameters() {
955 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
956 resolve(source, []);
957 assertErrors([CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS]);
958 verify([source]);
959 }
960 void fail_constWithUndefinedConstructor() {
961 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A(x) {}", "}", "f() {", " return const A(0);", "}"]));
962 resolve(source, []);
963 assertErrors([CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]);
964 verify([source]);
965 }
966 void fail_defaultValueInFunctionTypeAlias() {
967 Source source = addSource("/test.dart", EngineTestCase.createSource(["typede f F([x = 0]);"]));
968 resolve(source, []);
969 assertErrors([CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]);
970 verify([source]);
971 }
972 void fail_duplicateDefinition() {
973 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " int m = 0;", " m(a) {}", "}"]));
974 resolve(source, []);
975 assertErrors([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
976 verify([source]);
977 }
978 void fail_duplicateMemberName() {
979 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x = 0;", " int x() {}", "}"]));
980 resolve(source, []);
981 assertErrors([CompileTimeErrorCode.DUPLICATE_MEMBER_NAME]);
982 verify([source]);
983 }
984 void fail_duplicateMemberNameInstanceStatic() {
985 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " static int x;", "}"]));
986 resolve(source, []);
987 assertErrors([CompileTimeErrorCode.DUPLICATE_MEMBER_NAME_INSTANCE_STATIC]);
988 verify([source]);
989 }
990 void fail_duplicateNamedArgument() {
991 Source source = addSource("/test.dart", EngineTestCase.createSource(["f({a, a}) {}"]));
992 resolve(source, []);
993 assertErrors([CompileTimeErrorCode.DUPLICATE_NAMED_ARGUMENT]);
994 verify([source]);
995 }
996 void fail_exportOfNonLibrary() {
997 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y L;", "export 'lib1.dart';"]));
998 addSource("/lib1.dart", EngineTestCase.createSource(["part of lib;"]));
999 resolve(source, []);
1000 assertErrors([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]);
1001 verify([source]);
1002 }
1003 void fail_extendsOrImplementsDisallowedClass_extends_bool() {
1004 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends bool {}"]));
1005 resolve(source, []);
1006 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1007 verify([source]);
1008 }
1009 void fail_extendsOrImplementsDisallowedClass_extends_double() {
1010 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends double {}"]));
1011 resolve(source, []);
1012 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1013 verify([source]);
1014 }
1015 void fail_extendsOrImplementsDisallowedClass_extends_int() {
1016 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends int {}"]));
1017 resolve(source, []);
1018 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1019 verify([source]);
1020 }
1021 void fail_extendsOrImplementsDisallowedClass_extends_null() {
1022 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends Null {}"]));
1023 resolve(source, []);
1024 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1025 verify([source]);
1026 }
1027 void fail_extendsOrImplementsDisallowedClass_extends_num() {
1028 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends num {}"]));
1029 resolve(source, []);
1030 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1031 verify([source]);
1032 }
1033 void fail_extendsOrImplementsDisallowedClass_extends_String() {
1034 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends String {}"]));
1035 resolve(source, []);
1036 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1037 verify([source]);
1038 }
1039 void fail_extendsOrImplementsDisallowedClass_implements_bool() {
1040 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements bool {}"]));
1041 resolve(source, []);
1042 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1043 verify([source]);
1044 }
1045 void fail_extendsOrImplementsDisallowedClass_implements_double() {
1046 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements double {}"]));
1047 resolve(source, []);
1048 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1049 verify([source]);
1050 }
1051 void fail_extendsOrImplementsDisallowedClass_implements_int() {
1052 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements int {}"]));
1053 resolve(source, []);
1054 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1055 verify([source]);
1056 }
1057 void fail_extendsOrImplementsDisallowedClass_implements_null() {
1058 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements Null {}"]));
1059 resolve(source, []);
1060 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1061 verify([source]);
1062 }
1063 void fail_extendsOrImplementsDisallowedClass_implements_num() {
1064 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements num {}"]));
1065 resolve(source, []);
1066 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1067 verify([source]);
1068 }
1069 void fail_extendsOrImplementsDisallowedClass_implements_String() {
1070 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements String {}"]));
1071 resolve(source, []);
1072 assertErrors([CompileTimeErrorCode.EXTENDS_OR_IMPLEMENTS_DISALLOWED_CLASS]);
1073 verify([source]);
1074 }
1075 void fail_fieldInitializedByMultipleInitializers() {
1076 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A() : x = 0, x = 1 {}", "}"]));
1077 resolve(source, []);
1078 assertErrors([CompileTimeErrorCode.FIELD_INITIALIZED_BY_MULTIPLE_INITIALIZER S]);
1079 verify([source]);
1080 }
1081 void fail_fieldInitializedInInitializerAndDeclaration() {
1082 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x = 0;", " A() : x = 1 {}", "}"]));
1083 resolve(source, []);
1084 assertErrors([CompileTimeErrorCode.FIELD_INITIALIZED_IN_INITIALIZER_AND_DECL ARATION]);
1085 verify([source]);
1086 }
1087 void fail_fieldInitializeInParameterAndInitializer() {
1088 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A(this.x) : x = 1 {}", "}"]));
1089 resolve(source, []);
1090 assertErrors([CompileTimeErrorCode.FIELD_INITIALIZED_IN_PARAMETER_AND_INITIA LIZER]);
1091 verify([source]);
1092 }
1093 void fail_fieldInitializerOutsideConstructor() {
1094 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " m(this.x) {}", "}"]));
1095 resolve(source, []);
1096 assertErrors([CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]);
1097 verify([source]);
1098 }
1099 void fail_finalInitializedInDeclarationAndConstructor_assignment() {
1100 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final x = 0;", " A() { x = 1; }", "}"]));
1101 resolve(source, []);
1102 assertErrors([CompileTimeErrorCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONS TRUCTOR]);
1103 verify([source]);
1104 }
1105 void fail_finalInitializedInDeclarationAndConstructor_initializingFormal() {
1106 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final x = 0;", " A(this.x) {}", "}"]));
1107 resolve(source, []);
1108 assertErrors([CompileTimeErrorCode.FINAL_INITIALIZED_IN_DECLARATION_AND_CONS TRUCTOR]);
1109 verify([source]);
1110 }
1111 void fail_finalInitializedMultipleTimes() {
1112 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final x;", " A(this.x) { x = 0; }", "}"]));
1113 resolve(source, []);
1114 assertErrors([CompileTimeErrorCode.FINAL_INITIALIZED_MULTIPLE_TIMES]);
1115 verify([source]);
1116 }
1117 void fail_finalNotInitialized_library() {
1118 Source source = addSource("/test.dart", EngineTestCase.createSource(["final F;"]));
1119 resolve(source, []);
1120 assertErrors([CompileTimeErrorCode.FINAL_NOT_INITIALIZED]);
1121 verify([source]);
1122 }
1123 void fail_finalNotInitialized_local() {
1124 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " final int x;", "}"]));
1125 resolve(source, []);
1126 assertErrors([CompileTimeErrorCode.FINAL_NOT_INITIALIZED]);
1127 verify([source]);
1128 }
1129 void fail_finalNotInitialized_static() {
1130 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static final F;", "}"]));
1131 resolve(source, []);
1132 assertErrors([CompileTimeErrorCode.FINAL_NOT_INITIALIZED]);
1133 verify([source]);
1134 }
1135 void fail_getterAndMethodWithSameName() {
1136 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " get x -> 0;", " x(y) {}", "}"]));
1137 resolve(source, []);
1138 assertErrors([CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME]);
1139 verify([source]);
1140 }
1141 void fail_implementsDynamic() {
1142 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements dynamic {}"]));
1143 resolve(source, []);
1144 assertErrors([CompileTimeErrorCode.IMPLEMENTS_DYNAMIC]);
1145 verify([source]);
1146 }
1147 void fail_implementsRepeated() {
1148 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B implements A, A {}"]));
1149 resolve(source, []);
1150 assertErrors([CompileTimeErrorCode.IMPLEMENTS_REPEATED]);
1151 verify([source]);
1152 }
1153 void fail_implementsSelf() {
1154 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements A {}"]));
1155 resolve(source, []);
1156 assertErrors([CompileTimeErrorCode.IMPLEMENTS_SELF]);
1157 verify([source]);
1158 }
1159 void fail_importDuplicatedLibraryName() {
1160 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y test;", "import 'lib1.dart';", "import 'lib2.dart';"]));
1161 addSource("/lib1.dart", EngineTestCase.createSource(["library lib;"]));
1162 addSource("/lib2.dart", EngineTestCase.createSource(["library lib;"]));
1163 resolve(source, []);
1164 assertErrors([CompileTimeErrorCode.IMPORT_DUPLICATED_LIBRARY_NAME]);
1165 verify([source]);
1166 }
1167 void fail_importOfNonLibrary() {
1168 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y lib;", "import 'part.dart';"]));
1169 addSource("/part.dart", EngineTestCase.createSource(["part of lib;"]));
1170 resolve(source, []);
1171 assertErrors([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]);
1172 verify([source]);
1173 }
1174 void fail_inconsistentCaseExpressionTypes() {
1175 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(var p) {", " switch (p) {", " case 3:", " break;", " case 'a':", " break;", " }", "}"]));
1176 resolve(source, []);
1177 assertErrors([CompileTimeErrorCode.INCONSITENT_CASE_EXPRESSION_TYPES]);
1178 verify([source]);
1179 }
1180 void fail_initializerForNonExistantField() {
1181 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A(this.x) {}", "}"]));
1182 resolve(source, []);
1183 assertErrors([CompileTimeErrorCode.INITIALIZER_FOR_NON_EXISTANT_FIELD]);
1184 verify([source]);
1185 }
1186 void fail_invalidConstructorName() {
1187 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1188 resolve(source, []);
1189 assertErrors([CompileTimeErrorCode.INVALID_CONSTRUCTOR_NAME]);
1190 verify([source]);
1191 }
1192 void fail_invalidFactoryNameNotAClass() {
1193 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1194 resolve(source, []);
1195 assertErrors([CompileTimeErrorCode.INVALID_FACTORY_NAME_NOT_A_CLASS]);
1196 verify([source]);
1197 }
1198 void fail_invalidOverrideDefaultValue() {
1199 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m([a = 0]) {}", "}", "class B extends A {", " m([a = 1]) {}", "}"]));
1200 resolve(source, []);
1201 assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_DEFAULT_VALUE]);
1202 verify([source]);
1203 }
1204 void fail_invalidOverrideNamed() {
1205 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m({a, b}) {}", "}", "class B extends A {", " m({a}) {}", "}"]));
1206 resolve(source, []);
1207 assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_NAMED]);
1208 verify([source]);
1209 }
1210 void fail_invalidOverridePositional() {
1211 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m([a, b]) {}", "}", "class B extends A {", " m([a]) {}", "}"]));
1212 resolve(source, []);
1213 assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_POSITIONAL]);
1214 verify([source]);
1215 }
1216 void fail_invalidOverrideRequired() {
1217 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a) {}", "}", "class B extends A {", " m(a, b) {}", "}"]));
1218 resolve(source, []);
1219 assertErrors([CompileTimeErrorCode.INVALID_OVERRIDE_REQUIRED]);
1220 verify([source]);
1221 }
1222 void fail_invalidReferenceToThis_staticMethod() {
1223 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static m() { return this; }", "}"]));
1224 resolve(source, []);
1225 assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
1226 verify([source]);
1227 }
1228 void fail_invalidReferenceToThis_topLevelFunction() {
1229 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() { return this; }"]));
1230 resolve(source, []);
1231 assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
1232 verify([source]);
1233 }
1234 void fail_invalidReferenceToThis_variableInitializer() {
1235 Source source = addSource("/test.dart", EngineTestCase.createSource(["int x = this;"]));
1236 resolve(source, []);
1237 assertErrors([CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]);
1238 verify([source]);
1239 }
1240 void fail_invalidTypeArgumentForKey() {
1241 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m() {", " return const <int, int>{}", " }", "}"]));
1242 resolve(source, []);
1243 assertErrors([CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_FOR_KEY]);
1244 verify([source]);
1245 }
1246 void fail_invalidTypeArgumentInConstList() {
1247 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {", " m() {", " return const <E>[]", " }", "}"]));
1248 resolve(source, []);
1249 assertErrors([CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST]);
1250 verify([source]);
1251 }
1252 void fail_invalidTypeArgumentInConstMap() {
1253 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<E> {", " m() {", " return const <String, E>{}", " }", "}"]));
1254 resolve(source, []);
1255 assertErrors([CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]);
1256 verify([source]);
1257 }
1258 void fail_invalidVariableInInitializer_nonField() {
1259 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A(this.x) {}", "}"]));
1260 resolve(source, []);
1261 assertErrors([CompileTimeErrorCode.INVALID_VARIABLE_IN_INITIALIZER]);
1262 verify([source]);
1263 }
1264 void fail_invalidVariableInInitializer_static() {
1265 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static x = 0;", " A(this.x) {}", "}"]));
1266 resolve(source, []);
1267 assertErrors([CompileTimeErrorCode.INVALID_VARIABLE_IN_INITIALIZER]);
1268 verify([source]);
1269 }
1270 void fail_memberWithClassName() {
1271 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int A = 0;", "}"]));
1272 resolve(source, []);
1273 assertErrors([CompileTimeErrorCode.MEMBER_WITH_CLASS_NAME]);
1274 verify([source]);
1275 }
1276 void fail_mixinDeclaresConstructor() {
1277 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A() {}", "}", "class B extends Object mixin A {}"]));
1278 resolve(source, []);
1279 assertErrors([CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR]);
1280 verify([source]);
1281 }
1282 void fail_mixinInheritsFromNotObject() {
1283 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class C extends Object mixin B {}"]));
1284 resolve(source, []);
1285 assertErrors([CompileTimeErrorCode.MIXIN_INHERITS_FROM_NOT_OBJECT]);
1286 verify([source]);
1287 }
1288 void fail_mixinOfNonClass() {
1289 Source source = addSource("/test.dart", EngineTestCase.createSource(["var A; ", "class B extends Object mixin A {}"]));
1290 resolve(source, []);
1291 assertErrors([CompileTimeErrorCode.MIXIN_OF_NON_CLASS]);
1292 verify([source]);
1293 }
1294 void fail_mixinOfNonMixin() {
1295 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1296 resolve(source, []);
1297 assertErrors([CompileTimeErrorCode.MIXIN_OF_NON_MIXIN]);
1298 verify([source]);
1299 }
1300 void fail_mixinReferencesSuper() {
1301 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " toString() -> super.toString();", "}", "class B extends Object mixin A {}"]));
1302 resolve(source, []);
1303 assertErrors([CompileTimeErrorCode.MIXIN_REFERENCES_SUPER]);
1304 verify([source]);
1305 }
1306 void fail_mixinWithNonClassSuperclass() {
1307 Source source = addSource("/test.dart", EngineTestCase.createSource(["int A; ", "class B extends Object mixin A {}"]));
1308 resolve(source, []);
1309 assertErrors([CompileTimeErrorCode.MIXIN_WITH_NON_CLASS_SUPERCLASS]);
1310 verify([source]);
1311 }
1312 void fail_multipleSuperInitializers() {
1313 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {", " B() : super(), super() {}", "}"]));
1314 resolve(source, []);
1315 assertErrors([CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]);
1316 verify([source]);
1317 }
1318 void fail_nonConstantDefaultValue_named() {
1319 Source source = addSource("/test.dart", EngineTestCase.createSource(["f({x : 2 + 3}) {}"]));
1320 resolve(source, []);
1321 assertErrors([CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
1322 verify([source]);
1323 }
1324 void fail_nonConstantDefaultValue_positional() {
1325 Source source = addSource("/test.dart", EngineTestCase.createSource(["f([x = 2 + 3]) {}"]));
1326 resolve(source, []);
1327 assertErrors([CompileTimeErrorCode.NON_CONSTANT_DEFAULT_VALUE]);
1328 verify([source]);
1329 }
1330 void fail_nonConstCaseExpression() {
1331 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(int p) {", " switch (p) {", " case 3 + 4:", " break;", " }", "}"]));
1332 resolve(source, []);
1333 assertErrors([CompileTimeErrorCode.NON_CONSTANT_CASE_EXPRESSION]);
1334 verify([source]);
1335 }
1336 void fail_nonConstMapAsExpressionStatement() {
1337 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " {'a' : 0, 'b' : 1};", "}"]));
1338 resolve(source, []);
1339 assertErrors([CompileTimeErrorCode.NON_CONST_MAP_AS_EXPRESSION_STATEMENT]);
1340 verify([source]);
1341 }
1342 void fail_nonConstMapKey() {
1343 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a) { ", " return const {a : 0};", "}"]));
1344 resolve(source, []);
1345 assertErrors([CompileTimeErrorCode.NON_CONSTANT_MAP_KEY]);
1346 verify([source]);
1347 }
1348 void fail_nonConstValueInInitializer() {
1349 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static C;", " int a;", " A() : a = C {}", "}"]));
1350 resolve(source, []);
1351 assertErrors([CompileTimeErrorCode.NON_CONSTANT_VALUE_IN_INITIALIZER]);
1352 verify([source]);
1353 }
1354 void fail_objectCannotExtendAnotherClass() {
1355 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1356 resolve(source, []);
1357 assertErrors([CompileTimeErrorCode.OBJECT_CANNOT_EXTEND_ANOTHER_CLASS]);
1358 verify([source]);
1359 }
1360 void fail_optionalParameterInOperator() {
1361 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " operator +([p]) {}", "}"]));
1362 resolve(source, []);
1363 assertErrors([CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]);
1364 verify([source]);
1365 }
1366 void fail_overrideMissingNamedParameters() {
1367 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a, {b}) {}", "}", "class B extends A {", " m(a) {}", "}"]));
1368 resolve(source, []);
1369 assertErrors([CompileTimeErrorCode.OVERRIDE_MISSING_NAMED_PARAMETERS]);
1370 verify([source]);
1371 }
1372 void fail_overrideMissingRequiredParameters() {
1373 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m(a) {}", "}", "class B extends A {", " m(a, b) {}", "}"]));
1374 resolve(source, []);
1375 assertErrors([CompileTimeErrorCode.OVERRIDE_MISSING_REQUIRED_PARAMETERS]);
1376 verify([source]);
1377 }
1378 void fail_partOfNonPart() {
1379 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y l1;", "part 'l2.dart';"]));
1380 addSource("/l2.dart", EngineTestCase.createSource(["library l2;"]));
1381 resolve(source, []);
1382 assertErrors([CompileTimeErrorCode.PART_OF_NON_PART]);
1383 verify([source]);
1384 }
1385 void fail_prefixCollidesWithTopLevelMembers() {
1386 Source source = addSource("/test.dart", EngineTestCase.createSource(["import 'dart:uri' as uri;", "var uri = null;"]));
1387 resolve(source, []);
1388 assertErrors([CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER]);
1389 verify([source]);
1390 }
1391 void fail_privateOptionalParameter() {
1392 Source source = addSource("/test.dart", EngineTestCase.createSource(["f({_p : 0}) {}"]));
1393 resolve(source, []);
1394 assertErrors([CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]);
1395 verify([source]);
1396 }
1397 void fail_recursiveCompileTimeConstant() {
1398 Source source = addSource("/test.dart", EngineTestCase.createSource(["const x = y + 1;", "const y = x + 1;"]));
1399 resolve(source, []);
1400 assertErrors([CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT]);
1401 verify([source]);
1402 }
1403 void fail_recursiveFactoryRedirect() {
1404 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1405 resolve(source, []);
1406 assertErrors([CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]);
1407 verify([source]);
1408 }
1409 void fail_recursiveFunctionTypeAlias_direct() {
1410 Source source = addSource("/test.dart", EngineTestCase.createSource(["typede f F(F f);"]));
1411 resolve(source, []);
1412 assertErrors([CompileTimeErrorCode.RECURSIVE_FUNCTION_TYPE_ALIAS]);
1413 verify([source]);
1414 }
1415 void fail_recursiveFunctionTypeAlias_indirect() {
1416 Source source = addSource("/test.dart", EngineTestCase.createSource(["typede f F(G g);", "typedef G(F f);"]));
1417 resolve(source, []);
1418 assertErrors([CompileTimeErrorCode.RECURSIVE_FUNCTION_TYPE_ALIAS]);
1419 verify([source]);
1420 }
1421 void fail_recursiveInterfaceInheritance_direct() {
1422 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements A {}"]));
1423 resolve(source, []);
1424 assertErrors([CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
1425 verify([source]);
1426 }
1427 void fail_recursiveInterfaceInheritance_indirect() {
1428 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A implements B {}", "class B implements A {}"]));
1429 resolve(source, []);
1430 assertErrors([CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE]);
1431 verify([source]);
1432 }
1433 void fail_redirectToNonConstConstructor() {
1434 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1435 resolve(source, []);
1436 assertErrors([CompileTimeErrorCode.REDIRECT_TO_NON_CONST_CONSTRUCTOR]);
1437 verify([source]);
1438 }
1439 void fail_referenceToDeclaredVariableInInitializer_getter() {
1440 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " int x = x + 1;", "}"]));
1441 resolve(source, []);
1442 assertErrors([CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIABLE_IN_INITIAL IZER]);
1443 verify([source]);
1444 }
1445 void fail_referenceToDeclaredVariableInInitializer_setter() {
1446 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " int x = x++;", "}"]));
1447 resolve(source, []);
1448 assertErrors([CompileTimeErrorCode.REFERENCE_TO_DECLARED_VARIABLE_IN_INITIAL IZER]);
1449 verify([source]);
1450 }
1451 void fail_reservedWordAsIdentifier() {
1452 Source source = addSource("/test.dart", EngineTestCase.createSource(["int cl ass = 2;"]));
1453 resolve(source, []);
1454 assertErrors([CompileTimeErrorCode.RESERVED_WORD_AS_IDENTIFIER]);
1455 verify([source]);
1456 }
1457 void fail_returnInGenerativeConstructor() {
1458 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A() { return 0; }", "}"]));
1459 resolve(source, []);
1460 assertErrors([CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]);
1461 verify([source]);
1462 }
1463 void fail_staticTopLevelFunction_topLevel() {
1464 Source source = addSource("/test.dart", EngineTestCase.createSource(["static f() {}"]));
1465 resolve(source, []);
1466 assertErrors([CompileTimeErrorCode.STATIC_TOP_LEVEL_FUNCTION]);
1467 verify([source]);
1468 }
1469 void fail_staticTopLevelVariable() {
1470 Source source = addSource("/test.dart", EngineTestCase.createSource(["static int x;"]));
1471 resolve(source, []);
1472 assertErrors([CompileTimeErrorCode.STATIC_TOP_LEVEL_VARIABLE]);
1473 verify([source]);
1474 }
1475 void fail_superInInvalidContext_factoryConstructor() {
1476 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1477 resolve(source, []);
1478 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1479 verify([source]);
1480 }
1481 void fail_superInInvalidContext_instanceVariableInitializer() {
1482 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var a;", "}", "class B extends A {", " var b = super.a;", "}"]));
1483 resolve(source, []);
1484 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1485 verify([source]);
1486 }
1487 void fail_superInInvalidContext_staticMethod() {
1488 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static m() {}", "}", "class B extends A {", " static n() { return supe r.m(); }", "}"]));
1489 resolve(source, []);
1490 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1491 verify([source]);
1492 }
1493 void fail_superInInvalidContext_staticVariableInitializer() {
1494 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static a = 0;", "}", "class B extends A {", " static b = super.a;", "} "]));
1495 resolve(source, []);
1496 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1497 verify([source]);
1498 }
1499 void fail_superInInvalidContext_topLevelFunction() {
1500 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " super.f();", "}"]));
1501 resolve(source, []);
1502 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1503 verify([source]);
1504 }
1505 void fail_superInInvalidContext_variableInitializer() {
1506 Source source = addSource("/test.dart", EngineTestCase.createSource(["var v = super.v;"]));
1507 resolve(source, []);
1508 assertErrors([CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT]);
1509 verify([source]);
1510 }
1511 void fail_superInitializerInObject() {
1512 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1513 resolve(source, []);
1514 assertErrors([CompileTimeErrorCode.SUPER_INITIALIZER_IN_OBJECT]);
1515 verify([source]);
1516 }
1517 void fail_throwWithoutValueOutsideOn() {
1518 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " throw;", "}"]));
1519 resolve(source, []);
1520 assertErrors([CompileTimeErrorCode.THROW_WITHOUT_VALUE_OUTSIDE_ON]);
1521 verify([source]);
1522 }
1523 void fail_typeArgumentsForNonGenericClass_creation_const() {
1524 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return const A<int>();", "}"]));
1525 resolve(source, []);
1526 assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
1527 verify([source]);
1528 }
1529 void fail_typeArgumentsForNonGenericClass_creation_new() {
1530 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return new A<int>();", "}"]));
1531 resolve(source, []);
1532 assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
1533 verify([source]);
1534 }
1535 void fail_typeArgumentsForNonGenericClass_typeCast() {
1536 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f(p) {", " return p as A<int>;", "}"]));
1537 resolve(source, []);
1538 assertErrors([CompileTimeErrorCode.TYPE_ARGUMENTS_FOR_NON_GENERIC_CLASS]);
1539 verify([source]);
1540 }
1541 void fail_undefinedConstructorInInitializer() {
1542 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
1543 resolve(source, []);
1544 assertErrors([CompileTimeErrorCode.UNDEFINED_CONSTRUCTOR_IN_INITIALIZER]);
1545 verify([source]);
1546 }
1547 void fail_uninitializedFinalField() {
1548 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int i;", "}"]));
1549 resolve(source, []);
1550 assertErrors([CompileTimeErrorCode.UNINITIALIZED_FINAL_FIELD]);
1551 verify([source]);
1552 }
1553 void fail_wrongNumberOfParametersForOperator() {
1554 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " operator []=(i) {}", "}"]));
1555 resolve(source, []);
1556 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]) ;
1557 verify([source]);
1558 }
1559 void fail_wrongNumberOfParametersForSetter_tooFew() {
1560 Source source = addSource("/test.dart", EngineTestCase.createSource(["set x( ) {}"]));
1561 resolve(source, []);
1562 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
1563 verify([source]);
1564 }
1565 void fail_wrongNumberOfParametersForSetter_tooMany() {
1566 Source source = addSource("/test.dart", EngineTestCase.createSource(["set x( a, b) {}"]));
1567 resolve(source, []);
1568 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_SETTER]);
1569 verify([source]);
1570 }
1571 void fail_wrongNumberOfTypeArguments_creation_const_tooFew() {
1572 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return const C<A>();", "}"]));
1573 resolve(source, []);
1574 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1575 verify([source]);
1576 }
1577 void fail_wrongNumberOfTypeArguments_creation_const_tooMany() {
1578 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return const C<A, A>();", "}"]));
1579 resolve(source, []);
1580 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1581 verify([source]);
1582 }
1583 void fail_wrongNumberOfTypeArguments_creation_new_tooFew() {
1584 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return new C<A>();", "}"]));
1585 resolve(source, []);
1586 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1587 verify([source]);
1588 }
1589 void fail_wrongNumberOfTypeArguments_creation_new_tooMany() {
1590 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return new C<A, A>();", "}"]));
1591 resolve(source, []);
1592 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1593 verify([source]);
1594 }
1595 void fail_wrongNumberOfTypeArguments_typeTest_tooFew() {
1596 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<K, V> {}", "f(p) {", " return p is C<A>;", "}"]));
1597 resolve(source, []);
1598 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1599 verify([source]);
1600 }
1601 void fail_wrongNumberOfTypeArguments_typeTest_tooMany() {
1602 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class C<E> {}", "f(p) {", " return p is C<A, A>;", "}"]));
1603 resolve(source, []);
1604 assertErrors([CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS]);
1605 verify([source]);
1606 }
1607 void test_argumentDefinitionTestNonParameter() {
1608 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " var v = 0;", " return ?v;", "}"]));
1609 resolve(source, []);
1610 assertErrors([CompileTimeErrorCode.ARGUMENT_DEFINITION_TEST_NON_PARAMETER]);
1611 verify([source]);
1612 }
1613 void test_builtInIdentifierAsType() {
1614 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " typedef x;", "}"]));
1615 resolve(source, []);
1616 assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE]);
1617 verify([source]);
1618 }
1619 void test_builtInIdentifierAsTypedefName_classTypeAlias() {
1620 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B {}", "typedef as = A with B;"]));
1621 resolve(source, []);
1622 assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
1623 verify([source]);
1624 }
1625 void test_builtInIdentifierAsTypedefName_functionTypeAlias() {
1626 Source source = addSource("/test.dart", EngineTestCase.createSource(["typede f bool as();"]));
1627 resolve(source, []);
1628 assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]);
1629 verify([source]);
1630 }
1631 void test_builtInIdentifierAsTypeName() {
1632 Source source = addSource("/test.dart", EngineTestCase.createSource(["class as {}"]));
1633 resolve(source, []);
1634 assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME]);
1635 verify([source]);
1636 }
1637 void test_builtInIdentifierAsTypeVariableName() {
1638 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A<as> {}"]));
1639 resolve(source, []);
1640 assertErrors([CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_VARIABLE_NAME ]);
1641 verify([source]);
1642 }
1643 void test_compileTimeConstantRaisesExceptionDivideByZero() {
1644 Source source = addSource("/test.dart", EngineTestCase.createSource(["const int INF = 0 / 0;"]));
1645 resolve(source, []);
1646 assertErrors([CompileTimeErrorCode.COMPILE_TIME_CONSTANT_RAISES_EXCEPTION_DI VIDE_BY_ZERO]);
1647 verify([source]);
1648 }
1649 void test_conflictingConstructorNameAndMember_field() {
1650 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A.x() {}", "}"]));
1651 resolve(source, []);
1652 assertErrors([CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_FIELD]);
1653 verify([source]);
1654 }
1655 void test_conflictingConstructorNameAndMember_method() {
1656 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const A.x() {}", " void x() {}", "}"]));
1657 resolve(source, []);
1658 assertErrors([CompileTimeErrorCode.CONFLICTING_CONSTRUCTOR_NAME_AND_METHOD]) ;
1659 verify([source]);
1660 }
1661 void test_constConstructorWithNonFinalField() {
1662 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " const A() {}", "}"]));
1663 resolve(source, []);
1664 assertErrors([CompileTimeErrorCode.CONST_CONSTRUCTOR_WITH_NON_FINAL_FIELD]);
1665 verify([source]);
1666 }
1667 void test_constFormalParameter_fieldFormalParameter() {
1668 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var x;", " A(const this.x) {}", "}"]));
1669 resolve(source, []);
1670 assertErrors([CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
1671 verify([source]);
1672 }
1673 void test_constFormalParameter_simpleFormalParameter() {
1674 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(cons t x) {}"]));
1675 resolve(source, []);
1676 assertErrors([CompileTimeErrorCode.CONST_FORMAL_PARAMETER]);
1677 verify([source]);
1678 }
1679 void test_constInitializedWithNonConstValue() {
1680 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(p) { ", " const C = p;", "}"]));
1681 resolve(source, []);
1682 assertErrors([CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE ]);
1683 verify([source]);
1684 }
1685 void test_constWithInvalidTypeParameters() {
1686 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const A() {}", "}", "f() { return const A<A>(); }"]));
1687 resolve(source, []);
1688 assertErrors([CompileTimeErrorCode.CONST_WITH_INVALID_TYPE_PARAMETERS]);
1689 verify([source]);
1690 }
1691 void test_duplicateMemberError() {
1692 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" library lib;", "", "part 'a.dart';", "part 'b.dart';"]));
1693 Source sourceA = addSource("/a.dart", EngineTestCase.createSource(["part of lib;", "", "class A {}"]));
1694 Source sourceB = addSource("/b.dart", EngineTestCase.createSource(["part of lib;", "", "class A {}"]));
1695 resolve(librarySource, [sourceA, sourceB]);
1696 assertErrors([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
1697 verify([librarySource, sourceA, sourceB]);
1698 }
1699 void test_extendsNonClass() {
1700 Source source = addSource("/test.dart", EngineTestCase.createSource(["int A; ", "class B extends A {}"]));
1701 resolve(source, []);
1702 assertErrors([CompileTimeErrorCode.EXTENDS_NON_CLASS]);
1703 verify([source]);
1704 }
1705 void test_implementsNonClass() {
1706 Source source = addSource("/test.dart", EngineTestCase.createSource(["int A; ", "class B implements A {}"]));
1707 resolve(source, []);
1708 assertErrors([CompileTimeErrorCode.IMPLEMENTS_NON_CLASS]);
1709 verify([source]);
1710 }
1711 void test_labelInOuterScope() {
1712 Source source = addSource("/test.dart", EngineTestCase.createSource(["class int {}", "", "class A {", " void m(int i) {", " l: while (i > 0) {", " void f() {", " break l;", " };", " }", " }", "}"]));
1713 resolve(source, []);
1714 assertErrors([CompileTimeErrorCode.LABEL_IN_OUTER_SCOPE, ResolverErrorCode.C ANNOT_BE_RESOLVED]);
1715 }
1716 void test_labelUndefined_break() {
1717 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " x: while (true) {", " break y;", " }", "}"]));
1718 resolve(source, []);
1719 assertErrors([CompileTimeErrorCode.LABEL_UNDEFINED]);
1720 }
1721 void test_labelUndefined_continue() {
1722 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " x: while (true) {", " continue y;", " }", "}"]));
1723 resolve(source, []);
1724 assertErrors([CompileTimeErrorCode.LABEL_UNDEFINED]);
1725 }
1726 void test_newWithInvalidTypeParameters() {
1727 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "f() { return new A<A>(); }"]));
1728 resolve(source, []);
1729 assertErrors([CompileTimeErrorCode.NEW_WITH_INVALID_TYPE_PARAMETERS]);
1730 verify([source]);
1731 }
1732 void test_nonConstListElement() {
1733 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a) { ", " return const [a];", "}"]));
1734 resolve(source, []);
1735 assertErrors([CompileTimeErrorCode.NON_CONSTANT_LIST_ELEMENT]);
1736 verify([source]);
1737 }
1738 void test_nonConstMapValue() {
1739 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a) { ", " return const {'a' : a};", "}"]));
1740 resolve(source, []);
1741 assertErrors([CompileTimeErrorCode.NON_CONSTANT_MAP_VALUE]);
1742 verify([source]);
1743 }
1744 void test_uriWithInterpolation_constant() {
1745 Source source = addSource("/test.dart", EngineTestCase.createSource(["import 'stuff_\$platform.dart';"]));
1746 resolve(source, []);
1747 assertErrors([CompileTimeErrorCode.URI_WITH_INTERPOLATION]);
1748 }
1749 void test_uriWithInterpolation_nonConstant() {
1750 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y lib;", "part '\${'a'}.dart';"]));
1751 resolve(source, []);
1752 assertErrors([CompileTimeErrorCode.URI_WITH_INTERPOLATION]);
1753 }
1754 static dartSuite() {
1755 _ut.group('CompileTimeErrorCodeTest', () {
1756 _ut.test('test_argumentDefinitionTestNonParameter', () {
1757 final __test = new CompileTimeErrorCodeTest();
1758 runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter);
1759 });
1760 _ut.test('test_builtInIdentifierAsType', () {
1761 final __test = new CompileTimeErrorCodeTest();
1762 runJUnitTest(__test, __test.test_builtInIdentifierAsType);
1763 });
1764 _ut.test('test_builtInIdentifierAsTypeName', () {
1765 final __test = new CompileTimeErrorCodeTest();
1766 runJUnitTest(__test, __test.test_builtInIdentifierAsTypeName);
1767 });
1768 _ut.test('test_builtInIdentifierAsTypeVariableName', () {
1769 final __test = new CompileTimeErrorCodeTest();
1770 runJUnitTest(__test, __test.test_builtInIdentifierAsTypeVariableName);
1771 });
1772 _ut.test('test_builtInIdentifierAsTypedefName_classTypeAlias', () {
1773 final __test = new CompileTimeErrorCodeTest();
1774 runJUnitTest(__test, __test.test_builtInIdentifierAsTypedefName_classTyp eAlias);
1775 });
1776 _ut.test('test_builtInIdentifierAsTypedefName_functionTypeAlias', () {
1777 final __test = new CompileTimeErrorCodeTest();
1778 runJUnitTest(__test, __test.test_builtInIdentifierAsTypedefName_function TypeAlias);
1779 });
1780 _ut.test('test_compileTimeConstantRaisesExceptionDivideByZero', () {
1781 final __test = new CompileTimeErrorCodeTest();
1782 runJUnitTest(__test, __test.test_compileTimeConstantRaisesExceptionDivid eByZero);
1783 });
1784 _ut.test('test_conflictingConstructorNameAndMember_field', () {
1785 final __test = new CompileTimeErrorCodeTest();
1786 runJUnitTest(__test, __test.test_conflictingConstructorNameAndMember_fie ld);
1787 });
1788 _ut.test('test_conflictingConstructorNameAndMember_method', () {
1789 final __test = new CompileTimeErrorCodeTest();
1790 runJUnitTest(__test, __test.test_conflictingConstructorNameAndMember_met hod);
1791 });
1792 _ut.test('test_constConstructorWithNonFinalField', () {
1793 final __test = new CompileTimeErrorCodeTest();
1794 runJUnitTest(__test, __test.test_constConstructorWithNonFinalField);
1795 });
1796 _ut.test('test_constFormalParameter_fieldFormalParameter', () {
1797 final __test = new CompileTimeErrorCodeTest();
1798 runJUnitTest(__test, __test.test_constFormalParameter_fieldFormalParamet er);
1799 });
1800 _ut.test('test_constFormalParameter_simpleFormalParameter', () {
1801 final __test = new CompileTimeErrorCodeTest();
1802 runJUnitTest(__test, __test.test_constFormalParameter_simpleFormalParame ter);
1803 });
1804 _ut.test('test_constInitializedWithNonConstValue', () {
1805 final __test = new CompileTimeErrorCodeTest();
1806 runJUnitTest(__test, __test.test_constInitializedWithNonConstValue);
1807 });
1808 _ut.test('test_constWithInvalidTypeParameters', () {
1809 final __test = new CompileTimeErrorCodeTest();
1810 runJUnitTest(__test, __test.test_constWithInvalidTypeParameters);
1811 });
1812 _ut.test('test_duplicateMemberError', () {
1813 final __test = new CompileTimeErrorCodeTest();
1814 runJUnitTest(__test, __test.test_duplicateMemberError);
1815 });
1816 _ut.test('test_extendsNonClass', () {
1817 final __test = new CompileTimeErrorCodeTest();
1818 runJUnitTest(__test, __test.test_extendsNonClass);
1819 });
1820 _ut.test('test_implementsNonClass', () {
1821 final __test = new CompileTimeErrorCodeTest();
1822 runJUnitTest(__test, __test.test_implementsNonClass);
1823 });
1824 _ut.test('test_labelInOuterScope', () {
1825 final __test = new CompileTimeErrorCodeTest();
1826 runJUnitTest(__test, __test.test_labelInOuterScope);
1827 });
1828 _ut.test('test_labelUndefined_break', () {
1829 final __test = new CompileTimeErrorCodeTest();
1830 runJUnitTest(__test, __test.test_labelUndefined_break);
1831 });
1832 _ut.test('test_labelUndefined_continue', () {
1833 final __test = new CompileTimeErrorCodeTest();
1834 runJUnitTest(__test, __test.test_labelUndefined_continue);
1835 });
1836 _ut.test('test_newWithInvalidTypeParameters', () {
1837 final __test = new CompileTimeErrorCodeTest();
1838 runJUnitTest(__test, __test.test_newWithInvalidTypeParameters);
1839 });
1840 _ut.test('test_nonConstListElement', () {
1841 final __test = new CompileTimeErrorCodeTest();
1842 runJUnitTest(__test, __test.test_nonConstListElement);
1843 });
1844 _ut.test('test_nonConstMapValue', () {
1845 final __test = new CompileTimeErrorCodeTest();
1846 runJUnitTest(__test, __test.test_nonConstMapValue);
1847 });
1848 _ut.test('test_uriWithInterpolation_constant', () {
1849 final __test = new CompileTimeErrorCodeTest();
1850 runJUnitTest(__test, __test.test_uriWithInterpolation_constant);
1851 });
1852 _ut.test('test_uriWithInterpolation_nonConstant', () {
1853 final __test = new CompileTimeErrorCodeTest();
1854 runJUnitTest(__test, __test.test_uriWithInterpolation_nonConstant);
1855 });
1856 });
1857 }
1858 }
1859 /**
1860 * Instances of the class {@code StaticTypeVerifier} verify that all of the node s in an AST
1861 * structure that should have a static type associated with them do have a stati c type.
1862 */
1863 class StaticTypeVerifier extends GeneralizingASTVisitor<Object> {
1864 /**
1865 * A list containing all of the AST Expression nodes that were not resolved.
1866 */
1867 List<Expression> _unresolvedExpressions = new List<Expression>();
1868 /**
1869 * A list containing all of the AST TypeName nodes that were not resolved.
1870 */
1871 List<TypeName> _unresolvedTypes = new List<TypeName>();
1872 /**
1873 * Counter for the number of Expression nodes visited that are resolved.
1874 */
1875 int _resolvedExpressionCount = 0;
1876 /**
1877 * Counter for the number of TypeName nodes visited that are resolved.
1878 */
1879 int _resolvedTypeCount = 0;
1880 /**
1881 * Initialize a newly created verifier to verify that all of the nodes in an A ST structure that
1882 * should have a static type associated with them do have a static type.
1883 */
1884 StaticTypeVerifier() : super() {
1885 }
1886 /**
1887 * Assert that all of the visited nodes have a static type associated with the m.
1888 */
1889 void assertResolved() {
1890 if (!_unresolvedExpressions.isEmpty || !_unresolvedTypes.isEmpty) {
1891 int unresolvedExpressionCount = _unresolvedExpressions.length;
1892 int unresolvedTypeCount = _unresolvedTypes.length;
1893 PrintStringWriter writer = new PrintStringWriter();
1894 writer.print("Failed to associate types with nodes: ");
1895 writer.print(unresolvedExpressionCount);
1896 writer.print("/");
1897 writer.print(_resolvedExpressionCount + unresolvedExpressionCount);
1898 writer.print(" Expressions and ");
1899 writer.print(unresolvedTypeCount);
1900 writer.print("/");
1901 writer.print(_resolvedTypeCount + unresolvedTypeCount);
1902 writer.printlnObject(" TypeNames.");
1903 if (unresolvedTypeCount > 0) {
1904 writer.printlnObject("TypeNames:");
1905 for (TypeName identifier in _unresolvedTypes) {
1906 writer.print(" ");
1907 writer.print(identifier.toString());
1908 writer.print(" (");
1909 writer.print(getFileName(identifier));
1910 writer.print(" : ");
1911 writer.print(identifier.offset);
1912 writer.printlnObject(")");
1913 }
1914 }
1915 if (unresolvedExpressionCount > 0) {
1916 writer.printlnObject("Expressions:");
1917 for (Expression identifier in _unresolvedExpressions) {
1918 writer.print(" ");
1919 writer.print(identifier.toString());
1920 writer.print(" (");
1921 writer.print(getFileName(identifier));
1922 writer.print(" : ");
1923 writer.print(identifier.offset);
1924 writer.printlnObject(")");
1925 }
1926 }
1927 JUnitTestCase.fail(writer.toString());
1928 }
1929 }
1930 Object visitCommentReference(CommentReference node) => null;
1931 Object visitExpression(Expression node) {
1932 node.visitChildren(this);
1933 if (node.staticType == null) {
1934 _unresolvedExpressions.add(node);
1935 } else {
1936 _resolvedExpressionCount++;
1937 }
1938 return null;
1939 }
1940 Object visitLibraryIdentifier(LibraryIdentifier node) => null;
1941 Object visitPrefixedIdentifier(PrefixedIdentifier node) {
1942 if (node.staticType == null && identical(node.prefix.staticType, DynamicType Impl.instance)) {
1943 return null;
1944 }
1945 return super.visitPrefixedIdentifier(node);
1946 }
1947 Object visitSimpleIdentifier(SimpleIdentifier node) {
1948 ASTNode parent19 = node.parent;
1949 if (parent19 is MethodInvocation && identical(node, ((parent19 as MethodInvo cation)).methodName)) {
1950 return null;
1951 } else if (parent19 is RedirectingConstructorInvocation && identical(node, ( (parent19 as RedirectingConstructorInvocation)).constructorName)) {
1952 return null;
1953 } else if (parent19 is SuperConstructorInvocation && identical(node, ((paren t19 as SuperConstructorInvocation)).constructorName)) {
1954 return null;
1955 } else if (parent19 is ConstructorName && identical(node, ((parent19 as Cons tructorName)).name)) {
1956 return null;
1957 } else if (parent19 is Label && identical(node, ((parent19 as Label)).label) ) {
1958 return null;
1959 } else if (parent19 is ImportDirective && identical(node, ((parent19 as Impo rtDirective)).prefix)) {
1960 return null;
1961 } else if (node.element is PrefixElement) {
1962 return null;
1963 }
1964 return super.visitSimpleIdentifier(node);
1965 }
1966 Object visitTypeName(TypeName node) {
1967 if (node.type == null) {
1968 _unresolvedTypes.add(node);
1969 } else {
1970 _resolvedTypeCount++;
1971 }
1972 return null;
1973 }
1974 String getFileName(ASTNode node) {
1975 if (node != null) {
1976 ASTNode root3 = node.root;
1977 if (root3 is CompilationUnit) {
1978 CompilationUnit rootCU = (root3 as CompilationUnit);
1979 if (rootCU.element != null) {
1980 return rootCU.element.source.fullName;
1981 } else {
1982 return "<unknown file- CompilationUnit.getElement() returned null>";
1983 }
1984 } else {
1985 return "<unknown file- CompilationUnit.getRoot() is not a CompilationUni t>";
1986 }
1987 }
1988 return "<unknown file- ASTNode is null>";
1989 }
1990 }
1991 class ElementResolverTest extends EngineTestCase {
1992 /**
1993 * The error listener to which errors will be reported.
1994 */
1995 GatheringErrorListener _listener;
1996 /**
1997 * The type provider used to access the types.
1998 */
1999 TestTypeProvider _typeProvider;
2000 /**
2001 * The library containing the code being resolved.
2002 */
2003 LibraryElementImpl _definingLibrary;
2004 /**
2005 * The resolver visitor that maintains the state for the resolver.
2006 */
2007 ResolverVisitor _visitor;
2008 /**
2009 * The resolver being used to resolve the test cases.
2010 */
2011 ElementResolver _resolver;
2012 void fail_visitExportDirective_combinators() {
2013 JUnitTestCase.fail("Not yet tested");
2014 ExportDirective directive = ASTFactory.exportDirective2(null, [ASTFactory.hi deCombinator2(["A"])]);
2015 resolveNode(directive, []);
2016 _listener.assertNoErrors();
2017 }
2018 void fail_visitFunctionExpressionInvocation() {
2019 JUnitTestCase.fail("Not yet tested");
2020 _listener.assertNoErrors();
2021 }
2022 void fail_visitImportDirective_combinators_noPrefix() {
2023 JUnitTestCase.fail("Not yet tested");
2024 ImportDirective directive = ASTFactory.importDirective2(null, null, [ASTFact ory.showCombinator2(["A"])]);
2025 resolveNode(directive, []);
2026 _listener.assertNoErrors();
2027 }
2028 void fail_visitImportDirective_combinators_prefix() {
2029 JUnitTestCase.fail("Not yet tested");
2030 String prefixName = "p";
2031 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E lementFactory.prefix(prefixName), [])];
2032 ImportDirective directive = ASTFactory.importDirective2(null, prefixName, [A STFactory.showCombinator2(["A"]), ASTFactory.hideCombinator2(["B"])]);
2033 resolveNode(directive, []);
2034 _listener.assertNoErrors();
2035 }
2036 void fail_visitRedirectingConstructorInvocation() {
2037 JUnitTestCase.fail("Not yet tested");
2038 _listener.assertNoErrors();
2039 }
2040 void setUp() {
2041 _listener = new GatheringErrorListener();
2042 _typeProvider = new TestTypeProvider();
2043 _resolver = createResolver();
2044 }
2045 void test_visitAssignmentExpression_compound() {
2046 InterfaceType intType2 = _typeProvider.intType;
2047 SimpleIdentifier leftHandSide = ASTFactory.identifier2("a");
2048 leftHandSide.staticType = intType2;
2049 AssignmentExpression assignment = ASTFactory.assignmentExpression(leftHandSi de, TokenType.PLUS_EQ, ASTFactory.integer(1));
2050 resolveNode(assignment, []);
2051 JUnitTestCase.assertSame(getMethod(_typeProvider.numType, "+"), assignment.e lement);
2052 _listener.assertNoErrors();
2053 }
2054 void test_visitAssignmentExpression_simple() {
2055 AssignmentExpression expression = ASTFactory.assignmentExpression(ASTFactory .identifier2("x"), TokenType.EQ, ASTFactory.integer(0));
2056 resolveNode(expression, []);
2057 JUnitTestCase.assertNull(expression.element);
2058 _listener.assertNoErrors();
2059 }
2060 void test_visitBinaryExpression() {
2061 InterfaceType numType2 = _typeProvider.numType;
2062 SimpleIdentifier left = ASTFactory.identifier2("i");
2063 left.staticType = numType2;
2064 BinaryExpression expression = ASTFactory.binaryExpression(left, TokenType.PL US, ASTFactory.identifier2("j"));
2065 resolveNode(expression, []);
2066 JUnitTestCase.assertEquals(getMethod(numType2, "+"), expression.element);
2067 _listener.assertNoErrors();
2068 }
2069 void test_visitBreakStatement_withLabel() {
2070 String label = "loop";
2071 LabelElementImpl labelElement = new LabelElementImpl(ASTFactory.identifier2( label), false, false);
2072 BreakStatement statement = ASTFactory.breakStatement2(label);
2073 JUnitTestCase.assertSame(labelElement, resolve(statement, labelElement));
2074 _listener.assertNoErrors();
2075 }
2076 void test_visitBreakStatement_withoutLabel() {
2077 BreakStatement statement = ASTFactory.breakStatement();
2078 resolveStatement(statement, null);
2079 _listener.assertNoErrors();
2080 }
2081 void test_visitConstructorName_named() {
2082 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2083 String constructorName = "a";
2084 ConstructorElement constructor = ElementFactory.constructorElement(construct orName);
2085 classA.constructors = <ConstructorElement> [constructor];
2086 ConstructorName name = ASTFactory.constructorName(ASTFactory.typeName(classA , []), constructorName);
2087 resolveNode(name, []);
2088 JUnitTestCase.assertSame(constructor, name.element);
2089 _listener.assertNoErrors();
2090 }
2091 void test_visitConstructorName_unnamed() {
2092 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2093 String constructorName = null;
2094 ConstructorElement constructor = ElementFactory.constructorElement(construct orName);
2095 classA.constructors = <ConstructorElement> [constructor];
2096 ConstructorName name = ASTFactory.constructorName(ASTFactory.typeName(classA , []), constructorName);
2097 resolveNode(name, []);
2098 JUnitTestCase.assertSame(constructor, name.element);
2099 _listener.assertNoErrors();
2100 }
2101 void test_visitContinueStatement_withLabel() {
2102 String label = "loop";
2103 LabelElementImpl labelElement = new LabelElementImpl(ASTFactory.identifier2( label), false, false);
2104 ContinueStatement statement = ASTFactory.continueStatement2(label);
2105 JUnitTestCase.assertSame(labelElement, resolve2(statement, labelElement));
2106 _listener.assertNoErrors();
2107 }
2108 void test_visitContinueStatement_withoutLabel() {
2109 ContinueStatement statement = ASTFactory.continueStatement();
2110 resolveStatement(statement, null);
2111 _listener.assertNoErrors();
2112 }
2113 void test_visitExportDirective_noCombinators() {
2114 ExportDirective directive = ASTFactory.exportDirective2(null, []);
2115 directive.element = ElementFactory.exportFor(ElementFactory.library(_definin gLibrary.context, "lib"), []);
2116 resolveNode(directive, []);
2117 _listener.assertNoErrors();
2118 }
2119 void test_visitImportDirective_noCombinators_noPrefix() {
2120 ImportDirective directive = ASTFactory.importDirective2(null, null, []);
2121 directive.element = ElementFactory.importFor(ElementFactory.library(_definin gLibrary.context, "lib"), null, []);
2122 resolveNode(directive, []);
2123 _listener.assertNoErrors();
2124 }
2125 void test_visitImportDirective_noCombinators_prefix() {
2126 String prefixName = "p";
2127 ImportElement importElement = ElementFactory.importFor(ElementFactory.librar y(_definingLibrary.context, "lib"), ElementFactory.prefix(prefixName), []);
2128 _definingLibrary.imports = <ImportElement> [importElement];
2129 ImportDirective directive = ASTFactory.importDirective2(null, prefixName, [] );
2130 directive.element = importElement;
2131 resolveNode(directive, []);
2132 _listener.assertNoErrors();
2133 }
2134 void test_visitIndexExpression_get() {
2135 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2136 InterfaceType intType3 = _typeProvider.intType;
2137 MethodElement getter = ElementFactory.methodElement("[]", intType3, [intType 3]);
2138 classA.methods = <MethodElement> [getter];
2139 SimpleIdentifier array = ASTFactory.identifier2("a");
2140 array.staticType = classA.type;
2141 IndexExpression expression = ASTFactory.indexExpression(array, ASTFactory.id entifier2("i"));
2142 JUnitTestCase.assertSame(getter, resolve4(expression, []));
2143 _listener.assertNoErrors();
2144 }
2145 void test_visitIndexExpression_set() {
2146 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2147 InterfaceType intType4 = _typeProvider.intType;
2148 MethodElement setter = ElementFactory.methodElement("[]=", intType4, [intTyp e4]);
2149 classA.methods = <MethodElement> [setter];
2150 SimpleIdentifier array = ASTFactory.identifier2("a");
2151 array.staticType = classA.type;
2152 IndexExpression expression = ASTFactory.indexExpression(array, ASTFactory.id entifier2("i"));
2153 ASTFactory.assignmentExpression(expression, TokenType.EQ, ASTFactory.integer (0));
2154 JUnitTestCase.assertSame(setter, resolve4(expression, []));
2155 _listener.assertNoErrors();
2156 }
2157 void test_visitInstanceCreationExpression_named() {
2158 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2159 String constructorName = "a";
2160 ConstructorElement constructor = ElementFactory.constructorElement(construct orName);
2161 classA.constructors = <ConstructorElement> [constructor];
2162 ConstructorName name = ASTFactory.constructorName(ASTFactory.typeName(classA , []), constructorName);
2163 name.element = constructor;
2164 InstanceCreationExpression creation = ASTFactory.instanceCreationExpression( Keyword.NEW, name, []);
2165 resolveNode(creation, []);
2166 JUnitTestCase.assertSame(constructor, creation.element);
2167 _listener.assertNoErrors();
2168 }
2169 void test_visitInstanceCreationExpression_unnamed() {
2170 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2171 String constructorName = null;
2172 ConstructorElement constructor = ElementFactory.constructorElement(construct orName);
2173 classA.constructors = <ConstructorElement> [constructor];
2174 ConstructorName name = ASTFactory.constructorName(ASTFactory.typeName(classA , []), constructorName);
2175 name.element = constructor;
2176 InstanceCreationExpression creation = ASTFactory.instanceCreationExpression( Keyword.NEW, name, []);
2177 resolveNode(creation, []);
2178 JUnitTestCase.assertSame(constructor, creation.element);
2179 _listener.assertNoErrors();
2180 }
2181 void test_visitInstanceCreationExpression_unnamed_namedParameter() {
2182 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2183 String constructorName = null;
2184 ConstructorElementImpl constructor = ElementFactory.constructorElement(const ructorName);
2185 String parameterName = "a";
2186 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
2187 constructor.parameters = <ParameterElement> [parameter];
2188 classA.constructors = <ConstructorElement> [constructor];
2189 ConstructorName name = ASTFactory.constructorName(ASTFactory.typeName(classA , []), constructorName);
2190 name.element = constructor;
2191 InstanceCreationExpression creation = ASTFactory.instanceCreationExpression( Keyword.NEW, name, [ASTFactory.namedExpression(parameterName, ASTFactory.integer (0))]);
2192 resolveNode(creation, []);
2193 JUnitTestCase.assertSame(constructor, creation.element);
2194 JUnitTestCase.assertSame(parameter, ((creation.argumentList.arguments[0] as NamedExpression)).name.label.element);
2195 _listener.assertNoErrors();
2196 }
2197 void test_visitMethodInvocation() {
2198 InterfaceType numType3 = _typeProvider.numType;
2199 SimpleIdentifier left = ASTFactory.identifier2("i");
2200 left.staticType = numType3;
2201 String methodName = "abs";
2202 MethodInvocation invocation = ASTFactory.methodInvocation(left, methodName, []);
2203 resolveNode(invocation, []);
2204 JUnitTestCase.assertSame(getMethod(numType3, methodName), invocation.methodN ame.element);
2205 _listener.assertNoErrors();
2206 }
2207 void test_visitMethodInvocation_namedParameter() {
2208 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2209 String methodName = "m";
2210 String parameterName = "p";
2211 MethodElementImpl method = ElementFactory.methodElement(methodName, null, [] );
2212 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
2213 method.parameters = <ParameterElement> [parameter];
2214 classA.methods = <MethodElement> [method];
2215 SimpleIdentifier left = ASTFactory.identifier2("i");
2216 left.staticType = classA.type;
2217 MethodInvocation invocation = ASTFactory.methodInvocation(left, methodName, [ASTFactory.namedExpression(parameterName, ASTFactory.integer(0))]);
2218 resolveNode(invocation, []);
2219 JUnitTestCase.assertSame(method, invocation.methodName.element);
2220 JUnitTestCase.assertSame(parameter, ((invocation.argumentList.arguments[0] a s NamedExpression)).name.label.element);
2221 _listener.assertNoErrors();
2222 }
2223 void test_visitPostfixExpression() {
2224 InterfaceType numType4 = _typeProvider.numType;
2225 SimpleIdentifier operand = ASTFactory.identifier2("i");
2226 operand.staticType = numType4;
2227 PostfixExpression expression = ASTFactory.postfixExpression(operand, TokenTy pe.PLUS_PLUS);
2228 resolveNode(expression, []);
2229 JUnitTestCase.assertEquals(getMethod(numType4, "+"), expression.element);
2230 _listener.assertNoErrors();
2231 }
2232 void test_visitPrefixedIdentifier_dynamic() {
2233 Type2 dynamicType2 = _typeProvider.dynamicType;
2234 SimpleIdentifier target = ASTFactory.identifier2("a");
2235 VariableElementImpl variable = ElementFactory.localVariableElement(target);
2236 variable.type = dynamicType2;
2237 target.element = variable;
2238 target.staticType = dynamicType2;
2239 PrefixedIdentifier identifier5 = ASTFactory.identifier(target, ASTFactory.id entifier2("b"));
2240 resolveNode(identifier5, []);
2241 JUnitTestCase.assertNull(identifier5.element);
2242 JUnitTestCase.assertNull(identifier5.identifier.element);
2243 _listener.assertNoErrors();
2244 }
2245 void test_visitPrefixedIdentifier_nonDynamic() {
2246 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2247 String getterName = "b";
2248 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
2249 classA.accessors = <PropertyAccessorElement> [getter];
2250 SimpleIdentifier target = ASTFactory.identifier2("a");
2251 VariableElementImpl variable = ElementFactory.localVariableElement(target);
2252 variable.type = classA.type;
2253 target.element = variable;
2254 target.staticType = classA.type;
2255 PrefixedIdentifier identifier6 = ASTFactory.identifier(target, ASTFactory.id entifier2(getterName));
2256 resolveNode(identifier6, []);
2257 JUnitTestCase.assertSame(getter, identifier6.element);
2258 JUnitTestCase.assertSame(getter, identifier6.identifier.element);
2259 _listener.assertNoErrors();
2260 }
2261 void test_visitPrefixExpression() {
2262 InterfaceType numType5 = _typeProvider.numType;
2263 SimpleIdentifier operand = ASTFactory.identifier2("i");
2264 operand.staticType = numType5;
2265 PrefixExpression expression = ASTFactory.prefixExpression(TokenType.PLUS_PLU S, operand);
2266 resolveNode(expression, []);
2267 JUnitTestCase.assertEquals(getMethod(numType5, "+"), expression.element);
2268 _listener.assertNoErrors();
2269 }
2270 void test_visitPropertyAccess_getter_identifier() {
2271 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2272 String getterName = "b";
2273 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
2274 classA.accessors = <PropertyAccessorElement> [getter];
2275 SimpleIdentifier target = ASTFactory.identifier2("a");
2276 target.staticType = classA.type;
2277 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName);
2278 resolveNode(access, []);
2279 JUnitTestCase.assertSame(getter, access.propertyName.element);
2280 _listener.assertNoErrors();
2281 }
2282 void test_visitPropertyAccess_getter_super() {
2283 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2284 String getterName = "b";
2285 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa lse, _typeProvider.intType);
2286 classA.accessors = <PropertyAccessorElement> [getter];
2287 SuperExpression target = ASTFactory.superExpression();
2288 target.staticType = classA.type;
2289 PropertyAccess access = ASTFactory.propertyAccess2(target, getterName);
2290 resolveNode(access, []);
2291 JUnitTestCase.assertSame(getter, access.propertyName.element);
2292 _listener.assertNoErrors();
2293 }
2294 void test_visitPropertyAccess_setter_this() {
2295 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2296 String setterName = "b";
2297 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa lse, _typeProvider.intType);
2298 classA.accessors = <PropertyAccessorElement> [setter];
2299 ThisExpression target = ASTFactory.thisExpression();
2300 target.staticType = classA.type;
2301 PropertyAccess access = ASTFactory.propertyAccess2(target, setterName);
2302 ASTFactory.assignmentExpression(access, TokenType.EQ, ASTFactory.integer(0)) ;
2303 resolveNode(access, []);
2304 JUnitTestCase.assertSame(setter, access.propertyName.element);
2305 _listener.assertNoErrors();
2306 }
2307 void test_visitSimpleIdentifier_classScope() {
2308 InterfaceType doubleType2 = _typeProvider.doubleType;
2309 String fieldName = "NAN";
2310 SimpleIdentifier node = ASTFactory.identifier2(fieldName);
2311 resolveInClass(node, doubleType2.element);
2312 JUnitTestCase.assertEquals(getGetter(doubleType2, fieldName), node.element);
2313 _listener.assertNoErrors();
2314 }
2315 void test_visitSimpleIdentifier_lexicalScope() {
2316 SimpleIdentifier node = ASTFactory.identifier2("i");
2317 VariableElementImpl element = ElementFactory.localVariableElement(node);
2318 JUnitTestCase.assertSame(element, resolve3(node, [element]));
2319 _listener.assertNoErrors();
2320 }
2321 void test_visitSimpleIdentifier_lexicalScope_field_setter() {
2322 InterfaceType intType5 = _typeProvider.intType;
2323 ClassElementImpl classA = ElementFactory.classElement2("A", []);
2324 String fieldName = "a";
2325 FieldElement field = ElementFactory.fieldElement(fieldName, false, false, fa lse, intType5);
2326 classA.fields = <FieldElement> [field];
2327 classA.accessors = <PropertyAccessorElement> [field.getter, field.setter];
2328 SimpleIdentifier node = ASTFactory.identifier2(fieldName);
2329 ASTFactory.assignmentExpression(node, TokenType.EQ, ASTFactory.integer(0));
2330 resolveInClass(node, classA);
2331 Element element47 = node.element;
2332 EngineTestCase.assertInstanceOf(PropertyAccessorElement, element47);
2333 JUnitTestCase.assertTrue(((element47 as PropertyAccessorElement)).isSetter() );
2334 _listener.assertNoErrors();
2335 }
2336 void test_visitSuperConstructorInvocation() {
2337 ClassElementImpl superclass = ElementFactory.classElement2("A", []);
2338 ConstructorElementImpl superConstructor = ElementFactory.constructorElement( null);
2339 superclass.constructors = <ConstructorElement> [superConstructor];
2340 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type , []);
2341 ConstructorElementImpl subConstructor = ElementFactory.constructorElement(nu ll);
2342 subclass.constructors = <ConstructorElement> [subConstructor];
2343 SuperConstructorInvocation invocation = ASTFactory.superConstructorInvocatio n([]);
2344 resolveInClass(invocation, subclass);
2345 JUnitTestCase.assertEquals(superConstructor, invocation.element);
2346 _listener.assertNoErrors();
2347 }
2348 void test_visitSuperConstructorInvocation_namedParameter() {
2349 ClassElementImpl superclass = ElementFactory.classElement2("A", []);
2350 ConstructorElementImpl superConstructor = ElementFactory.constructorElement( null);
2351 String parameterName = "p";
2352 ParameterElement parameter = ElementFactory.namedParameter(parameterName);
2353 superConstructor.parameters = <ParameterElement> [parameter];
2354 superclass.constructors = <ConstructorElement> [superConstructor];
2355 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type , []);
2356 ConstructorElementImpl subConstructor = ElementFactory.constructorElement(nu ll);
2357 subclass.constructors = <ConstructorElement> [subConstructor];
2358 SuperConstructorInvocation invocation = ASTFactory.superConstructorInvocatio n([ASTFactory.namedExpression(parameterName, ASTFactory.integer(0))]);
2359 resolveInClass(invocation, subclass);
2360 JUnitTestCase.assertEquals(superConstructor, invocation.element);
2361 JUnitTestCase.assertSame(parameter, ((invocation.argumentList.arguments[0] a s NamedExpression)).name.label.element);
2362 _listener.assertNoErrors();
2363 }
2364 /**
2365 * Create the resolver used by the tests.
2366 * @return the resolver that was created
2367 */
2368 ElementResolver createResolver() {
2369 AnalysisContextImpl context = new AnalysisContextImpl();
2370 SourceFactory sourceFactory = new SourceFactory.con2([new DartUriResolver(Da rtSdk.defaultSdk)]);
2371 context.sourceFactory = sourceFactory;
2372 CompilationUnitElementImpl definingCompilationUnit = new CompilationUnitElem entImpl("test.dart");
2373 definingCompilationUnit.source = new FileBasedSource.con1(sourceFactory, Fil eUtilities2.createFile("/test.dart"));
2374 _definingLibrary = ElementFactory.library(context, "test");
2375 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
2376 Library library = new Library(context, _listener, null);
2377 library.libraryElement = _definingLibrary;
2378 _visitor = new ResolverVisitor(library, null, _typeProvider);
2379 try {
2380 return _visitor.elementResolver_J2DAccessor as ElementResolver;
2381 } on JavaException catch (exception) {
2382 throw new IllegalArgumentException("Could not create resolver", exception) ;
2383 }
2384 }
2385 /**
2386 * Return the element associated with the label of the given statement after t he resolver has
2387 * resolved the statement.
2388 * @param statement the statement to be resolved
2389 * @param labelElement the label element to be defined in the statement's labe l scope
2390 * @return the element to which the statement's label was resolved
2391 */
2392 Element resolve(BreakStatement statement, LabelElementImpl labelElement) {
2393 resolveStatement(statement, labelElement);
2394 return statement.label.element;
2395 }
2396 /**
2397 * Return the element associated with the label of the given statement after t he resolver has
2398 * resolved the statement.
2399 * @param statement the statement to be resolved
2400 * @param labelElement the label element to be defined in the statement's labe l scope
2401 * @return the element to which the statement's label was resolved
2402 */
2403 Element resolve2(ContinueStatement statement, LabelElementImpl labelElement) {
2404 resolveStatement(statement, labelElement);
2405 return statement.label.element;
2406 }
2407 /**
2408 * Return the element associated with the given identifier after the resolver has resolved the
2409 * identifier.
2410 * @param node the expression to be resolved
2411 * @param definedElements the elements that are to be defined in the scope in which the element is
2412 * being resolved
2413 * @return the element to which the expression was resolved
2414 */
2415 Element resolve3(Identifier node, List<Element> definedElements) {
2416 resolveNode(node, definedElements);
2417 return node.element;
2418 }
2419 /**
2420 * Return the element associated with the given expression after the resolver has resolved the
2421 * expression.
2422 * @param node the expression to be resolved
2423 * @param definedElements the elements that are to be defined in the scope in which the element is
2424 * being resolved
2425 * @return the element to which the expression was resolved
2426 */
2427 Element resolve4(IndexExpression node, List<Element> definedElements) {
2428 resolveNode(node, definedElements);
2429 return node.element;
2430 }
2431 /**
2432 * Return the element associated with the given identifier after the resolver has resolved the
2433 * identifier.
2434 * @param node the expression to be resolved
2435 * @param enclosingClass the element representing the class enclosing the iden tifier
2436 * @return the element to which the expression was resolved
2437 */
2438 void resolveInClass(ASTNode node, ClassElement enclosingClass) {
2439 try {
2440 Scope outerScope = _visitor.nameScope_J2DAccessor as Scope;
2441 try {
2442 _visitor.enclosingClass_J2DAccessor = enclosingClass;
2443 EnclosedScope innerScope = new ClassScope(outerScope, enclosingClass);
2444 _visitor.nameScope_J2DAccessor = innerScope;
2445 node.accept(_resolver);
2446 } finally {
2447 _visitor.enclosingClass_J2DAccessor = null;
2448 _visitor.nameScope_J2DAccessor = outerScope;
2449 }
2450 } on JavaException catch (exception) {
2451 throw new IllegalArgumentException("Could not resolve node", exception);
2452 }
2453 }
2454 /**
2455 * Return the element associated with the given identifier after the resolver has resolved the
2456 * identifier.
2457 * @param node the expression to be resolved
2458 * @param definedElements the elements that are to be defined in the scope in which the element is
2459 * being resolved
2460 * @return the element to which the expression was resolved
2461 */
2462 void resolveNode(ASTNode node, List<Element> definedElements) {
2463 try {
2464 Scope outerScope = _visitor.nameScope_J2DAccessor as Scope;
2465 try {
2466 EnclosedScope innerScope = new EnclosedScope(outerScope);
2467 for (Element element in definedElements) {
2468 innerScope.define(element);
2469 }
2470 _visitor.nameScope_J2DAccessor = innerScope;
2471 node.accept(_resolver);
2472 } finally {
2473 _visitor.nameScope_J2DAccessor = outerScope;
2474 }
2475 } on JavaException catch (exception) {
2476 throw new IllegalArgumentException("Could not resolve node", exception);
2477 }
2478 }
2479 /**
2480 * Return the element associated with the label of the given statement after t he resolver has
2481 * resolved the statement.
2482 * @param statement the statement to be resolved
2483 * @param labelElement the label element to be defined in the statement's labe l scope
2484 * @return the element to which the statement's label was resolved
2485 */
2486 void resolveStatement(Statement statement, LabelElementImpl labelElement) {
2487 try {
2488 LabelScope outerScope = _visitor.labelScope_J2DAccessor as LabelScope;
2489 try {
2490 LabelScope innerScope;
2491 if (labelElement == null) {
2492 innerScope = new LabelScope.con1(outerScope, false, false);
2493 } else {
2494 innerScope = new LabelScope.con2(outerScope, labelElement.name, labelE lement);
2495 }
2496 _visitor.labelScope_J2DAccessor = innerScope;
2497 statement.accept(_resolver);
2498 } finally {
2499 _visitor.labelScope_J2DAccessor = outerScope;
2500 }
2501 } on JavaException catch (exception) {
2502 throw new IllegalArgumentException("Could not resolve node", exception);
2503 }
2504 }
2505 static dartSuite() {
2506 _ut.group('ElementResolverTest', () {
2507 _ut.test('test_visitAssignmentExpression_compound', () {
2508 final __test = new ElementResolverTest();
2509 runJUnitTest(__test, __test.test_visitAssignmentExpression_compound);
2510 });
2511 _ut.test('test_visitAssignmentExpression_simple', () {
2512 final __test = new ElementResolverTest();
2513 runJUnitTest(__test, __test.test_visitAssignmentExpression_simple);
2514 });
2515 _ut.test('test_visitBinaryExpression', () {
2516 final __test = new ElementResolverTest();
2517 runJUnitTest(__test, __test.test_visitBinaryExpression);
2518 });
2519 _ut.test('test_visitBreakStatement_withLabel', () {
2520 final __test = new ElementResolverTest();
2521 runJUnitTest(__test, __test.test_visitBreakStatement_withLabel);
2522 });
2523 _ut.test('test_visitBreakStatement_withoutLabel', () {
2524 final __test = new ElementResolverTest();
2525 runJUnitTest(__test, __test.test_visitBreakStatement_withoutLabel);
2526 });
2527 _ut.test('test_visitConstructorName_named', () {
2528 final __test = new ElementResolverTest();
2529 runJUnitTest(__test, __test.test_visitConstructorName_named);
2530 });
2531 _ut.test('test_visitConstructorName_unnamed', () {
2532 final __test = new ElementResolverTest();
2533 runJUnitTest(__test, __test.test_visitConstructorName_unnamed);
2534 });
2535 _ut.test('test_visitContinueStatement_withLabel', () {
2536 final __test = new ElementResolverTest();
2537 runJUnitTest(__test, __test.test_visitContinueStatement_withLabel);
2538 });
2539 _ut.test('test_visitContinueStatement_withoutLabel', () {
2540 final __test = new ElementResolverTest();
2541 runJUnitTest(__test, __test.test_visitContinueStatement_withoutLabel);
2542 });
2543 _ut.test('test_visitExportDirective_noCombinators', () {
2544 final __test = new ElementResolverTest();
2545 runJUnitTest(__test, __test.test_visitExportDirective_noCombinators);
2546 });
2547 _ut.test('test_visitImportDirective_noCombinators_noPrefix', () {
2548 final __test = new ElementResolverTest();
2549 runJUnitTest(__test, __test.test_visitImportDirective_noCombinators_noPr efix);
2550 });
2551 _ut.test('test_visitImportDirective_noCombinators_prefix', () {
2552 final __test = new ElementResolverTest();
2553 runJUnitTest(__test, __test.test_visitImportDirective_noCombinators_pref ix);
2554 });
2555 _ut.test('test_visitIndexExpression_get', () {
2556 final __test = new ElementResolverTest();
2557 runJUnitTest(__test, __test.test_visitIndexExpression_get);
2558 });
2559 _ut.test('test_visitIndexExpression_set', () {
2560 final __test = new ElementResolverTest();
2561 runJUnitTest(__test, __test.test_visitIndexExpression_set);
2562 });
2563 _ut.test('test_visitInstanceCreationExpression_named', () {
2564 final __test = new ElementResolverTest();
2565 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_named);
2566 });
2567 _ut.test('test_visitInstanceCreationExpression_unnamed', () {
2568 final __test = new ElementResolverTest();
2569 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_unnamed );
2570 });
2571 _ut.test('test_visitInstanceCreationExpression_unnamed_namedParameter', () {
2572 final __test = new ElementResolverTest();
2573 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_unnamed _namedParameter);
2574 });
2575 _ut.test('test_visitMethodInvocation', () {
2576 final __test = new ElementResolverTest();
2577 runJUnitTest(__test, __test.test_visitMethodInvocation);
2578 });
2579 _ut.test('test_visitMethodInvocation_namedParameter', () {
2580 final __test = new ElementResolverTest();
2581 runJUnitTest(__test, __test.test_visitMethodInvocation_namedParameter);
2582 });
2583 _ut.test('test_visitPostfixExpression', () {
2584 final __test = new ElementResolverTest();
2585 runJUnitTest(__test, __test.test_visitPostfixExpression);
2586 });
2587 _ut.test('test_visitPrefixExpression', () {
2588 final __test = new ElementResolverTest();
2589 runJUnitTest(__test, __test.test_visitPrefixExpression);
2590 });
2591 _ut.test('test_visitPrefixedIdentifier_dynamic', () {
2592 final __test = new ElementResolverTest();
2593 runJUnitTest(__test, __test.test_visitPrefixedIdentifier_dynamic);
2594 });
2595 _ut.test('test_visitPrefixedIdentifier_nonDynamic', () {
2596 final __test = new ElementResolverTest();
2597 runJUnitTest(__test, __test.test_visitPrefixedIdentifier_nonDynamic);
2598 });
2599 _ut.test('test_visitPropertyAccess_getter_identifier', () {
2600 final __test = new ElementResolverTest();
2601 runJUnitTest(__test, __test.test_visitPropertyAccess_getter_identifier);
2602 });
2603 _ut.test('test_visitPropertyAccess_getter_super', () {
2604 final __test = new ElementResolverTest();
2605 runJUnitTest(__test, __test.test_visitPropertyAccess_getter_super);
2606 });
2607 _ut.test('test_visitPropertyAccess_setter_this', () {
2608 final __test = new ElementResolverTest();
2609 runJUnitTest(__test, __test.test_visitPropertyAccess_setter_this);
2610 });
2611 _ut.test('test_visitSimpleIdentifier_classScope', () {
2612 final __test = new ElementResolverTest();
2613 runJUnitTest(__test, __test.test_visitSimpleIdentifier_classScope);
2614 });
2615 _ut.test('test_visitSimpleIdentifier_lexicalScope', () {
2616 final __test = new ElementResolverTest();
2617 runJUnitTest(__test, __test.test_visitSimpleIdentifier_lexicalScope);
2618 });
2619 _ut.test('test_visitSimpleIdentifier_lexicalScope_field_setter', () {
2620 final __test = new ElementResolverTest();
2621 runJUnitTest(__test, __test.test_visitSimpleIdentifier_lexicalScope_fiel d_setter);
2622 });
2623 _ut.test('test_visitSuperConstructorInvocation', () {
2624 final __test = new ElementResolverTest();
2625 runJUnitTest(__test, __test.test_visitSuperConstructorInvocation);
2626 });
2627 _ut.test('test_visitSuperConstructorInvocation_namedParameter', () {
2628 final __test = new ElementResolverTest();
2629 runJUnitTest(__test, __test.test_visitSuperConstructorInvocation_namedPa rameter);
2630 });
2631 });
2632 }
2633 }
2634 class StaticWarningCodeTest extends ResolverTestCase {
2635 void fail_argumentTypeNotAssignable() {
2636 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2637 resolve(source, []);
2638 assertErrors([StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]);
2639 verify([source]);
2640 }
2641 void fail_assignmentToFinal() {
2642 Source source = addSource("/test.dart", EngineTestCase.createSource(["final x = 0;", "f() { x = 1; }"]));
2643 resolve(source, []);
2644 assertErrors([StaticWarningCode.ASSIGNMENT_TO_FINAL]);
2645 verify([source]);
2646 }
2647 void fail_caseBlockNotTerminated() {
2648 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(int p) {", " switch (p) {", " case 0:", " f(p);", " case 1:", " bre ak;", " }", "}"]));
2649 resolve(source, []);
2650 assertErrors([StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]);
2651 verify([source]);
2652 }
2653 void fail_castToNonType() {
2654 Source source = addSource("/test.dart", EngineTestCase.createSource(["var A = 0;", "f(String s) { var x = s as A; }"]));
2655 resolve(source, []);
2656 assertErrors([StaticWarningCode.CAST_TO_NON_TYPE]);
2657 verify([source]);
2658 }
2659 void fail_commentReferenceConstructorNotVisible() {
2660 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2661 resolve(source, []);
2662 assertErrors([StaticWarningCode.COMMENT_REFERENCE_CONSTRUCTOR_NOT_VISIBLE]);
2663 verify([source]);
2664 }
2665 void fail_commentReferenceIdentifierNotVisible() {
2666 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2667 resolve(source, []);
2668 assertErrors([StaticWarningCode.COMMENT_REFERENCE_IDENTIFIER_NOT_VISIBLE]);
2669 verify([source]);
2670 }
2671 void fail_commentReferenceUndeclaredConstructor() {
2672 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2673 resolve(source, []);
2674 assertErrors([StaticWarningCode.COMMENT_REFERENCE_UNDECLARED_CONSTRUCTOR]);
2675 verify([source]);
2676 }
2677 void fail_commentReferenceUndeclaredIdentifier() {
2678 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2679 resolve(source, []);
2680 assertErrors([StaticWarningCode.COMMENT_REFERENCE_UNDECLARED_IDENTIFIER]);
2681 verify([source]);
2682 }
2683 void fail_commentReferenceUriNotLibrary() {
2684 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2685 resolve(source, []);
2686 assertErrors([StaticWarningCode.COMMENT_REFERENCE_URI_NOT_LIBRARY]);
2687 verify([source]);
2688 }
2689 void fail_concreteClassWithAbstractMember() {
2690 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m();", "}"]));
2691 resolve(source, []);
2692 assertErrors([StaticWarningCode.CONCRETE_CLASS_WITH_ABSTRACT_MEMBER]);
2693 verify([source]);
2694 }
2695 void fail_conflictingInstanceGetterAndSuperclassMember() {
2696 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2697 resolve(source, []);
2698 assertErrors([StaticWarningCode.CONFLICTING_INSTANCE_GETTER_AND_SUPERCLASS_M EMBER]);
2699 verify([source]);
2700 }
2701 void fail_conflictingInstanceSetterAndSuperclassMember() {
2702 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2703 resolve(source, []);
2704 assertErrors([StaticWarningCode.CONFLICTING_INSTANCE_SETTER_AND_SUPERCLASS_M EMBER]);
2705 verify([source]);
2706 }
2707 void fail_conflictingStaticGetterAndInstanceSetter() {
2708 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static get x -> 0;", " set x(int p) {}", "}"]));
2709 resolve(source, []);
2710 assertErrors([StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTE R]);
2711 verify([source]);
2712 }
2713 void fail_conflictingStaticSetterAndInstanceGetter() {
2714 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " get x -> 0;", " static set x(int p) {}", "}"]));
2715 resolve(source, []);
2716 assertErrors([StaticWarningCode.CONFLICTING_STATIC_SETTER_AND_INSTANCE_GETTE R]);
2717 verify([source]);
2718 }
2719 void fail_fieldInitializerWithInvalidType() {
2720 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int x;", " A(String this.x) {}", "}"]));
2721 resolve(source, []);
2722 assertErrors([StaticWarningCode.FIELD_INITIALIZER_WITH_INVALID_TYPE]);
2723 verify([source]);
2724 }
2725 void fail_incorrectNumberOfArguments_tooFew() {
2726 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a, b ) -> 0;", "g() {", " f(2);", "}"]));
2727 resolve(source, []);
2728 assertErrors([StaticWarningCode.INCORRECT_NUMBER_OF_ARGUMENTS]);
2729 verify([source]);
2730 }
2731 void fail_incorrectNumberOfArguments_tooMany() {
2732 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(a, b ) -> 0;", "g() {", " f(2, 3, 4);", "}"]));
2733 resolve(source, []);
2734 assertErrors([StaticWarningCode.INCORRECT_NUMBER_OF_ARGUMENTS]);
2735 verify([source]);
2736 }
2737 void fail_instanceMethodNameCollidesWithSuperclassStatic() {
2738 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static n", "}", "class C extends A {", " void n() {}", "}"]));
2739 resolve(source, []);
2740 assertErrors([StaticWarningCode.INSTANCE_METHOD_NAME_COLLIDES_WITH_SUPERCLAS S_STATIC]);
2741 verify([source]);
2742 }
2743 void fail_invalidFactoryName() {
2744 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2745 resolve(source, []);
2746 assertErrors([StaticWarningCode.INVALID_FACTORY_NAME]);
2747 verify([source]);
2748 }
2749 void fail_invalidOverrideGetterType() {
2750 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int get g -> 0", "}", "class B extends A {", " String get g { return ' a'; }", "}"]));
2751 resolve(source, []);
2752 assertErrors([StaticWarningCode.INVALID_OVERRIDE_GETTER_TYPE]);
2753 verify([source]);
2754 }
2755 void fail_invalidOverrideReturnType() {
2756 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int m() { return 0; }", "}", "class B extends A {", " String m() { ret urn 'a'; }", "}"]));
2757 resolve(source, []);
2758 assertErrors([StaticWarningCode.INVALID_OVERRIDE_RETURN_TYPE]);
2759 verify([source]);
2760 }
2761 void fail_invalidOverrideSetterReturnType() {
2762 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void set s(int v) {}", "}", "class B extends A {", " void set s(String v) {}", "}"]));
2763 resolve(source, []);
2764 assertErrors([StaticWarningCode.INVALID_OVERRIDE_SETTER_RETURN_TYPE]);
2765 verify([source]);
2766 }
2767 void fail_invocationOfNonFunction() {
2768 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2769 resolve(source, []);
2770 assertErrors([StaticWarningCode.INVOCATION_OF_NON_FUNCTION]);
2771 verify([source]);
2772 }
2773 void fail_mismatchedGetterAndSetterTypes() {
2774 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int get g { return 0; }", " set g(String v) {}", "}"]));
2775 resolve(source, []);
2776 assertErrors([StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES]);
2777 verify([source]);
2778 }
2779 void fail_newWithNonType() {
2780 Source source = addSource("/test.dart", EngineTestCase.createSource(["var A = 0;", "void f() {", " A a = new A();", "}"]));
2781 resolve(source, []);
2782 assertErrors([StaticWarningCode.NEW_WITH_NON_TYPE]);
2783 verify([source]);
2784 }
2785 void fail_newWithUndefinedConstructor() {
2786 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A(int p) {}", "}", "A f() {", " return new A();", "}"]));
2787 resolve(source, []);
2788 assertErrors([StaticWarningCode.NEW_WITH_UNDEFINED_CONSTRUCTOR]);
2789 verify([source]);
2790 }
2791 void fail_nonAbstractClassInheritsAbstractMember() {
2792 Source source = addSource("/test.dart", EngineTestCase.createSource(["class I {", " m(p) {}", "}", "class C implements I {", "}"]));
2793 resolve(source, []);
2794 assertErrors([StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER] );
2795 verify([source]);
2796 }
2797 void fail_nonAbstractClassInheritsAbstractMethod() {
2798 Source source = addSource("/test.dart", EngineTestCase.createSource(["abstra ct class A {", " m(p);", "}", "class C extends A {", "}"]));
2799 resolve(source, []);
2800 assertErrors([StaticWarningCode.NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_METHOD] );
2801 verify([source]);
2802 }
2803 void fail_nonType() {
2804 Source source = addSource("/test.dart", EngineTestCase.createSource(["var A = 0;", "f(var p) {", " if (p is A) {", " }", "}"]));
2805 resolve(source, []);
2806 assertErrors([StaticWarningCode.NON_TYPE]);
2807 verify([source]);
2808 }
2809 void fail_nonTypeInCatchClause() {
2810 Source source = addSource("/test.dart", EngineTestCase.createSource(["var T = 0;", "f(var p) {", " try {", " } on T catch e {", " }", "}"]));
2811 resolve(source, []);
2812 assertErrors([StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE]);
2813 verify([source]);
2814 }
2815 void fail_nonVoidReturnForOperator() {
2816 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int operator []=() {}", "}"]));
2817 resolve(source, []);
2818 assertErrors([StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]);
2819 verify([source]);
2820 }
2821 void fail_nonVoidReturnForSetter() {
2822 Source source = addSource("/test.dart", EngineTestCase.createSource(["int se t x(int v) {", " var s = x;", " x = v;", " return s;", "}"]));
2823 resolve(source, []);
2824 assertErrors([StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]);
2825 verify([source]);
2826 }
2827 void fail_overrideNotSubtype() {
2828 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int m() {}", "}", "class B extends A {", " String m() {}", "}"]));
2829 resolve(source, []);
2830 assertErrors([StaticWarningCode.OVERRIDE_NOT_SUBTYPE]);
2831 verify([source]);
2832 }
2833 void fail_overrideWithDifferentDefault() {
2834 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " m([int p = 0]) {}", "}", "class B extends A {", " m([int p = 1]) {}", "}"]));
2835 resolve(source, []);
2836 assertErrors([StaticWarningCode.OVERRIDE_WITH_DIFFERENT_DEFAULT]);
2837 verify([source]);
2838 }
2839 void fail_redirectToInvalidReturnType() {
2840 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2841 resolve(source, []);
2842 assertErrors([StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE]);
2843 verify([source]);
2844 }
2845 void fail_redirectToMissingConstructor() {
2846 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2847 resolve(source, []);
2848 assertErrors([StaticWarningCode.REDIRECT_TO_MISSING_CONSTRUCTOR]);
2849 verify([source]);
2850 }
2851 void fail_redirectToNonClass() {
2852 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2853 resolve(source, []);
2854 assertErrors([StaticWarningCode.REDIRECT_TO_NON_CLASS]);
2855 verify([source]);
2856 }
2857 void fail_returnWithoutValue() {
2858 Source source = addSource("/test.dart", EngineTestCase.createSource(["int f( ) { return; }"]));
2859 resolve(source, []);
2860 assertErrors([StaticWarningCode.RETURN_WITHOUT_VALUE]);
2861 verify([source]);
2862 }
2863 void fail_switchExpressionNotAssignable() {
2864 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(int p) {", " switch (p) {", " case 'a': break;", " }", "}"]));
2865 resolve(source, []);
2866 assertErrors([StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE]);
2867 verify([source]);
2868 }
2869 void fail_undefinedClass() {
2870 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() { C.m(); }"]));
2871 resolve(source, []);
2872 assertErrors([StaticWarningCode.UNDEFINED_CLASS]);
2873 verify([source]);
2874 }
2875 void fail_undefinedGetter() {
2876 Source source = addSource("/test.dart", EngineTestCase.createSource([]));
2877 resolve(source, []);
2878 assertErrors([StaticWarningCode.UNDEFINED_GETTER]);
2879 verify([source]);
2880 }
2881 void fail_undefinedIdentifier_function() {
2882 Source source = addSource("/test.dart", EngineTestCase.createSource(["int a( ) -> b;"]));
2883 resolve(source, []);
2884 assertErrors([StaticWarningCode.UNDEFINED_IDENTIFIER]);
2885 verify([source]);
2886 }
2887 void fail_undefinedIdentifier_initializer() {
2888 Source source = addSource("/test.dart", EngineTestCase.createSource(["var a = b;"]));
2889 resolve(source, []);
2890 assertErrors([StaticWarningCode.UNDEFINED_IDENTIFIER]);
2891 verify([source]);
2892 }
2893 void fail_undefinedSetter() {
2894 Source source = addSource("/test.dart", EngineTestCase.createSource(["class C {}", "f(var p) {", " C.m = 0;", "}"]));
2895 resolve(source, []);
2896 assertErrors([StaticWarningCode.UNDEFINED_SETTER]);
2897 verify([source]);
2898 }
2899 void fail_undefinedStaticMethodOrGetter_getter() {
2900 Source source = addSource("/test.dart", EngineTestCase.createSource(["class C {}", "f(var p) {", " f(C.m);", "}"]));
2901 resolve(source, []);
2902 assertErrors([StaticWarningCode.UNDEFINED_STATIC_METHOD_OR_GETTER]);
2903 verify([source]);
2904 }
2905 void fail_undefinedStaticMethodOrGetter_method() {
2906 Source source = addSource("/test.dart", EngineTestCase.createSource(["class C {}", "f(var p) {", " f(C.m());", "}"]));
2907 resolve(source, []);
2908 assertErrors([StaticWarningCode.UNDEFINED_STATIC_METHOD_OR_GETTER]);
2909 verify([source]);
2910 }
2911 void test_constWithAbstractClass() {
2912 Source source = addSource("/test.dart", EngineTestCase.createSource(["abstra ct class A {}", "void f() {", " A a = const A();", "}"]));
2913 resolve(source, []);
2914 assertErrors([StaticWarningCode.CONST_WITH_ABSTRACT_CLASS]);
2915 verify([source]);
2916 }
2917 void test_equalKeysInMap() {
2918 Source source = addSource("/test.dart", EngineTestCase.createSource(["var m = {'a' : 0, 'b' : 1, 'a' : 2};"]));
2919 resolve(source, []);
2920 assertErrors([StaticWarningCode.EQUAL_KEYS_IN_MAP]);
2921 verify([source]);
2922 }
2923 void test_newWithAbstractClass() {
2924 Source source = addSource("/test.dart", EngineTestCase.createSource(["abstra ct class A {}", "void f() {", " A a = new A();", "}"]));
2925 resolve(source, []);
2926 assertErrors([StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]);
2927 verify([source]);
2928 }
2929 void test_partOfDifferentLibrary() {
2930 Source source = addSource("/test.dart", EngineTestCase.createSource(["librar y lib;", "part 'part.dart';"]));
2931 addSource("/part.dart", EngineTestCase.createSource(["part of lub;"]));
2932 resolve(source, []);
2933 assertErrors([StaticWarningCode.PART_OF_DIFFERENT_LIBRARY]);
2934 verify([source]);
2935 }
2936 static dartSuite() {
2937 _ut.group('StaticWarningCodeTest', () {
2938 _ut.test('test_constWithAbstractClass', () {
2939 final __test = new StaticWarningCodeTest();
2940 runJUnitTest(__test, __test.test_constWithAbstractClass);
2941 });
2942 _ut.test('test_equalKeysInMap', () {
2943 final __test = new StaticWarningCodeTest();
2944 runJUnitTest(__test, __test.test_equalKeysInMap);
2945 });
2946 _ut.test('test_newWithAbstractClass', () {
2947 final __test = new StaticWarningCodeTest();
2948 runJUnitTest(__test, __test.test_newWithAbstractClass);
2949 });
2950 _ut.test('test_partOfDifferentLibrary', () {
2951 final __test = new StaticWarningCodeTest();
2952 runJUnitTest(__test, __test.test_partOfDifferentLibrary);
2953 });
2954 });
2955 }
2956 }
2957 class ErrorResolverTest extends ResolverTestCase {
2958 void test_breakLabelOnSwitchMember() {
2959 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m(int i) {", " switch (i) {", " l: case 0:", " brea k;", " case 1:", " break l;", " }", " }", "}"]));
2960 resolve(source, []);
2961 assertErrors([ResolverErrorCode.BREAK_LABEL_ON_SWITCH_MEMBER]);
2962 verify([source]);
2963 }
2964 void test_continueLabelOnSwitch() {
2965 Source source = addSource("/a.dart", EngineTestCase.createSource(["class A { ", " void m(int i) {", " l: switch (i) {", " case 0:", " continu e l;", " }", " }", "}"]));
2966 resolve(source, []);
2967 assertErrors([ResolverErrorCode.CONTINUE_LABEL_ON_SWITCH]);
2968 verify([source]);
2969 }
2970 static dartSuite() {
2971 _ut.group('ErrorResolverTest', () {
2972 _ut.test('test_breakLabelOnSwitchMember', () {
2973 final __test = new ErrorResolverTest();
2974 runJUnitTest(__test, __test.test_breakLabelOnSwitchMember);
2975 });
2976 _ut.test('test_continueLabelOnSwitch', () {
2977 final __test = new ErrorResolverTest();
2978 runJUnitTest(__test, __test.test_continueLabelOnSwitch);
2979 });
2980 });
2981 }
2982 }
2983 /**
2984 * The class {@code AnalysisContextFactory} defines utility methods used to crea te analysis contexts
2985 * for testing purposes.
2986 */
2987 class AnalysisContextFactory {
2988 /**
2989 * Create an analysis context that has a fake core library already resolved.
2990 * @return the analysis context that was created
2991 */
2992 static AnalysisContextImpl contextWithCore() {
2993 AnalysisContextImpl context = new AnalysisContextImpl();
2994 SourceFactory sourceFactory = new SourceFactory.con2([new DartUriResolver(Da rtSdk.defaultSdk), new FileUriResolver()]);
2995 context.sourceFactory = sourceFactory;
2996 TestTypeProvider provider = new TestTypeProvider();
2997 CompilationUnitElementImpl unit = new CompilationUnitElementImpl("core.dart" );
2998 unit.types = <ClassElement> [provider.boolType.element, provider.doubleType. element, provider.functionType.element, provider.intType.element, provider.listT ype.element, provider.mapType.element, provider.numType.element, provider.object Type.element, provider.stackTraceType.element, provider.stringType.element, prov ider.typeType.element];
2999 LibraryElementImpl library = new LibraryElementImpl(context, ASTFactory.libr aryIdentifier2(["dart", "core"]));
3000 library.definingCompilationUnit = unit;
3001 Map<Source, LibraryElement> elementMap = new Map<Source, LibraryElement>();
3002 Source coreSource = sourceFactory.forUri(DartSdk.DART_CORE);
3003 elementMap[coreSource] = library;
3004 context.recordLibraryElements(elementMap);
3005 unit.source = coreSource;
3006 return context;
3007 }
3008 /**
3009 * Prevent the creation of instances of this class.
3010 */
3011 AnalysisContextFactory() {
3012 }
3013 }
3014 /**
3015 * Instances of the class {@code TestTypeProvider} implement a type provider tha t can be used by
3016 * tests without creating the element model for the core library.
3017 */
3018 class TestTypeProvider implements TypeProvider {
3019 /**
3020 * The type representing the built-in type 'bool'.
3021 */
3022 InterfaceType _boolType;
3023 /**
3024 * The type representing the type 'bottom'.
3025 */
3026 Type2 _bottomType;
3027 /**
3028 * The type representing the built-in type 'double'.
3029 */
3030 InterfaceType _doubleType;
3031 /**
3032 * The type representing the built-in type 'dynamic'.
3033 */
3034 Type2 _dynamicType;
3035 /**
3036 * The type representing the built-in type 'Function'.
3037 */
3038 InterfaceType _functionType;
3039 /**
3040 * The type representing the built-in type 'int'.
3041 */
3042 InterfaceType _intType;
3043 /**
3044 * The type representing the built-in type 'List'.
3045 */
3046 InterfaceType _listType;
3047 /**
3048 * The type representing the built-in type 'Map'.
3049 */
3050 InterfaceType _mapType;
3051 /**
3052 * The type representing the built-in type 'num'.
3053 */
3054 InterfaceType _numType;
3055 /**
3056 * The type representing the built-in type 'Object'.
3057 */
3058 InterfaceType _objectType;
3059 /**
3060 * The type representing the built-in type 'StackTrace'.
3061 */
3062 InterfaceType _stackTraceType;
3063 /**
3064 * The type representing the built-in type 'String'.
3065 */
3066 InterfaceType _stringType;
3067 /**
3068 * The type representing the built-in type 'Type'.
3069 */
3070 InterfaceType _typeType;
3071 /**
3072 * Initialize a newly created type provider to provide stand-ins for the types defined in the core
3073 * library.
3074 */
3075 TestTypeProvider() : super() {
3076 }
3077 InterfaceType get boolType {
3078 if (_boolType == null) {
3079 _boolType = ElementFactory.classElement2("bool", []).type;
3080 }
3081 return _boolType;
3082 }
3083 Type2 get bottomType {
3084 if (_bottomType == null) {
3085 _bottomType = BottomTypeImpl.instance;
3086 }
3087 return _bottomType;
3088 }
3089 InterfaceType get doubleType {
3090 if (_doubleType == null) {
3091 initializeNumericTypes();
3092 }
3093 return _doubleType;
3094 }
3095 Type2 get dynamicType {
3096 if (_dynamicType == null) {
3097 _dynamicType = DynamicTypeImpl.instance;
3098 }
3099 return _dynamicType;
3100 }
3101 InterfaceType get functionType {
3102 if (_functionType == null) {
3103 _functionType = ElementFactory.classElement2("Function", []).type;
3104 }
3105 return _functionType;
3106 }
3107 InterfaceType get intType {
3108 if (_intType == null) {
3109 initializeNumericTypes();
3110 }
3111 return _intType;
3112 }
3113 InterfaceType get listType {
3114 if (_listType == null) {
3115 ClassElementImpl listElement = ElementFactory.classElement2("List", ["E"]) ;
3116 _listType = listElement.type;
3117 Type2 eType = listElement.typeVariables[0].type;
3118 listElement.methods = <MethodElement> [ElementFactory.methodElement("[]", eType, [_intType]), ElementFactory.methodElement("[]=", VoidTypeImpl.instance, [ _intType, eType])];
3119 }
3120 return _listType;
3121 }
3122 InterfaceType get mapType {
3123 if (_mapType == null) {
3124 _mapType = ElementFactory.classElement2("Map", ["K", "V"]).type;
3125 }
3126 return _mapType;
3127 }
3128 InterfaceType get numType {
3129 if (_numType == null) {
3130 initializeNumericTypes();
3131 }
3132 return _numType;
3133 }
3134 InterfaceType get objectType {
3135 if (_objectType == null) {
3136 ClassElementImpl objectElement = ElementFactory.object;
3137 _objectType = objectElement.type;
3138 if (objectElement.methods.length == 0) {
3139 objectElement.methods = <MethodElement> [ElementFactory.methodElement("t oString", stringType, []), ElementFactory.methodElement("==", _boolType, [_objec tType])];
3140 objectElement.accessors = <PropertyAccessorElement> [ElementFactory.gett erElement("hashCode", false, intType)];
3141 }
3142 }
3143 return _objectType;
3144 }
3145 InterfaceType get stackTraceType {
3146 if (_stackTraceType == null) {
3147 _stackTraceType = ElementFactory.classElement2("StackTrace", []).type;
3148 }
3149 return _stackTraceType;
3150 }
3151 InterfaceType get stringType {
3152 if (_stringType == null) {
3153 _stringType = ElementFactory.classElement2("String", []).type;
3154 ClassElementImpl stringElement = _stringType.element as ClassElementImpl;
3155 stringElement.accessors = <PropertyAccessorElement> [ElementFactory.getter Element("length", false, intType)];
3156 }
3157 return _stringType;
3158 }
3159 InterfaceType get typeType {
3160 if (_typeType == null) {
3161 _typeType = ElementFactory.classElement2("Type", []).type;
3162 }
3163 return _typeType;
3164 }
3165 /**
3166 * Initialize the numeric types. They are created as a group so that we can (a ) create the right
3167 * hierarchy and (b) add members to them.
3168 */
3169 void initializeNumericTypes() {
3170 ClassElementImpl numElement = ElementFactory.classElement2("num", []);
3171 _numType = numElement.type;
3172 ClassElementImpl intElement = ElementFactory.classElement("int", _numType, [ ]);
3173 _intType = intElement.type;
3174 ClassElementImpl doubleElement = ElementFactory.classElement("double", _numT ype, []);
3175 _doubleType = doubleElement.type;
3176 boolType;
3177 stringType;
3178 numElement.methods = <MethodElement> [ElementFactory.methodElement("+", _num Type, [_numType]), ElementFactory.methodElement("-", _numType, [_numType]), Elem entFactory.methodElement("*", _numType, [_numType]), ElementFactory.methodElemen t("%", _numType, [_numType]), ElementFactory.methodElement("/", _doubleType, [_n umType]), ElementFactory.methodElement("~/", _numType, [_numType]), ElementFacto ry.methodElement("-", _numType, []), ElementFactory.methodElement("remainder", _ numType, [_numType]), ElementFactory.methodElement("<", _boolType, [_numType]), ElementFactory.methodElement("<=", _boolType, [_numType]), ElementFactory.method Element(">", _boolType, [_numType]), ElementFactory.methodElement(">=", _boolTyp e, [_numType]), ElementFactory.methodElement("isNaN", _boolType, []), ElementFac tory.methodElement("isNegative", _boolType, []), ElementFactory.methodElement("i sInfinite", _boolType, []), ElementFactory.methodElement("abs", _numType, []), E lementFactory.methodElement("floor", _numType, []), ElementFactory.methodElement ("ceil", _numType, []), ElementFactory.methodElement("round", _numType, []), Ele mentFactory.methodElement("truncate", _numType, []), ElementFactory.methodElemen t("toInt", _intType, []), ElementFactory.methodElement("toDouble", _doubleType, []), ElementFactory.methodElement("toStringAsFixed", _stringType, [_intType]), E lementFactory.methodElement("toStringAsExponential", _stringType, [_intType]), E lementFactory.methodElement("toStringAsPrecision", _stringType, [_intType]), Ele mentFactory.methodElement("toRadixString", _stringType, [_intType])];
3179 intElement.methods = <MethodElement> [ElementFactory.methodElement("&", _int Type, [_intType]), ElementFactory.methodElement("|", _intType, [_intType]), Elem entFactory.methodElement("^", _intType, [_intType]), ElementFactory.methodElemen t("~", _intType, []), ElementFactory.methodElement("<<", _intType, [_intType]), ElementFactory.methodElement(">>", _intType, [_intType]), ElementFactory.methodE lement("-", _intType, []), ElementFactory.methodElement("abs", _intType, []), El ementFactory.methodElement("round", _intType, []), ElementFactory.methodElement( "floor", _intType, []), ElementFactory.methodElement("ceil", _intType, []), Elem entFactory.methodElement("truncate", _intType, []), ElementFactory.methodElement ("toString", _stringType, [])];
3180 List<FieldElement> fields = <FieldElement> [ElementFactory.fieldElement("NAN ", true, false, true, _doubleType), ElementFactory.fieldElement("INFINITY", true , false, true, _doubleType), ElementFactory.fieldElement("NEGATIVE_INFINITY", tr ue, false, true, _doubleType), ElementFactory.fieldElement("MIN_POSITIVE", true, false, true, _doubleType), ElementFactory.fieldElement("MAX_FINITE", true, fals e, true, _doubleType)];
3181 doubleElement.fields = fields;
3182 int fieldCount = fields.length;
3183 List<PropertyAccessorElement> accessors = new List<PropertyAccessorElement>( fieldCount);
3184 for (int i = 0; i < fieldCount; i++) {
3185 accessors[i] = fields[i].getter;
3186 }
3187 doubleElement.accessors = accessors;
3188 doubleElement.methods = <MethodElement> [ElementFactory.methodElement("remai nder", _doubleType, [_numType]), ElementFactory.methodElement("+", _doubleType, [_numType]), ElementFactory.methodElement("-", _doubleType, [_numType]), Element Factory.methodElement("*", _doubleType, [_numType]), ElementFactory.methodElemen t("%", _doubleType, [_numType]), ElementFactory.methodElement("/", _doubleType, [_numType]), ElementFactory.methodElement("~/", _doubleType, [_numType]), Elemen tFactory.methodElement("-", _doubleType, []), ElementFactory.methodElement("abs" , _doubleType, []), ElementFactory.methodElement("round", _doubleType, []), Elem entFactory.methodElement("floor", _doubleType, []), ElementFactory.methodElement ("ceil", _doubleType, []), ElementFactory.methodElement("truncate", _doubleType, []), ElementFactory.methodElement("toString", _stringType, [])];
3189 }
3190 }
3191 class LibraryImportScopeTest extends ResolverTestCase {
3192 void test_conflictingImports() {
3193 AnalysisContext context = new AnalysisContextImpl();
3194 String typeNameA = "A";
3195 String typeNameB = "B";
3196 String typeNameC = "C";
3197 ClassElement typeA = new ClassElementImpl(ASTFactory.identifier2(typeNameA)) ;
3198 ClassElement typeB1 = new ClassElementImpl(ASTFactory.identifier2(typeNameB) );
3199 ClassElement typeB2 = new ClassElementImpl(ASTFactory.identifier2(typeNameB) );
3200 ClassElement typeC = new ClassElementImpl(ASTFactory.identifier2(typeNameC)) ;
3201 LibraryElement importedLibrary1 = createTestLibrary2(context, "imported1", [ ]);
3202 ((importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl)).t ypes = <ClassElement> [typeA, typeB1];
3203 ImportElementImpl import1 = new ImportElementImpl();
3204 import1.importedLibrary = importedLibrary1;
3205 LibraryElement importedLibrary2 = createTestLibrary2(context, "imported2", [ ]);
3206 ((importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl)).t ypes = <ClassElement> [typeB2, typeC];
3207 ImportElementImpl import2 = new ImportElementImpl();
3208 import2.importedLibrary = importedLibrary2;
3209 LibraryElementImpl importingLibrary = createTestLibrary2(context, "importing ", []);
3210 importingLibrary.imports = <ImportElement> [import1, import2];
3211 GatheringErrorListener errorListener = new GatheringErrorListener();
3212 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
3213 JUnitTestCase.assertEquals(typeA, scope.lookup3(typeNameA, importingLibrary) );
3214 errorListener.assertNoErrors();
3215 JUnitTestCase.assertEquals(typeC, scope.lookup3(typeNameC, importingLibrary) );
3216 errorListener.assertNoErrors();
3217 Element element = scope.lookup3(typeNameB, importingLibrary);
3218 errorListener.assertNoErrors();
3219 EngineTestCase.assertInstanceOf(MultiplyDefinedElement, element);
3220 List<Element> conflictingElements2 = ((element as MultiplyDefinedElement)).c onflictingElements;
3221 JUnitTestCase.assertEquals(typeB1, conflictingElements2[0]);
3222 JUnitTestCase.assertEquals(typeB2, conflictingElements2[1]);
3223 JUnitTestCase.assertEquals(2, conflictingElements2.length);
3224 }
3225 void test_creation_empty() {
3226 LibraryElement definingLibrary = createTestLibrary();
3227 GatheringErrorListener errorListener = new GatheringErrorListener();
3228 new LibraryImportScope(definingLibrary, errorListener);
3229 }
3230 void test_creation_nonEmpty() {
3231 AnalysisContext context = new AnalysisContextImpl();
3232 String importedTypeName = "A";
3233 ClassElement importedType = new ClassElementImpl(ASTFactory.identifier2(impo rtedTypeName));
3234 LibraryElement importedLibrary = createTestLibrary2(context, "imported", []) ;
3235 ((importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)).ty pes = <ClassElement> [importedType];
3236 LibraryElementImpl definingLibrary = createTestLibrary2(context, "importing" , []);
3237 ImportElementImpl importElement = new ImportElementImpl();
3238 importElement.importedLibrary = importedLibrary;
3239 definingLibrary.imports = <ImportElement> [importElement];
3240 GatheringErrorListener errorListener = new GatheringErrorListener();
3241 Scope scope = new LibraryImportScope(definingLibrary, errorListener);
3242 JUnitTestCase.assertEquals(importedType, scope.lookup3(importedTypeName, def iningLibrary));
3243 }
3244 void test_getDefiningLibrary() {
3245 LibraryElement definingLibrary = createTestLibrary();
3246 GatheringErrorListener errorListener = new GatheringErrorListener();
3247 Scope scope = new LibraryImportScope(definingLibrary, errorListener);
3248 JUnitTestCase.assertEquals(definingLibrary, scope.definingLibrary);
3249 }
3250 void test_getErrorListener() {
3251 LibraryElement definingLibrary = createTestLibrary();
3252 GatheringErrorListener errorListener = new GatheringErrorListener();
3253 Scope scope = new LibraryImportScope(definingLibrary, errorListener);
3254 JUnitTestCase.assertEquals(errorListener, scope.errorListener);
3255 }
3256 static dartSuite() {
3257 _ut.group('LibraryImportScopeTest', () {
3258 _ut.test('test_conflictingImports', () {
3259 final __test = new LibraryImportScopeTest();
3260 runJUnitTest(__test, __test.test_conflictingImports);
3261 });
3262 _ut.test('test_creation_empty', () {
3263 final __test = new LibraryImportScopeTest();
3264 runJUnitTest(__test, __test.test_creation_empty);
3265 });
3266 _ut.test('test_creation_nonEmpty', () {
3267 final __test = new LibraryImportScopeTest();
3268 runJUnitTest(__test, __test.test_creation_nonEmpty);
3269 });
3270 _ut.test('test_getDefiningLibrary', () {
3271 final __test = new LibraryImportScopeTest();
3272 runJUnitTest(__test, __test.test_getDefiningLibrary);
3273 });
3274 _ut.test('test_getErrorListener', () {
3275 final __test = new LibraryImportScopeTest();
3276 runJUnitTest(__test, __test.test_getErrorListener);
3277 });
3278 });
3279 }
3280 }
3281 /**
3282 * Instances of the class {@code ResolutionVerifier} verify that all of the node s in an AST
3283 * structure that should have been resolved were resolved.
3284 */
3285 class ResolutionVerifier extends RecursiveASTVisitor<Object> {
3286 /**
3287 * A set containing nodes that are known to not be resolvable and should there fore not cause the
3288 * test to fail.
3289 */
3290 Set<ASTNode> _knownExceptions;
3291 /**
3292 * A list containing all of the AST nodes that were not resolved.
3293 */
3294 List<ASTNode> _unresolvedNodes = new List<ASTNode>();
3295 /**
3296 * A list containing all of the AST nodes that were resolved to an element of the wrong type.
3297 */
3298 List<ASTNode> _wrongTypedNodes = new List<ASTNode>();
3299 /**
3300 * Initialize a newly created verifier to verify that all of the nodes in the visited AST
3301 * structures that are expected to have been resolved have an element associat ed with them.
3302 */
3303 ResolutionVerifier() {
3304 _jtd_constructor_306_impl();
3305 }
3306 _jtd_constructor_306_impl() {
3307 _jtd_constructor_307_impl(null);
3308 }
3309 /**
3310 * Initialize a newly created verifier to verify that all of the identifiers i n the visited AST
3311 * structures that are expected to have been resolved have an element associat ed with them. Nodes
3312 * in the set of known exceptions are not expected to have been resolved, even if they normally
3313 * would have been expected to have been resolved.
3314 * @param knownExceptions a set containing nodes that are known to not be reso lvable and should
3315 * therefore not cause the test to fail
3316 */
3317 ResolutionVerifier.con1(Set<ASTNode> knownExceptions2) {
3318 _jtd_constructor_307_impl(knownExceptions2);
3319 }
3320 _jtd_constructor_307_impl(Set<ASTNode> knownExceptions2) {
3321 this._knownExceptions = knownExceptions2;
3322 }
3323 /**
3324 * Assert that all of the visited identifiers were resolved.
3325 */
3326 void assertResolved() {
3327 if (!_unresolvedNodes.isEmpty || !_wrongTypedNodes.isEmpty) {
3328 PrintStringWriter writer = new PrintStringWriter();
3329 if (!_unresolvedNodes.isEmpty) {
3330 writer.print("Failed to resolve ");
3331 writer.print(_unresolvedNodes.length);
3332 writer.printlnObject(" nodes:");
3333 printNodes(writer, _unresolvedNodes);
3334 }
3335 if (!_wrongTypedNodes.isEmpty) {
3336 writer.print("Resolved ");
3337 writer.print(_wrongTypedNodes.length);
3338 writer.printlnObject(" to the wrong type of element:");
3339 printNodes(writer, _wrongTypedNodes);
3340 }
3341 JUnitTestCase.fail(writer.toString());
3342 }
3343 }
3344 Object visitBinaryExpression(BinaryExpression node) {
3345 node.visitChildren(this);
3346 if (!node.operator.isUserDefinableOperator()) {
3347 return null;
3348 }
3349 return checkResolved2(node, node.element, MethodElement);
3350 }
3351 Object visitCompilationUnit(CompilationUnit node) {
3352 node.visitChildren(this);
3353 return checkResolved2(node, node.element, CompilationUnitElement);
3354 }
3355 Object visitExportDirective(ExportDirective node) => checkResolved2(node, node .element, ExportElement);
3356 Object visitFunctionDeclaration(FunctionDeclaration node) {
3357 node.visitChildren(this);
3358 if (node.element is LibraryElement) {
3359 _wrongTypedNodes.add(node);
3360 }
3361 return null;
3362 }
3363 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
3364 node.visitChildren(this);
3365 return checkResolved2(node, node.element, FunctionElement);
3366 }
3367 Object visitImportDirective(ImportDirective node) {
3368 checkResolved2(node, node.element, ImportElement);
3369 SimpleIdentifier prefix10 = node.prefix;
3370 if (prefix10 == null) {
3371 return null;
3372 }
3373 return checkResolved2(prefix10, prefix10.element, PrefixElement);
3374 }
3375 Object visitIndexExpression(IndexExpression node) {
3376 node.visitChildren(this);
3377 return checkResolved2(node, node.element, MethodElement);
3378 }
3379 Object visitLibraryDirective(LibraryDirective node) => checkResolved2(node, no de.element, LibraryElement);
3380 Object visitPartDirective(PartDirective node) => checkResolved2(node, node.ele ment, CompilationUnitElement);
3381 Object visitPartOfDirective(PartOfDirective node) => checkResolved2(node, node .element, LibraryElement);
3382 Object visitPostfixExpression(PostfixExpression node) {
3383 node.visitChildren(this);
3384 if (!node.operator.isUserDefinableOperator()) {
3385 return null;
3386 }
3387 return checkResolved2(node, node.element, MethodElement);
3388 }
3389 Object visitPrefixExpression(PrefixExpression node) {
3390 node.visitChildren(this);
3391 if (!node.operator.isUserDefinableOperator()) {
3392 return null;
3393 }
3394 return checkResolved2(node, node.element, MethodElement);
3395 }
3396 Object visitSimpleIdentifier(SimpleIdentifier node) {
3397 if (node.name == "void") {
3398 return null;
3399 }
3400 return checkResolved(node, node.element);
3401 }
3402 Object checkResolved(ASTNode node, Element element) => checkResolved2(node, el ement, null);
3403 Object checkResolved2(ASTNode node, Element element, Type expectedClass) {
3404 if (element == null) {
3405 if (node.parent is CommentReference) {
3406 return null;
3407 }
3408 if (_knownExceptions == null || !_knownExceptions.contains(node)) {
3409 _unresolvedNodes.add(node);
3410 }
3411 } else if (expectedClass != null) {
3412 if (!isInstanceOf(element, expectedClass)) {
3413 _wrongTypedNodes.add(node);
3414 }
3415 }
3416 return null;
3417 }
3418 String getFileName(ASTNode node) {
3419 if (node != null) {
3420 ASTNode root2 = node.root;
3421 if (root2 is CompilationUnit) {
3422 CompilationUnit rootCU = (root2 as CompilationUnit);
3423 if (rootCU.element != null) {
3424 return rootCU.element.source.fullName;
3425 } else {
3426 return "<unknown file- CompilationUnit.getElement() returned null>";
3427 }
3428 } else {
3429 return "<unknown file- CompilationUnit.getRoot() is not a CompilationUni t>";
3430 }
3431 }
3432 return "<unknown file- ASTNode is null>";
3433 }
3434 void printNodes(PrintStringWriter writer, List<ASTNode> nodes) {
3435 for (ASTNode identifier in nodes) {
3436 writer.print(" ");
3437 writer.print(identifier.toString());
3438 writer.print(" (");
3439 writer.print(getFileName(identifier));
3440 writer.print(" : ");
3441 writer.print(identifier.offset);
3442 writer.printlnObject(")");
3443 }
3444 }
3445 }
3446 class LibraryScopeTest extends ResolverTestCase {
3447 void test_creation_empty() {
3448 LibraryElement definingLibrary = createTestLibrary();
3449 GatheringErrorListener errorListener = new GatheringErrorListener();
3450 new LibraryScope(definingLibrary, errorListener);
3451 }
3452 void test_creation_nonEmpty() {
3453 AnalysisContext context = new AnalysisContextImpl();
3454 String importedTypeName = "A";
3455 ClassElement importedType = new ClassElementImpl(ASTFactory.identifier2(impo rtedTypeName));
3456 LibraryElement importedLibrary = createTestLibrary2(context, "imported", []) ;
3457 ((importedLibrary.definingCompilationUnit as CompilationUnitElementImpl)).ty pes = <ClassElement> [importedType];
3458 LibraryElementImpl definingLibrary = createTestLibrary2(context, "importing" , []);
3459 ImportElementImpl importElement = new ImportElementImpl();
3460 importElement.importedLibrary = importedLibrary;
3461 definingLibrary.imports = <ImportElement> [importElement];
3462 GatheringErrorListener errorListener = new GatheringErrorListener();
3463 Scope scope = new LibraryScope(definingLibrary, errorListener);
3464 JUnitTestCase.assertEquals(importedType, scope.lookup3(importedTypeName, def iningLibrary));
3465 }
3466 void test_getDefiningLibrary() {
3467 LibraryElement definingLibrary = createTestLibrary();
3468 GatheringErrorListener errorListener = new GatheringErrorListener();
3469 Scope scope = new LibraryScope(definingLibrary, errorListener);
3470 JUnitTestCase.assertEquals(definingLibrary, scope.definingLibrary);
3471 }
3472 void test_getErrorListener() {
3473 LibraryElement definingLibrary = createTestLibrary();
3474 GatheringErrorListener errorListener = new GatheringErrorListener();
3475 Scope scope = new LibraryScope(definingLibrary, errorListener);
3476 JUnitTestCase.assertEquals(errorListener, scope.errorListener);
3477 }
3478 static dartSuite() {
3479 _ut.group('LibraryScopeTest', () {
3480 _ut.test('test_creation_empty', () {
3481 final __test = new LibraryScopeTest();
3482 runJUnitTest(__test, __test.test_creation_empty);
3483 });
3484 _ut.test('test_creation_nonEmpty', () {
3485 final __test = new LibraryScopeTest();
3486 runJUnitTest(__test, __test.test_creation_nonEmpty);
3487 });
3488 _ut.test('test_getDefiningLibrary', () {
3489 final __test = new LibraryScopeTest();
3490 runJUnitTest(__test, __test.test_getDefiningLibrary);
3491 });
3492 _ut.test('test_getErrorListener', () {
3493 final __test = new LibraryScopeTest();
3494 runJUnitTest(__test, __test.test_getErrorListener);
3495 });
3496 });
3497 }
3498 }
3499 class StaticTypeAnalyzerTest extends EngineTestCase {
3500 /**
3501 * The error listener to which errors will be reported.
3502 */
3503 GatheringErrorListener _listener;
3504 /**
3505 * The analyzer being used to analyze the test cases.
3506 */
3507 StaticTypeAnalyzer _analyzer;
3508 /**
3509 * The type provider used to access the types.
3510 */
3511 TestTypeProvider _typeProvider;
3512 void fail_visitFunctionExpressionInvocation() {
3513 JUnitTestCase.fail("Not yet tested");
3514 _listener.assertNoErrors();
3515 }
3516 void fail_visitIndexExpression_typeParameters() {
3517 InterfaceType intType6 = _typeProvider.intType;
3518 InterfaceType listType2 = _typeProvider.listType;
3519 MethodElement methodElement = getMethod(listType2, "[]");
3520 SimpleIdentifier identifier = ASTFactory.identifier2("list");
3521 identifier.staticType = listType2.substitute5(<Type2> [intType6]);
3522 IndexExpression indexExpression2 = ASTFactory.indexExpression(identifier, AS TFactory.integer(0));
3523 indexExpression2.element = methodElement;
3524 JUnitTestCase.assertSame(intType6, analyze(indexExpression2));
3525 _listener.assertNoErrors();
3526 }
3527 void fail_visitMethodInvocation() {
3528 JUnitTestCase.fail("Not yet tested");
3529 _listener.assertNoErrors();
3530 }
3531 void fail_visitSimpleIdentifier() {
3532 JUnitTestCase.fail("Not yet tested");
3533 _listener.assertNoErrors();
3534 }
3535 void setUp() {
3536 _listener = new GatheringErrorListener();
3537 _typeProvider = new TestTypeProvider();
3538 _analyzer = createAnalyzer();
3539 }
3540 void test_visitAdjacentStrings() {
3541 Expression node = ASTFactory.adjacentStrings([resolvedString("a"), resolvedS tring("b")]);
3542 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node));
3543 _listener.assertNoErrors();
3544 }
3545 void test_visitArgumentDefinitionTest() {
3546 Expression node = ASTFactory.argumentDefinitionTest("p");
3547 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3548 _listener.assertNoErrors();
3549 }
3550 void test_visitAsExpression() {
3551 ClassElement superclass = ElementFactory.classElement2("A", []);
3552 InterfaceType superclassType = superclass.type;
3553 ClassElement subclass = ElementFactory.classElement("B", superclassType, []) ;
3554 Expression node = ASTFactory.asExpression(ASTFactory.thisExpression(), ASTFa ctory.typeName(subclass, []));
3555 JUnitTestCase.assertSame(subclass.type, analyze2(node, superclassType));
3556 _listener.assertNoErrors();
3557 }
3558 void test_visitAssignmentExpression_compound() {
3559 InterfaceType numType6 = _typeProvider.numType;
3560 SimpleIdentifier identifier = resolvedVariable(_typeProvider.intType, "i");
3561 AssignmentExpression node = ASTFactory.assignmentExpression(identifier, Toke nType.PLUS_EQ, resolvedInteger(1));
3562 node.element = getMethod(numType6, "+");
3563 JUnitTestCase.assertSame(numType6, analyze(node));
3564 _listener.assertNoErrors();
3565 }
3566 void test_visitAssignmentExpression_simple() {
3567 InterfaceType intType7 = _typeProvider.intType;
3568 Expression node = ASTFactory.assignmentExpression(resolvedVariable(intType7, "i"), TokenType.EQ, resolvedInteger(0));
3569 JUnitTestCase.assertSame(intType7, analyze(node));
3570 _listener.assertNoErrors();
3571 }
3572 void test_visitBinaryExpression_equals() {
3573 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType. EQ_EQ, resolvedInteger(3));
3574 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3575 _listener.assertNoErrors();
3576 }
3577 void test_visitBinaryExpression_logicalAnd() {
3578 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals e), TokenType.AMPERSAND_AMPERSAND, ASTFactory.booleanLiteral(true));
3579 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3580 _listener.assertNoErrors();
3581 }
3582 void test_visitBinaryExpression_logicalOr() {
3583 Expression node = ASTFactory.binaryExpression(ASTFactory.booleanLiteral(fals e), TokenType.BAR_BAR, ASTFactory.booleanLiteral(true));
3584 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3585 _listener.assertNoErrors();
3586 }
3587 void test_visitBinaryExpression_notEquals() {
3588 Expression node = ASTFactory.binaryExpression(resolvedInteger(2), TokenType. BANG_EQ, resolvedInteger(3));
3589 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3590 _listener.assertNoErrors();
3591 }
3592 void test_visitBinaryExpression_plus() {
3593 BinaryExpression node = ASTFactory.binaryExpression(resolvedInteger(2), Toke nType.PLUS, resolvedInteger(2));
3594 node.element = getMethod(_typeProvider.numType, "+");
3595 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node));
3596 _listener.assertNoErrors();
3597 }
3598 void test_visitBooleanLiteral_false() {
3599 Expression node = ASTFactory.booleanLiteral(false);
3600 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3601 _listener.assertNoErrors();
3602 }
3603 void test_visitBooleanLiteral_true() {
3604 Expression node = ASTFactory.booleanLiteral(true);
3605 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3606 _listener.assertNoErrors();
3607 }
3608 void test_visitCascadeExpression() {
3609 Expression node = ASTFactory.cascadeExpression(resolvedString("a"), [ASTFact ory.propertyAccess2(null, "length")]);
3610 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node));
3611 _listener.assertNoErrors();
3612 }
3613 void test_visitConditionalExpression_differentTypes() {
3614 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral (true), resolvedDouble(1.0), resolvedInteger(0));
3615 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node));
3616 _listener.assertNoErrors();
3617 }
3618 void test_visitConditionalExpression_sameTypes() {
3619 Expression node = ASTFactory.conditionalExpression(ASTFactory.booleanLiteral (true), resolvedInteger(1), resolvedInteger(0));
3620 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3621 _listener.assertNoErrors();
3622 }
3623 void test_visitDoubleLiteral() {
3624 Expression node = ASTFactory.doubleLiteral(4.33);
3625 JUnitTestCase.assertSame(_typeProvider.doubleType, analyze(node));
3626 _listener.assertNoErrors();
3627 }
3628 void test_visitFunctionExpression_named_block() {
3629 Type2 dynamicType3 = _typeProvider.dynamicType;
3630 FormalParameter p1 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal Parameter3("p1"), resolvedInteger(0));
3631 setType(p1, dynamicType3);
3632 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal Parameter3("p2"), resolvedInteger(0));
3633 setType(p2, dynamicType3);
3634 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.blockFunctionBody([]));
3635 analyze3(p1);
3636 analyze3(p2);
3637 Type2 resultType = analyze(node);
3638 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>();
3639 expectedNamedTypes["p1"] = dynamicType3;
3640 expectedNamedTypes["p2"] = dynamicType3;
3641 assertFunctionType(dynamicType3, null, null, expectedNamedTypes, resultType) ;
3642 _listener.assertNoErrors();
3643 }
3644 void test_visitFunctionExpression_named_expression() {
3645 Type2 dynamicType4 = _typeProvider.dynamicType;
3646 FormalParameter p = ASTFactory.namedFormalParameter(ASTFactory.simpleFormalP arameter3("p"), resolvedInteger(0));
3647 setType(p, dynamicType4);
3648 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0)));
3649 analyze3(p);
3650 Type2 resultType = analyze(node);
3651 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>();
3652 expectedNamedTypes["p"] = dynamicType4;
3653 assertFunctionType(_typeProvider.intType, null, null, expectedNamedTypes, re sultType);
3654 _listener.assertNoErrors();
3655 }
3656 void test_visitFunctionExpression_normal_block() {
3657 Type2 dynamicType5 = _typeProvider.dynamicType;
3658 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1");
3659 setType(p1, dynamicType5);
3660 FormalParameter p2 = ASTFactory.simpleFormalParameter3("p2");
3661 setType(p2, dynamicType5);
3662 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.blockFunctionBody([]));
3663 analyze3(p1);
3664 analyze3(p2);
3665 Type2 resultType = analyze(node);
3666 assertFunctionType(dynamicType5, <Type2> [dynamicType5, dynamicType5], null, null, resultType);
3667 _listener.assertNoErrors();
3668 }
3669 void test_visitFunctionExpression_normal_expression() {
3670 Type2 dynamicType6 = _typeProvider.dynamicType;
3671 FormalParameter p = ASTFactory.simpleFormalParameter3("p");
3672 setType(p, dynamicType6);
3673 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0)));
3674 analyze3(p);
3675 Type2 resultType = analyze(node);
3676 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType6], null, null , resultType);
3677 _listener.assertNoErrors();
3678 }
3679 void test_visitFunctionExpression_normalAndNamed_block() {
3680 Type2 dynamicType7 = _typeProvider.dynamicType;
3681 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1");
3682 setType(p1, dynamicType7);
3683 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal Parameter3("p2"), resolvedInteger(0));
3684 setType(p2, dynamicType7);
3685 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.blockFunctionBody([]));
3686 analyze3(p2);
3687 Type2 resultType = analyze(node);
3688 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>();
3689 expectedNamedTypes["p2"] = dynamicType7;
3690 assertFunctionType(dynamicType7, <Type2> [dynamicType7], null, expectedNamed Types, resultType);
3691 _listener.assertNoErrors();
3692 }
3693 void test_visitFunctionExpression_normalAndNamed_expression() {
3694 Type2 dynamicType8 = _typeProvider.dynamicType;
3695 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1");
3696 setType(p1, dynamicType8);
3697 FormalParameter p2 = ASTFactory.namedFormalParameter(ASTFactory.simpleFormal Parameter3("p2"), resolvedInteger(0));
3698 setType(p2, dynamicType8);
3699 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0)));
3700 analyze3(p2);
3701 Type2 resultType = analyze(node);
3702 Map<String, Type2> expectedNamedTypes = new Map<String, Type2>();
3703 expectedNamedTypes["p2"] = dynamicType8;
3704 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType8], null, expe ctedNamedTypes, resultType);
3705 _listener.assertNoErrors();
3706 }
3707 void test_visitFunctionExpression_normalAndPositional_block() {
3708 Type2 dynamicType9 = _typeProvider.dynamicType;
3709 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1");
3710 setType(p1, dynamicType9);
3711 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF ormalParameter3("p2"), resolvedInteger(0));
3712 setType(p2, dynamicType9);
3713 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.blockFunctionBody([]));
3714 analyze3(p1);
3715 analyze3(p2);
3716 Type2 resultType = analyze(node);
3717 assertFunctionType(dynamicType9, <Type2> [dynamicType9], <Type2> [dynamicTyp e9], null, resultType);
3718 _listener.assertNoErrors();
3719 }
3720 void test_visitFunctionExpression_normalAndPositional_expression() {
3721 Type2 dynamicType10 = _typeProvider.dynamicType;
3722 FormalParameter p1 = ASTFactory.simpleFormalParameter3("p1");
3723 setType(p1, dynamicType10);
3724 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF ormalParameter3("p2"), resolvedInteger(0));
3725 setType(p2, dynamicType10);
3726 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.expressionFunctionBody(resolvedInteger(0)));
3727 analyze3(p1);
3728 analyze3(p2);
3729 Type2 resultType = analyze(node);
3730 assertFunctionType(_typeProvider.intType, <Type2> [dynamicType10], <Type2> [ dynamicType10], null, resultType);
3731 _listener.assertNoErrors();
3732 }
3733 void test_visitFunctionExpression_positional_block() {
3734 Type2 dynamicType11 = _typeProvider.dynamicType;
3735 FormalParameter p1 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF ormalParameter3("p1"), resolvedInteger(0));
3736 setType(p1, dynamicType11);
3737 FormalParameter p2 = ASTFactory.positionalFormalParameter(ASTFactory.simpleF ormalParameter3("p2"), resolvedInteger(0));
3738 setType(p2, dynamicType11);
3739 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p1, p2]), ASTFactory.blockFunctionBody([]));
3740 analyze3(p1);
3741 analyze3(p2);
3742 Type2 resultType = analyze(node);
3743 assertFunctionType(dynamicType11, null, <Type2> [dynamicType11, dynamicType1 1], null, resultType);
3744 _listener.assertNoErrors();
3745 }
3746 void test_visitFunctionExpression_positional_expression() {
3747 Type2 dynamicType12 = _typeProvider.dynamicType;
3748 FormalParameter p = ASTFactory.positionalFormalParameter(ASTFactory.simpleFo rmalParameter3("p"), resolvedInteger(0));
3749 setType(p, dynamicType12);
3750 FunctionExpression node = resolvedFunctionExpression(ASTFactory.formalParame terList([p]), ASTFactory.expressionFunctionBody(resolvedInteger(0)));
3751 analyze3(p);
3752 Type2 resultType = analyze(node);
3753 assertFunctionType(_typeProvider.intType, null, <Type2> [dynamicType12], nul l, resultType);
3754 _listener.assertNoErrors();
3755 }
3756 void test_visitIndexExpression_getter() {
3757 InterfaceType listType3 = _typeProvider.listType;
3758 SimpleIdentifier identifier = resolvedVariable(listType3, "a");
3759 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege r(2));
3760 node.element = listType3.element.methods[0];
3761 JUnitTestCase.assertSame(listType3.typeArguments[0], analyze(node));
3762 _listener.assertNoErrors();
3763 }
3764 void test_visitIndexExpression_setter() {
3765 InterfaceType listType4 = _typeProvider.listType;
3766 SimpleIdentifier identifier = resolvedVariable(listType4, "a");
3767 IndexExpression node = ASTFactory.indexExpression(identifier, resolvedIntege r(2));
3768 node.element = listType4.element.methods[1];
3769 ASTFactory.assignmentExpression(node, TokenType.EQ, ASTFactory.integer(0));
3770 JUnitTestCase.assertSame(listType4.typeArguments[0], analyze(node));
3771 _listener.assertNoErrors();
3772 }
3773 void test_visitInstanceCreationExpression_named() {
3774 ClassElement classElement = ElementFactory.classElement2("C", []);
3775 String constructorName = "m";
3776 ConstructorElementImpl constructor = ElementFactory.constructorElement(const ructorName);
3777 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
3778 constructorType.returnType = classElement.type;
3779 constructor.type = constructorType;
3780 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul l, ASTFactory.typeName(classElement, []), [ASTFactory.identifier2(constructorNam e)]);
3781 node.element = constructor;
3782 JUnitTestCase.assertSame(classElement.type, analyze(node));
3783 _listener.assertNoErrors();
3784 }
3785 void test_visitInstanceCreationExpression_typeParameters() {
3786 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]);
3787 ClassElementImpl elementI = ElementFactory.classElement2("I", []);
3788 ConstructorElementImpl constructor = ElementFactory.constructorElement(null) ;
3789 elementC.constructors = <ConstructorElement> [constructor];
3790 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
3791 constructorType.returnType = elementC.type;
3792 constructor.type = constructorType;
3793 TypeName typeName4 = ASTFactory.typeName(elementC, [ASTFactory.typeName(elem entI, [])]);
3794 typeName4.type = elementC.type.substitute5(<Type2> [elementI.type]);
3795 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul l, typeName4, []);
3796 node.element = constructor;
3797 InterfaceType interfaceType = analyze(node) as InterfaceType;
3798 List<Type2> typeArgs = interfaceType.typeArguments;
3799 JUnitTestCase.assertEquals(1, typeArgs.length);
3800 JUnitTestCase.assertEquals(elementI.type, typeArgs[0]);
3801 _listener.assertNoErrors();
3802 }
3803 void test_visitInstanceCreationExpression_unnamed() {
3804 ClassElement classElement = ElementFactory.classElement2("C", []);
3805 ConstructorElementImpl constructor = ElementFactory.constructorElement(null) ;
3806 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor);
3807 constructorType.returnType = classElement.type;
3808 constructor.type = constructorType;
3809 InstanceCreationExpression node = ASTFactory.instanceCreationExpression2(nul l, ASTFactory.typeName(classElement, []), []);
3810 node.element = constructor;
3811 JUnitTestCase.assertSame(classElement.type, analyze(node));
3812 _listener.assertNoErrors();
3813 }
3814 void test_visitIntegerLiteral() {
3815 Expression node = resolvedInteger(42);
3816 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3817 _listener.assertNoErrors();
3818 }
3819 void test_visitIsExpression_negated() {
3820 Expression node = ASTFactory.isExpression(resolvedString("a"), true, ASTFact ory.typeName3("String", []));
3821 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3822 _listener.assertNoErrors();
3823 }
3824 void test_visitIsExpression_notNegated() {
3825 Expression node = ASTFactory.isExpression(resolvedString("a"), false, ASTFac tory.typeName3("String", []));
3826 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3827 _listener.assertNoErrors();
3828 }
3829 void test_visitListLiteral_empty() {
3830 Expression node = ASTFactory.listLiteral([]);
3831 Type2 resultType = analyze(node);
3832 assertType2(_typeProvider.listType.substitute5(<Type2> [_typeProvider.dynami cType]), resultType);
3833 _listener.assertNoErrors();
3834 }
3835 void test_visitListLiteral_nonEmpty() {
3836 Expression node = ASTFactory.listLiteral([resolvedInteger(0)]);
3837 Type2 resultType = analyze(node);
3838 assertType2(_typeProvider.listType.substitute5(<Type2> [_typeProvider.dynami cType]), resultType);
3839 _listener.assertNoErrors();
3840 }
3841 void test_visitMapLiteral_empty() {
3842 Expression node = ASTFactory.mapLiteral2([]);
3843 Type2 resultType = analyze(node);
3844 assertType2(_typeProvider.mapType.substitute5(<Type2> [_typeProvider.stringT ype, _typeProvider.dynamicType]), resultType);
3845 _listener.assertNoErrors();
3846 }
3847 void test_visitMapLiteral_nonEmpty() {
3848 Expression node = ASTFactory.mapLiteral2([ASTFactory.mapLiteralEntry("k", re solvedInteger(0))]);
3849 Type2 resultType = analyze(node);
3850 assertType2(_typeProvider.mapType.substitute5(<Type2> [_typeProvider.stringT ype, _typeProvider.dynamicType]), resultType);
3851 _listener.assertNoErrors();
3852 }
3853 void test_visitNamedExpression() {
3854 Expression node = ASTFactory.namedExpression("n", resolvedString("a"));
3855 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node));
3856 _listener.assertNoErrors();
3857 }
3858 void test_visitNullLiteral() {
3859 Expression node = ASTFactory.nullLiteral();
3860 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node));
3861 _listener.assertNoErrors();
3862 }
3863 void test_visitParenthesizedExpression() {
3864 Expression node = ASTFactory.parenthesizedExpression(resolvedInteger(0));
3865 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3866 _listener.assertNoErrors();
3867 }
3868 void test_visitPostfixExpression_minusMinus() {
3869 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To kenType.MINUS_MINUS);
3870 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3871 _listener.assertNoErrors();
3872 }
3873 void test_visitPostfixExpression_plusPlus() {
3874 PostfixExpression node = ASTFactory.postfixExpression(resolvedInteger(0), To kenType.PLUS_PLUS);
3875 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3876 _listener.assertNoErrors();
3877 }
3878 void test_visitPrefixedIdentifier_getter() {
3879 Type2 boolType2 = _typeProvider.boolType;
3880 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false , boolType2);
3881 PrefixedIdentifier node = ASTFactory.identifier4("a", "b");
3882 node.identifier.element = getter;
3883 JUnitTestCase.assertSame(boolType2, analyze(node));
3884 _listener.assertNoErrors();
3885 }
3886 void test_visitPrefixedIdentifier_setter() {
3887 Type2 boolType3 = _typeProvider.boolType;
3888 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals e, boolType3);
3889 PropertyAccessorElement setter5 = field.setter;
3890 PrefixedIdentifier node = ASTFactory.identifier4("a", "b");
3891 node.identifier.element = setter5;
3892 JUnitTestCase.assertSame(boolType3, analyze(node));
3893 _listener.assertNoErrors();
3894 }
3895 void test_visitPrefixedIdentifier_variable() {
3896 VariableElementImpl variable = ElementFactory.localVariableElement2("b");
3897 variable.type = _typeProvider.boolType;
3898 PrefixedIdentifier node = ASTFactory.identifier4("a", "b");
3899 node.identifier.element = variable;
3900 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3901 _listener.assertNoErrors();
3902 }
3903 void test_visitPrefixExpression_bang() {
3904 PrefixExpression node = ASTFactory.prefixExpression(TokenType.BANG, resolved Integer(0));
3905 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3906 _listener.assertNoErrors();
3907 }
3908 void test_visitPrefixExpression_minus() {
3909 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS, resolve dInteger(0));
3910 node.element = getMethod(_typeProvider.numType, "-");
3911 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node));
3912 _listener.assertNoErrors();
3913 }
3914 void test_visitPrefixExpression_minusMinus() {
3915 PrefixExpression node = ASTFactory.prefixExpression(TokenType.MINUS_MINUS, r esolvedInteger(0));
3916 node.element = getMethod(_typeProvider.numType, "-");
3917 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node));
3918 _listener.assertNoErrors();
3919 }
3920 void test_visitPrefixExpression_not() {
3921 Expression node = ASTFactory.prefixExpression(TokenType.BANG, ASTFactory.boo leanLiteral(true));
3922 JUnitTestCase.assertSame(_typeProvider.boolType, analyze(node));
3923 _listener.assertNoErrors();
3924 }
3925 void test_visitPrefixExpression_plusPlus() {
3926 PrefixExpression node = ASTFactory.prefixExpression(TokenType.PLUS_PLUS, res olvedInteger(0));
3927 node.element = getMethod(_typeProvider.numType, "+");
3928 JUnitTestCase.assertSame(_typeProvider.numType, analyze(node));
3929 _listener.assertNoErrors();
3930 }
3931 void test_visitPrefixExpression_tilde() {
3932 PrefixExpression node = ASTFactory.prefixExpression(TokenType.TILDE, resolve dInteger(0));
3933 node.element = getMethod(_typeProvider.intType, "~");
3934 JUnitTestCase.assertSame(_typeProvider.intType, analyze(node));
3935 _listener.assertNoErrors();
3936 }
3937 void test_visitPropertyAccess_getter() {
3938 Type2 boolType4 = _typeProvider.boolType;
3939 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false , boolType4);
3940 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier2("a") , "b");
3941 node.propertyName.element = getter;
3942 JUnitTestCase.assertSame(boolType4, analyze(node));
3943 _listener.assertNoErrors();
3944 }
3945 void test_visitPropertyAccess_setter() {
3946 Type2 boolType5 = _typeProvider.boolType;
3947 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals e, boolType5);
3948 PropertyAccessorElement setter6 = field.setter;
3949 PropertyAccess node = ASTFactory.propertyAccess2(ASTFactory.identifier2("a") , "b");
3950 node.propertyName.element = setter6;
3951 JUnitTestCase.assertSame(boolType5, analyze(node));
3952 _listener.assertNoErrors();
3953 }
3954 void test_visitSimpleStringLiteral() {
3955 Expression node = resolvedString("a");
3956 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node));
3957 _listener.assertNoErrors();
3958 }
3959 void test_visitStringInterpolation() {
3960 Expression node = ASTFactory.string([ASTFactory.interpolationString("a", "a" ), ASTFactory.interpolationExpression(resolvedString("b")), ASTFactory.interpola tionString("c", "c")]);
3961 JUnitTestCase.assertSame(_typeProvider.stringType, analyze(node));
3962 _listener.assertNoErrors();
3963 }
3964 void test_visitSuperExpression() {
3965 InterfaceType superType = ElementFactory.classElement2("A", []).type;
3966 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ e;
3967 Expression node = ASTFactory.superExpression();
3968 JUnitTestCase.assertSame(superType, analyze2(node, thisType));
3969 _listener.assertNoErrors();
3970 }
3971 void test_visitThisExpression() {
3972 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla ssElement2("A", []).type, []).type;
3973 Expression node = ASTFactory.thisExpression();
3974 JUnitTestCase.assertSame(thisType, analyze2(node, thisType));
3975 _listener.assertNoErrors();
3976 }
3977 void test_visitThrowExpression_withoutValue() {
3978 Expression node = ASTFactory.throwExpression();
3979 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node));
3980 _listener.assertNoErrors();
3981 }
3982 void test_visitThrowExpression_withValue() {
3983 Expression node = ASTFactory.throwExpression2(resolvedInteger(0));
3984 JUnitTestCase.assertSame(_typeProvider.bottomType, analyze(node));
3985 _listener.assertNoErrors();
3986 }
3987 /**
3988 * Return the type associated with the given expression after the static type analyzer has
3989 * computed a type for it.
3990 * @param node the expression with which the type is associated
3991 * @return the type associated with the expression
3992 */
3993 Type2 analyze(Expression node) => analyze2(node, null);
3994 /**
3995 * Return the type associated with the given expression after the static type analyzer has
3996 * computed a type for it.
3997 * @param node the expression with which the type is associated
3998 * @param thisType the type of 'this'
3999 * @return the type associated with the expression
4000 */
4001 Type2 analyze2(Expression node, InterfaceType thisType) {
4002 try {
4003 _analyzer.thisType_J2DAccessor = thisType;
4004 } on JavaException catch (exception) {
4005 throw new IllegalArgumentException("Could not set type of 'this'", excepti on);
4006 }
4007 node.accept(_analyzer);
4008 return node.staticType;
4009 }
4010 /**
4011 * Return the type associated with the given parameter after the static type a nalyzer has computed
4012 * a type for it.
4013 * @param node the parameter with which the type is associated
4014 * @return the type associated with the parameter
4015 */
4016 Type2 analyze3(FormalParameter node) {
4017 node.accept(_analyzer);
4018 return ((node.identifier.element as ParameterElement)).type;
4019 }
4020 /**
4021 * Assert that the actual type is a function type with the expected characteri stics.
4022 * @param expectedReturnType the expected return type of the function
4023 * @param expectedNormalTypes the expected types of the normal parameters
4024 * @param expectedOptionalTypes the expected types of the optional parameters
4025 * @param expectedNamedTypes the expected types of the named parameters
4026 * @param actualType the type being tested
4027 */
4028 void assertFunctionType(Type2 expectedReturnType, List<Type2> expectedNormalTy pes, List<Type2> expectedOptionalTypes, Map<String, Type2> expectedNamedTypes, T ype2 actualType) {
4029 EngineTestCase.assertInstanceOf(FunctionType, actualType);
4030 FunctionType functionType = actualType as FunctionType;
4031 List<Type2> normalTypes = functionType.normalParameterTypes;
4032 if (expectedNormalTypes == null) {
4033 EngineTestCase.assertLength(0, normalTypes);
4034 } else {
4035 int expectedCount = expectedNormalTypes.length;
4036 EngineTestCase.assertLength(expectedCount, normalTypes);
4037 for (int i = 0; i < expectedCount; i++) {
4038 JUnitTestCase.assertSame(expectedNormalTypes[i], normalTypes[i]);
4039 }
4040 }
4041 List<Type2> optionalTypes = functionType.optionalParameterTypes;
4042 if (expectedOptionalTypes == null) {
4043 EngineTestCase.assertLength(0, optionalTypes);
4044 } else {
4045 int expectedCount = expectedOptionalTypes.length;
4046 EngineTestCase.assertLength(expectedCount, optionalTypes);
4047 for (int i = 0; i < expectedCount; i++) {
4048 JUnitTestCase.assertSame(expectedOptionalTypes[i], optionalTypes[i]);
4049 }
4050 }
4051 Map<String, Type2> namedTypes = functionType.namedParameterTypes;
4052 if (expectedNamedTypes == null) {
4053 EngineTestCase.assertSize2(0, namedTypes);
4054 } else {
4055 EngineTestCase.assertSize2(expectedNamedTypes.length, namedTypes);
4056 for (MapEntry<String, Type2> entry in getMapEntrySet(expectedNamedTypes)) {
4057 JUnitTestCase.assertSame(entry.getValue(), namedTypes[entry.getKey()]);
4058 }
4059 }
4060 JUnitTestCase.assertSame(expectedReturnType, functionType.returnType);
4061 }
4062 void assertType(InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType) {
4063 JUnitTestCase.assertEquals(expectedType.name, actualType.name);
4064 JUnitTestCase.assertEquals(expectedType.element, actualType.element);
4065 List<Type2> expectedArguments = expectedType.typeArguments;
4066 int length9 = expectedArguments.length;
4067 List<Type2> actualArguments = actualType.typeArguments;
4068 EngineTestCase.assertLength(length9, actualArguments);
4069 for (int i = 0; i < length9; i++) {
4070 assertType2(expectedArguments[i], actualArguments[i]);
4071 }
4072 }
4073 void assertType2(Type2 expectedType, Type2 actualType) {
4074 if (expectedType is InterfaceTypeImpl) {
4075 EngineTestCase.assertInstanceOf(InterfaceTypeImpl, actualType);
4076 assertType((expectedType as InterfaceTypeImpl), (actualType as InterfaceTy peImpl));
4077 }
4078 }
4079 /**
4080 * Create the analyzer used by the tests.
4081 * @return the analyzer to be used by the tests
4082 */
4083 StaticTypeAnalyzer createAnalyzer() {
4084 AnalysisContextImpl context = new AnalysisContextImpl();
4085 context.sourceFactory = new SourceFactory.con2([new DartUriResolver(DartSdk. defaultSdk)]);
4086 CompilationUnitElementImpl definingCompilationUnit = new CompilationUnitElem entImpl("lib.dart");
4087 LibraryElementImpl definingLibrary = new LibraryElementImpl(context, null);
4088 definingLibrary.definingCompilationUnit = definingCompilationUnit;
4089 Library library = new Library(context, _listener, null);
4090 library.libraryElement = definingLibrary;
4091 ResolverVisitor visitor = new ResolverVisitor(library, null, _typeProvider);
4092 try {
4093 return visitor.typeAnalyzer_J2DAccessor as StaticTypeAnalyzer;
4094 } on JavaException catch (exception) {
4095 throw new IllegalArgumentException("Could not create analyzer", exception) ;
4096 }
4097 }
4098 /**
4099 * Return an integer literal that has been resolved to the correct type.
4100 * @param value the value of the literal
4101 * @return an integer literal that has been resolved to the correct type
4102 */
4103 DoubleLiteral resolvedDouble(double value) {
4104 DoubleLiteral literal = ASTFactory.doubleLiteral(value);
4105 literal.staticType = _typeProvider.doubleType;
4106 return literal;
4107 }
4108 /**
4109 * Create a function expression that has an element associated with it, where the element has an
4110 * incomplete type associated with it (just like the one{@link ElementBuilder# visitFunctionExpression(FunctionExpression)} would have built if we had
4111 * run it).
4112 * @param parameters the parameters to the function
4113 * @param body the body of the function
4114 * @return a resolved function expression
4115 */
4116 FunctionExpression resolvedFunctionExpression(FormalParameterList parameters15 , FunctionBody body) {
4117 for (FormalParameter parameter in parameters15.parameters) {
4118 ParameterElementImpl element = new ParameterElementImpl(parameter.identifi er);
4119 element.parameterKind = parameter.kind;
4120 element.type = _typeProvider.dynamicType;
4121 parameter.identifier.element = element;
4122 }
4123 FunctionExpression node = ASTFactory.functionExpression2(parameters15, body) ;
4124 FunctionElementImpl element = new FunctionElementImpl.con1(null);
4125 element.type = new FunctionTypeImpl.con1(element);
4126 node.element = element;
4127 return node;
4128 }
4129 /**
4130 * Return an integer literal that has been resolved to the correct type.
4131 * @param value the value of the literal
4132 * @return an integer literal that has been resolved to the correct type
4133 */
4134 IntegerLiteral resolvedInteger(int value) {
4135 IntegerLiteral literal = ASTFactory.integer(value);
4136 literal.staticType = _typeProvider.intType;
4137 return literal;
4138 }
4139 /**
4140 * Return a string literal that has been resolved to the correct type.
4141 * @param value the value of the literal
4142 * @return a string literal that has been resolved to the correct type
4143 */
4144 SimpleStringLiteral resolvedString(String value) {
4145 SimpleStringLiteral string = ASTFactory.string2(value);
4146 string.staticType = _typeProvider.stringType;
4147 return string;
4148 }
4149 /**
4150 * Return a simple identifier that has been resolved to a variable element wit h the given type.
4151 * @param type the type of the variable being represented
4152 * @param variableName the name of the variable
4153 * @return a simple identifier that has been resolved to a variable element wi th the given type
4154 */
4155 SimpleIdentifier resolvedVariable(InterfaceType type36, String variableName) {
4156 SimpleIdentifier identifier = ASTFactory.identifier2(variableName);
4157 VariableElementImpl element = ElementFactory.localVariableElement(identifier );
4158 element.type = type36;
4159 identifier.element = element;
4160 identifier.staticType = type36;
4161 return identifier;
4162 }
4163 /**
4164 * Set the type of the given parameter to the given type.
4165 * @param parameter the parameter whose type is to be set
4166 * @param type the new type of the given parameter
4167 */
4168 void setType(FormalParameter parameter, Type2 type37) {
4169 SimpleIdentifier identifier17 = parameter.identifier;
4170 Element element48 = identifier17.element;
4171 if (element48 is! ParameterElement) {
4172 element48 = new ParameterElementImpl(identifier17);
4173 identifier17.element = element48;
4174 }
4175 ((element48 as ParameterElementImpl)).type = type37;
4176 }
4177 static dartSuite() {
4178 _ut.group('StaticTypeAnalyzerTest', () {
4179 _ut.test('test_visitAdjacentStrings', () {
4180 final __test = new StaticTypeAnalyzerTest();
4181 runJUnitTest(__test, __test.test_visitAdjacentStrings);
4182 });
4183 _ut.test('test_visitArgumentDefinitionTest', () {
4184 final __test = new StaticTypeAnalyzerTest();
4185 runJUnitTest(__test, __test.test_visitArgumentDefinitionTest);
4186 });
4187 _ut.test('test_visitAsExpression', () {
4188 final __test = new StaticTypeAnalyzerTest();
4189 runJUnitTest(__test, __test.test_visitAsExpression);
4190 });
4191 _ut.test('test_visitAssignmentExpression_compound', () {
4192 final __test = new StaticTypeAnalyzerTest();
4193 runJUnitTest(__test, __test.test_visitAssignmentExpression_compound);
4194 });
4195 _ut.test('test_visitAssignmentExpression_simple', () {
4196 final __test = new StaticTypeAnalyzerTest();
4197 runJUnitTest(__test, __test.test_visitAssignmentExpression_simple);
4198 });
4199 _ut.test('test_visitBinaryExpression_equals', () {
4200 final __test = new StaticTypeAnalyzerTest();
4201 runJUnitTest(__test, __test.test_visitBinaryExpression_equals);
4202 });
4203 _ut.test('test_visitBinaryExpression_logicalAnd', () {
4204 final __test = new StaticTypeAnalyzerTest();
4205 runJUnitTest(__test, __test.test_visitBinaryExpression_logicalAnd);
4206 });
4207 _ut.test('test_visitBinaryExpression_logicalOr', () {
4208 final __test = new StaticTypeAnalyzerTest();
4209 runJUnitTest(__test, __test.test_visitBinaryExpression_logicalOr);
4210 });
4211 _ut.test('test_visitBinaryExpression_notEquals', () {
4212 final __test = new StaticTypeAnalyzerTest();
4213 runJUnitTest(__test, __test.test_visitBinaryExpression_notEquals);
4214 });
4215 _ut.test('test_visitBinaryExpression_plus', () {
4216 final __test = new StaticTypeAnalyzerTest();
4217 runJUnitTest(__test, __test.test_visitBinaryExpression_plus);
4218 });
4219 _ut.test('test_visitBooleanLiteral_false', () {
4220 final __test = new StaticTypeAnalyzerTest();
4221 runJUnitTest(__test, __test.test_visitBooleanLiteral_false);
4222 });
4223 _ut.test('test_visitBooleanLiteral_true', () {
4224 final __test = new StaticTypeAnalyzerTest();
4225 runJUnitTest(__test, __test.test_visitBooleanLiteral_true);
4226 });
4227 _ut.test('test_visitCascadeExpression', () {
4228 final __test = new StaticTypeAnalyzerTest();
4229 runJUnitTest(__test, __test.test_visitCascadeExpression);
4230 });
4231 _ut.test('test_visitConditionalExpression_differentTypes', () {
4232 final __test = new StaticTypeAnalyzerTest();
4233 runJUnitTest(__test, __test.test_visitConditionalExpression_differentTyp es);
4234 });
4235 _ut.test('test_visitConditionalExpression_sameTypes', () {
4236 final __test = new StaticTypeAnalyzerTest();
4237 runJUnitTest(__test, __test.test_visitConditionalExpression_sameTypes);
4238 });
4239 _ut.test('test_visitDoubleLiteral', () {
4240 final __test = new StaticTypeAnalyzerTest();
4241 runJUnitTest(__test, __test.test_visitDoubleLiteral);
4242 });
4243 _ut.test('test_visitFunctionExpression_named_block', () {
4244 final __test = new StaticTypeAnalyzerTest();
4245 runJUnitTest(__test, __test.test_visitFunctionExpression_named_block);
4246 });
4247 _ut.test('test_visitFunctionExpression_named_expression', () {
4248 final __test = new StaticTypeAnalyzerTest();
4249 runJUnitTest(__test, __test.test_visitFunctionExpression_named_expressio n);
4250 });
4251 _ut.test('test_visitFunctionExpression_normalAndNamed_block', () {
4252 final __test = new StaticTypeAnalyzerTest();
4253 runJUnitTest(__test, __test.test_visitFunctionExpression_normalAndNamed_ block);
4254 });
4255 _ut.test('test_visitFunctionExpression_normalAndNamed_expression', () {
4256 final __test = new StaticTypeAnalyzerTest();
4257 runJUnitTest(__test, __test.test_visitFunctionExpression_normalAndNamed_ expression);
4258 });
4259 _ut.test('test_visitFunctionExpression_normalAndPositional_block', () {
4260 final __test = new StaticTypeAnalyzerTest();
4261 runJUnitTest(__test, __test.test_visitFunctionExpression_normalAndPositi onal_block);
4262 });
4263 _ut.test('test_visitFunctionExpression_normalAndPositional_expression', () {
4264 final __test = new StaticTypeAnalyzerTest();
4265 runJUnitTest(__test, __test.test_visitFunctionExpression_normalAndPositi onal_expression);
4266 });
4267 _ut.test('test_visitFunctionExpression_normal_block', () {
4268 final __test = new StaticTypeAnalyzerTest();
4269 runJUnitTest(__test, __test.test_visitFunctionExpression_normal_block);
4270 });
4271 _ut.test('test_visitFunctionExpression_normal_expression', () {
4272 final __test = new StaticTypeAnalyzerTest();
4273 runJUnitTest(__test, __test.test_visitFunctionExpression_normal_expressi on);
4274 });
4275 _ut.test('test_visitFunctionExpression_positional_block', () {
4276 final __test = new StaticTypeAnalyzerTest();
4277 runJUnitTest(__test, __test.test_visitFunctionExpression_positional_bloc k);
4278 });
4279 _ut.test('test_visitFunctionExpression_positional_expression', () {
4280 final __test = new StaticTypeAnalyzerTest();
4281 runJUnitTest(__test, __test.test_visitFunctionExpression_positional_expr ession);
4282 });
4283 _ut.test('test_visitIndexExpression_getter', () {
4284 final __test = new StaticTypeAnalyzerTest();
4285 runJUnitTest(__test, __test.test_visitIndexExpression_getter);
4286 });
4287 _ut.test('test_visitIndexExpression_setter', () {
4288 final __test = new StaticTypeAnalyzerTest();
4289 runJUnitTest(__test, __test.test_visitIndexExpression_setter);
4290 });
4291 _ut.test('test_visitInstanceCreationExpression_named', () {
4292 final __test = new StaticTypeAnalyzerTest();
4293 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_named);
4294 });
4295 _ut.test('test_visitInstanceCreationExpression_typeParameters', () {
4296 final __test = new StaticTypeAnalyzerTest();
4297 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_typePar ameters);
4298 });
4299 _ut.test('test_visitInstanceCreationExpression_unnamed', () {
4300 final __test = new StaticTypeAnalyzerTest();
4301 runJUnitTest(__test, __test.test_visitInstanceCreationExpression_unnamed );
4302 });
4303 _ut.test('test_visitIntegerLiteral', () {
4304 final __test = new StaticTypeAnalyzerTest();
4305 runJUnitTest(__test, __test.test_visitIntegerLiteral);
4306 });
4307 _ut.test('test_visitIsExpression_negated', () {
4308 final __test = new StaticTypeAnalyzerTest();
4309 runJUnitTest(__test, __test.test_visitIsExpression_negated);
4310 });
4311 _ut.test('test_visitIsExpression_notNegated', () {
4312 final __test = new StaticTypeAnalyzerTest();
4313 runJUnitTest(__test, __test.test_visitIsExpression_notNegated);
4314 });
4315 _ut.test('test_visitListLiteral_empty', () {
4316 final __test = new StaticTypeAnalyzerTest();
4317 runJUnitTest(__test, __test.test_visitListLiteral_empty);
4318 });
4319 _ut.test('test_visitListLiteral_nonEmpty', () {
4320 final __test = new StaticTypeAnalyzerTest();
4321 runJUnitTest(__test, __test.test_visitListLiteral_nonEmpty);
4322 });
4323 _ut.test('test_visitMapLiteral_empty', () {
4324 final __test = new StaticTypeAnalyzerTest();
4325 runJUnitTest(__test, __test.test_visitMapLiteral_empty);
4326 });
4327 _ut.test('test_visitMapLiteral_nonEmpty', () {
4328 final __test = new StaticTypeAnalyzerTest();
4329 runJUnitTest(__test, __test.test_visitMapLiteral_nonEmpty);
4330 });
4331 _ut.test('test_visitNamedExpression', () {
4332 final __test = new StaticTypeAnalyzerTest();
4333 runJUnitTest(__test, __test.test_visitNamedExpression);
4334 });
4335 _ut.test('test_visitNullLiteral', () {
4336 final __test = new StaticTypeAnalyzerTest();
4337 runJUnitTest(__test, __test.test_visitNullLiteral);
4338 });
4339 _ut.test('test_visitParenthesizedExpression', () {
4340 final __test = new StaticTypeAnalyzerTest();
4341 runJUnitTest(__test, __test.test_visitParenthesizedExpression);
4342 });
4343 _ut.test('test_visitPostfixExpression_minusMinus', () {
4344 final __test = new StaticTypeAnalyzerTest();
4345 runJUnitTest(__test, __test.test_visitPostfixExpression_minusMinus);
4346 });
4347 _ut.test('test_visitPostfixExpression_plusPlus', () {
4348 final __test = new StaticTypeAnalyzerTest();
4349 runJUnitTest(__test, __test.test_visitPostfixExpression_plusPlus);
4350 });
4351 _ut.test('test_visitPrefixExpression_bang', () {
4352 final __test = new StaticTypeAnalyzerTest();
4353 runJUnitTest(__test, __test.test_visitPrefixExpression_bang);
4354 });
4355 _ut.test('test_visitPrefixExpression_minus', () {
4356 final __test = new StaticTypeAnalyzerTest();
4357 runJUnitTest(__test, __test.test_visitPrefixExpression_minus);
4358 });
4359 _ut.test('test_visitPrefixExpression_minusMinus', () {
4360 final __test = new StaticTypeAnalyzerTest();
4361 runJUnitTest(__test, __test.test_visitPrefixExpression_minusMinus);
4362 });
4363 _ut.test('test_visitPrefixExpression_not', () {
4364 final __test = new StaticTypeAnalyzerTest();
4365 runJUnitTest(__test, __test.test_visitPrefixExpression_not);
4366 });
4367 _ut.test('test_visitPrefixExpression_plusPlus', () {
4368 final __test = new StaticTypeAnalyzerTest();
4369 runJUnitTest(__test, __test.test_visitPrefixExpression_plusPlus);
4370 });
4371 _ut.test('test_visitPrefixExpression_tilde', () {
4372 final __test = new StaticTypeAnalyzerTest();
4373 runJUnitTest(__test, __test.test_visitPrefixExpression_tilde);
4374 });
4375 _ut.test('test_visitPrefixedIdentifier_getter', () {
4376 final __test = new StaticTypeAnalyzerTest();
4377 runJUnitTest(__test, __test.test_visitPrefixedIdentifier_getter);
4378 });
4379 _ut.test('test_visitPrefixedIdentifier_setter', () {
4380 final __test = new StaticTypeAnalyzerTest();
4381 runJUnitTest(__test, __test.test_visitPrefixedIdentifier_setter);
4382 });
4383 _ut.test('test_visitPrefixedIdentifier_variable', () {
4384 final __test = new StaticTypeAnalyzerTest();
4385 runJUnitTest(__test, __test.test_visitPrefixedIdentifier_variable);
4386 });
4387 _ut.test('test_visitPropertyAccess_getter', () {
4388 final __test = new StaticTypeAnalyzerTest();
4389 runJUnitTest(__test, __test.test_visitPropertyAccess_getter);
4390 });
4391 _ut.test('test_visitPropertyAccess_setter', () {
4392 final __test = new StaticTypeAnalyzerTest();
4393 runJUnitTest(__test, __test.test_visitPropertyAccess_setter);
4394 });
4395 _ut.test('test_visitSimpleStringLiteral', () {
4396 final __test = new StaticTypeAnalyzerTest();
4397 runJUnitTest(__test, __test.test_visitSimpleStringLiteral);
4398 });
4399 _ut.test('test_visitStringInterpolation', () {
4400 final __test = new StaticTypeAnalyzerTest();
4401 runJUnitTest(__test, __test.test_visitStringInterpolation);
4402 });
4403 _ut.test('test_visitSuperExpression', () {
4404 final __test = new StaticTypeAnalyzerTest();
4405 runJUnitTest(__test, __test.test_visitSuperExpression);
4406 });
4407 _ut.test('test_visitThisExpression', () {
4408 final __test = new StaticTypeAnalyzerTest();
4409 runJUnitTest(__test, __test.test_visitThisExpression);
4410 });
4411 _ut.test('test_visitThrowExpression_withValue', () {
4412 final __test = new StaticTypeAnalyzerTest();
4413 runJUnitTest(__test, __test.test_visitThrowExpression_withValue);
4414 });
4415 _ut.test('test_visitThrowExpression_withoutValue', () {
4416 final __test = new StaticTypeAnalyzerTest();
4417 runJUnitTest(__test, __test.test_visitThrowExpression_withoutValue);
4418 });
4419 });
4420 }
4421 }
4422 class EnclosedScopeTest extends ResolverTestCase {
4423 void test_define_duplicate() {
4424 LibraryElement definingLibrary2 = createTestLibrary();
4425 GatheringErrorListener errorListener2 = new GatheringErrorListener();
4426 Scope rootScope = new Scope_10(definingLibrary2, errorListener2);
4427 EnclosedScope scope = new EnclosedScope(rootScope);
4428 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4429 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4430 scope.define(element1);
4431 scope.define(element2);
4432 errorListener2.assertErrors3([ErrorSeverity.ERROR]);
4433 }
4434 void test_define_normal() {
4435 LibraryElement definingLibrary3 = createTestLibrary();
4436 GatheringErrorListener errorListener3 = new GatheringErrorListener();
4437 Scope rootScope = new Scope_11(definingLibrary3, errorListener3);
4438 EnclosedScope outerScope = new EnclosedScope(rootScope);
4439 EnclosedScope innerScope = new EnclosedScope(outerScope);
4440 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4441 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v2"));
4442 outerScope.define(element1);
4443 innerScope.define(element2);
4444 errorListener3.assertNoErrors();
4445 }
4446 static dartSuite() {
4447 _ut.group('EnclosedScopeTest', () {
4448 _ut.test('test_define_duplicate', () {
4449 final __test = new EnclosedScopeTest();
4450 runJUnitTest(__test, __test.test_define_duplicate);
4451 });
4452 _ut.test('test_define_normal', () {
4453 final __test = new EnclosedScopeTest();
4454 runJUnitTest(__test, __test.test_define_normal);
4455 });
4456 });
4457 }
4458 }
4459 class Scope_10 extends Scope {
4460 LibraryElement definingLibrary2;
4461 GatheringErrorListener errorListener2;
4462 Scope_10(this.definingLibrary2, this.errorListener2) : super();
4463 LibraryElement get definingLibrary => definingLibrary2;
4464 AnalysisErrorListener get errorListener => errorListener2;
4465 Element lookup3(String name, LibraryElement referencingLibrary) => null;
4466 }
4467 class Scope_11 extends Scope {
4468 LibraryElement definingLibrary3;
4469 GatheringErrorListener errorListener3;
4470 Scope_11(this.definingLibrary3, this.errorListener3) : super();
4471 LibraryElement get definingLibrary => definingLibrary3;
4472 AnalysisErrorListener get errorListener => errorListener3;
4473 Element lookup3(String name, LibraryElement referencingLibrary) => null;
4474 }
4475 class LibraryElementBuilderTest extends EngineTestCase {
4476 /**
4477 * The source factory used to create {@link Source sources}.
4478 */
4479 SourceFactory _sourceFactory;
4480 void setUp() {
4481 _sourceFactory = new SourceFactory.con2([new FileUriResolver()]);
4482 }
4483 void test_empty() {
4484 Source librarySource = addSource("/lib.dart", "library lib;");
4485 LibraryElement element = buildLibrary(librarySource, []);
4486 JUnitTestCase.assertNotNull(element);
4487 JUnitTestCase.assertEquals("lib", element.name);
4488 JUnitTestCase.assertNull(element.entryPoint);
4489 EngineTestCase.assertLength(0, element.importedLibraries);
4490 EngineTestCase.assertLength(0, element.imports);
4491 JUnitTestCase.assertNull(element.library);
4492 EngineTestCase.assertLength(0, element.prefixes);
4493 EngineTestCase.assertLength(0, element.parts);
4494 CompilationUnitElement unit = element.definingCompilationUnit;
4495 JUnitTestCase.assertNotNull(unit);
4496 JUnitTestCase.assertEquals("lib.dart", unit.name);
4497 JUnitTestCase.assertEquals(element, unit.library);
4498 EngineTestCase.assertLength(0, unit.accessors);
4499 EngineTestCase.assertLength(0, unit.functions);
4500 EngineTestCase.assertLength(0, unit.typeAliases);
4501 EngineTestCase.assertLength(0, unit.types);
4502 EngineTestCase.assertLength(0, unit.topLevelVariables);
4503 }
4504 void test_invalidUri_part() {
4505 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" library lib;", "", "part '\${'a'}.dart';"]));
4506 LibraryElement element = buildLibrary(librarySource, [CompileTimeErrorCode.U RI_WITH_INTERPOLATION]);
4507 JUnitTestCase.assertNotNull(element);
4508 }
4509 void test_missingLibraryDirectiveWithPart() {
4510 addSource("/a.dart", EngineTestCase.createSource(["part of lib;"]));
4511 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" part 'a.dart';"]));
4512 LibraryElement element = buildLibrary(librarySource, [ResolverErrorCode.MISS ING_LIBRARY_DIRECTIVE_WITH_PART]);
4513 JUnitTestCase.assertNotNull(element);
4514 }
4515 void test_missingPartOfDirective() {
4516 addSource("/a.dart", "class A {}");
4517 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" library lib;", "", "part 'a.dart';"]));
4518 LibraryElement element = buildLibrary(librarySource, [ResolverErrorCode.MISS ING_PART_OF_DIRECTIVE]);
4519 JUnitTestCase.assertNotNull(element);
4520 }
4521 void test_multipleFiles() {
4522 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" library lib;", "part 'first.dart';", "part 'second.dart';", "", "class A {}"]));
4523 addSource("/first.dart", EngineTestCase.createSource(["part of lib;", "class B {}"]));
4524 addSource("/second.dart", EngineTestCase.createSource(["part of lib;", "clas s C {}"]));
4525 LibraryElement element = buildLibrary(librarySource, []);
4526 JUnitTestCase.assertNotNull(element);
4527 List<CompilationUnitElement> sourcedUnits = element.parts;
4528 EngineTestCase.assertLength(2, sourcedUnits);
4529 assertTypes(element.definingCompilationUnit, ["A"]);
4530 if (sourcedUnits[0].name == "first.dart") {
4531 assertTypes(sourcedUnits[0], ["B"]);
4532 assertTypes(sourcedUnits[1], ["C"]);
4533 } else {
4534 assertTypes(sourcedUnits[0], ["C"]);
4535 assertTypes(sourcedUnits[1], ["B"]);
4536 }
4537 }
4538 void test_singleFile() {
4539 Source librarySource = addSource("/lib.dart", EngineTestCase.createSource([" library lib;", "", "class A {}"]));
4540 LibraryElement element = buildLibrary(librarySource, []);
4541 JUnitTestCase.assertNotNull(element);
4542 assertTypes(element.definingCompilationUnit, ["A"]);
4543 }
4544 /**
4545 * Add a source file to the content provider. The file path should be absolute .
4546 * @param filePath the path of the file being added
4547 * @param contents the contents to be returned by the content provider for the specified file
4548 * @return the source object representing the added file
4549 */
4550 Source addSource(String filePath, String contents) {
4551 Source source = new FileBasedSource.con1(_sourceFactory, FileUtilities2.crea teFile(filePath));
4552 _sourceFactory.setContents(source, contents);
4553 return source;
4554 }
4555 /**
4556 * Ensure that there are elements representing all of the types in the given a rray of type names.
4557 * @param unit the compilation unit containing the types
4558 * @param typeNames the names of the types that should be found
4559 */
4560 void assertTypes(CompilationUnitElement unit, List<String> typeNames) {
4561 JUnitTestCase.assertNotNull(unit);
4562 List<ClassElement> types3 = unit.types;
4563 EngineTestCase.assertLength(typeNames.length, types3);
4564 for (ClassElement type in types3) {
4565 JUnitTestCase.assertNotNull(type);
4566 String actualTypeName = type.name;
4567 bool wasExpected = false;
4568 for (String expectedTypeName in typeNames) {
4569 if (expectedTypeName == actualTypeName) {
4570 wasExpected = true;
4571 }
4572 }
4573 if (!wasExpected) {
4574 JUnitTestCase.fail("Found unexpected type ${actualTypeName}");
4575 }
4576 }
4577 }
4578 /**
4579 * Build the element model for the library whose defining compilation unit has the given source.
4580 * @param librarySource the source of the defining compilation unit for the li brary
4581 * @param expectedErrorCodes the errors that are expected to be found while bu ilding the element
4582 * model
4583 * @return the element model that was built for the library
4584 * @throws Exception if the element model could not be built
4585 */
4586 LibraryElement buildLibrary(Source librarySource, List<ErrorCode> expectedErro rCodes) {
4587 AnalysisContextImpl context = new AnalysisContextImpl();
4588 context.sourceFactory = new SourceFactory.con2([new DartUriResolver(DartSdk. defaultSdk), new FileUriResolver()]);
4589 GatheringErrorListener listener = new GatheringErrorListener();
4590 LibraryResolver resolver = new LibraryResolver.con2(context, listener);
4591 LibraryElementBuilder builder = new LibraryElementBuilder(resolver);
4592 Library library = resolver.createLibrary(librarySource) as Library;
4593 LibraryElement element = builder.buildLibrary(library);
4594 listener.assertErrors2(expectedErrorCodes);
4595 return element;
4596 }
4597 static dartSuite() {
4598 _ut.group('LibraryElementBuilderTest', () {
4599 _ut.test('test_empty', () {
4600 final __test = new LibraryElementBuilderTest();
4601 runJUnitTest(__test, __test.test_empty);
4602 });
4603 _ut.test('test_invalidUri_part', () {
4604 final __test = new LibraryElementBuilderTest();
4605 runJUnitTest(__test, __test.test_invalidUri_part);
4606 });
4607 _ut.test('test_missingLibraryDirectiveWithPart', () {
4608 final __test = new LibraryElementBuilderTest();
4609 runJUnitTest(__test, __test.test_missingLibraryDirectiveWithPart);
4610 });
4611 _ut.test('test_missingPartOfDirective', () {
4612 final __test = new LibraryElementBuilderTest();
4613 runJUnitTest(__test, __test.test_missingPartOfDirective);
4614 });
4615 _ut.test('test_multipleFiles', () {
4616 final __test = new LibraryElementBuilderTest();
4617 runJUnitTest(__test, __test.test_multipleFiles);
4618 });
4619 _ut.test('test_singleFile', () {
4620 final __test = new LibraryElementBuilderTest();
4621 runJUnitTest(__test, __test.test_singleFile);
4622 });
4623 });
4624 }
4625 }
4626 class ScopeTest extends ResolverTestCase {
4627 void test_define_duplicate() {
4628 LibraryElement definingLibrary = createTestLibrary();
4629 GatheringErrorListener errorListener = new GatheringErrorListener();
4630 ScopeTest_TestScope scope = new ScopeTest_TestScope(definingLibrary, errorLi stener);
4631 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4632 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4633 scope.define(element1);
4634 scope.define(element2);
4635 errorListener.assertErrors3([ErrorSeverity.ERROR]);
4636 }
4637 void test_define_normal() {
4638 LibraryElement definingLibrary = createTestLibrary();
4639 GatheringErrorListener errorListener = new GatheringErrorListener();
4640 ScopeTest_TestScope scope = new ScopeTest_TestScope(definingLibrary, errorLi stener);
4641 VariableElement element1 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v1"));
4642 VariableElement element2 = ElementFactory.localVariableElement(ASTFactory.id entifier2("v2"));
4643 scope.define(element1);
4644 scope.define(element2);
4645 errorListener.assertNoErrors();
4646 }
4647 void test_getDefiningLibrary() {
4648 LibraryElement definingLibrary = createTestLibrary();
4649 Scope scope = new ScopeTest_TestScope(definingLibrary, null);
4650 JUnitTestCase.assertEquals(definingLibrary, scope.definingLibrary);
4651 }
4652 void test_getErrorListener() {
4653 LibraryElement definingLibrary = new LibraryElementImpl(new AnalysisContextI mpl(), ASTFactory.libraryIdentifier2(["test"]));
4654 GatheringErrorListener errorListener = new GatheringErrorListener();
4655 Scope scope = new ScopeTest_TestScope(definingLibrary, errorListener);
4656 JUnitTestCase.assertEquals(errorListener, scope.errorListener);
4657 }
4658 void test_isPrivateName_nonPrivate() {
4659 JUnitTestCase.assertFalse(Scope.isPrivateName("Public"));
4660 }
4661 void test_isPrivateName_private() {
4662 JUnitTestCase.assertTrue(Scope.isPrivateName("_Private"));
4663 }
4664 static dartSuite() {
4665 _ut.group('ScopeTest', () {
4666 _ut.test('test_define_duplicate', () {
4667 final __test = new ScopeTest();
4668 runJUnitTest(__test, __test.test_define_duplicate);
4669 });
4670 _ut.test('test_define_normal', () {
4671 final __test = new ScopeTest();
4672 runJUnitTest(__test, __test.test_define_normal);
4673 });
4674 _ut.test('test_getDefiningLibrary', () {
4675 final __test = new ScopeTest();
4676 runJUnitTest(__test, __test.test_getDefiningLibrary);
4677 });
4678 _ut.test('test_getErrorListener', () {
4679 final __test = new ScopeTest();
4680 runJUnitTest(__test, __test.test_getErrorListener);
4681 });
4682 _ut.test('test_isPrivateName_nonPrivate', () {
4683 final __test = new ScopeTest();
4684 runJUnitTest(__test, __test.test_isPrivateName_nonPrivate);
4685 });
4686 _ut.test('test_isPrivateName_private', () {
4687 final __test = new ScopeTest();
4688 runJUnitTest(__test, __test.test_isPrivateName_private);
4689 });
4690 });
4691 }
4692 }
4693 /**
4694 * A non-abstract subclass that can be used for testing purposes.
4695 */
4696 class ScopeTest_TestScope extends Scope {
4697 /**
4698 * The element representing the library in which this scope is enclosed.
4699 */
4700 LibraryElement _definingLibrary;
4701 /**
4702 * The listener that is to be informed when an error is encountered.
4703 */
4704 AnalysisErrorListener _errorListener;
4705 ScopeTest_TestScope(LibraryElement definingLibrary, AnalysisErrorListener erro rListener) {
4706 this._definingLibrary = definingLibrary;
4707 this._errorListener = errorListener;
4708 }
4709 LibraryElement get definingLibrary => _definingLibrary;
4710 AnalysisErrorListener get errorListener => _errorListener;
4711 Element lookup3(String name, LibraryElement referencingLibrary) => localLookup (name, referencingLibrary);
4712 }
4713 class SimpleResolverTest extends ResolverTestCase {
4714 void fail_caseExpressionTypeImplementsEquals_Object() {
4715 Source source = addSource("/test.dart", EngineTestCase.createSource(["class IntWrapper {", " final int value;", " const IntWrapper(this.value);", "}", "", "f(IntWrapper intWrapper) {", " switch(intWrapper) {", " case(const IntWrap per(1)) : return 1;", " default: return 0;", " }", "}"]));
4716 resolve(source, []);
4717 assertNoErrors();
4718 verify([source]);
4719 }
4720 void fail_staticInvocation() {
4721 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static int get g => (a,b) => 0;", "}", "class B {", " f() {", " A.g (1,0);", " }", "}"]));
4722 resolve(source, []);
4723 assertNoErrors();
4724 verify([source]);
4725 }
4726 void test_argumentDefinitionTestNonParameter_formalParameter() {
4727 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(var v) {", " return ?v;", "}"]));
4728 resolve(source, []);
4729 assertNoErrors();
4730 verify([source]);
4731 }
4732 void test_argumentDefinitionTestNonParameter_namedParameter() {
4733 Source source = addSource("/test.dart", EngineTestCase.createSource(["f({var v : 0}) {", " return ?v;", "}"]));
4734 resolve(source, []);
4735 assertNoErrors();
4736 verify([source]);
4737 }
4738 void test_argumentDefinitionTestNonParameter_optionalParameter() {
4739 Source source = addSource("/test.dart", EngineTestCase.createSource(["f([var v]) {", " return ?v;", "}"]));
4740 resolve(source, []);
4741 assertNoErrors();
4742 verify([source]);
4743 }
4744 void test_breakWithoutLabelInSwitch() {
4745 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m(int i) {", " switch (i) {", " case 0:", " break;" , " }", " }", "}"]));
4746 resolve(source, []);
4747 assertNoErrors();
4748 verify([source]);
4749 }
4750 void test_builtInIdentifierAsType_dynamic() {
4751 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " dynamic x;", "}"]));
4752 resolve(source, []);
4753 assertNoErrors();
4754 verify([source]);
4755 }
4756 void test_caseExpressionTypeImplementsEquals_int() {
4757 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(int i) {", " switch(i) {", " case(1) : return 1;", " default: return 0;", " }", "}"]));
4758 resolve(source, []);
4759 assertNoErrors();
4760 verify([source]);
4761 }
4762 void test_caseExpressionTypeImplementsEquals_String() {
4763 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(Stri ng s) {", " switch(s) {", " case('1') : return 1;", " default: return 0;" , " }", "}"]));
4764 resolve(source, []);
4765 assertNoErrors();
4766 verify([source]);
4767 }
4768 void test_class_extends_implements() {
4769 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends B implements C {}", "class B {}", "class C {}"]));
4770 resolve(source, []);
4771 assertNoErrors();
4772 verify([source]);
4773 }
4774 void test_constConstructorWithNonFinalField_const() {
4775 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " const int x;", " const A() {}", "}"]));
4776 resolve(source, []);
4777 assertNoErrors();
4778 verify([source]);
4779 }
4780 void test_constConstructorWithNonFinalField_final() {
4781 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " final int x;", " const A() {}", "}"]));
4782 resolve(source, []);
4783 assertNoErrors();
4784 verify([source]);
4785 }
4786 void test_duplicateDefinition_getter() {
4787 Source source = addSource("/test.dart", EngineTestCase.createSource(["bool g et a => true;"]));
4788 resolve(source, []);
4789 assertNoErrors();
4790 verify([source]);
4791 }
4792 void test_empty() {
4793 Source source = addSource("/test.dart", "");
4794 resolve(source, []);
4795 assertNoErrors();
4796 verify([source]);
4797 }
4798 void test_forEachLoops_nonConflicting() {
4799 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " List list = [1,2,3];", " for (int x in list) {}", " for (int x in list) { }", "}"]));
4800 resolve(source, []);
4801 assertNoErrors();
4802 verify([source]);
4803 }
4804 void test_forLoops_nonConflicting() {
4805 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " for (int i = 0; i < 3; i++) {", " }", " for (int i = 0; i < 3; i++) {", " }", "}"]));
4806 resolve(source, []);
4807 assertNoErrors();
4808 verify([source]);
4809 }
4810 void test_functionTypeAlias() {
4811 Source source = addSource("/test.dart", EngineTestCase.createSource(["typede f bool P(e);", "class A {", " P p;", " m(e) {", " if (p(e)) {}", " }", "}" ]));
4812 resolve(source, []);
4813 assertNoErrors();
4814 verify([source]);
4815 }
4816 void test_getterAndSetterWithDifferentTypes() {
4817 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " int get f => 0;", " void set f(String s) {}", "}", "g (A a) {", " a.f = a.f.toString();", "}"]));
4818 resolve(source, []);
4819 assertNoErrors();
4820 verify([source]);
4821 }
4822 void test_invalidAssignment() {
4823 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " var x;", " var y;", " x = y;", "}"]));
4824 resolve(source, []);
4825 assertNoErrors();
4826 verify([source]);
4827 }
4828 void test_invalidAssignment_toDynamic() {
4829 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " var g;", " g = () => 0;", "}"]));
4830 resolve(source, []);
4831 assertNoErrors();
4832 verify([source]);
4833 }
4834 void test_invocationOfNonFunction_dynamic() {
4835 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var f;", "}", "class B extends A {", " g() {", " f();", " }", "}"] ));
4836 resolve(source, []);
4837 assertNoErrors();
4838 verify([source]);
4839 }
4840 void test_invocationOfNonFunction_getter() {
4841 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " var g;", "}", "f() {", " A a;", " a.g();", "}"]));
4842 resolve(source, []);
4843 assertNoErrors();
4844 verify([source]);
4845 }
4846 void test_invocationOfNonFunction_localVariable() {
4847 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " var g;", " g();", "}"]));
4848 resolve(source, []);
4849 assertNoErrors();
4850 verify([source]);
4851 }
4852 void test_isValidMixin_badSuperclass() {
4853 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A extends B {}", "class B {}"]));
4854 LibraryElement library = resolve(source, []);
4855 JUnitTestCase.assertNotNull(library);
4856 CompilationUnitElement unit = library.definingCompilationUnit;
4857 JUnitTestCase.assertNotNull(unit);
4858 List<ClassElement> classes = unit.types;
4859 EngineTestCase.assertLength(2, classes);
4860 JUnitTestCase.assertFalse(classes[0].isValidMixin());
4861 assertNoErrors();
4862 verify([source]);
4863 }
4864 void test_isValidMixin_constructor() {
4865 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " A() {}", "}"]));
4866 LibraryElement library = resolve(source, []);
4867 JUnitTestCase.assertNotNull(library);
4868 CompilationUnitElement unit = library.definingCompilationUnit;
4869 JUnitTestCase.assertNotNull(unit);
4870 List<ClassElement> classes = unit.types;
4871 EngineTestCase.assertLength(1, classes);
4872 JUnitTestCase.assertFalse(classes[0].isValidMixin());
4873 assertNoErrors();
4874 verify([source]);
4875 }
4876 void test_isValidMixin_super() {
4877 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " toString() {", " return super.toString();", " }", "}"]));
4878 LibraryElement library = resolve(source, []);
4879 JUnitTestCase.assertNotNull(library);
4880 CompilationUnitElement unit = library.definingCompilationUnit;
4881 JUnitTestCase.assertNotNull(unit);
4882 List<ClassElement> classes = unit.types;
4883 EngineTestCase.assertLength(1, classes);
4884 JUnitTestCase.assertFalse(classes[0].isValidMixin());
4885 assertNoErrors();
4886 verify([source]);
4887 }
4888 void test_isValidMixin_valid() {
4889 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}"]));
4890 LibraryElement library = resolve(source, []);
4891 JUnitTestCase.assertNotNull(library);
4892 CompilationUnitElement unit = library.definingCompilationUnit;
4893 JUnitTestCase.assertNotNull(unit);
4894 List<ClassElement> classes = unit.types;
4895 EngineTestCase.assertLength(1, classes);
4896 JUnitTestCase.assertTrue(classes[0].isValidMixin());
4897 assertNoErrors();
4898 verify([source]);
4899 }
4900 void test_methodCascades() {
4901 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " void m1() {}", " void m2() {}", " void m() {", " A a = new A();", " a..m1()", " ..m2();", " }", "}"]));
4902 resolve(source, []);
4903 assertNoErrors();
4904 verify([source]);
4905 }
4906 void test_methodCascades_withSetter() {
4907 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " String name;", " void m1() {}", " void m2() {}", " void m() {", " A a = new A();", " a..m1()", " ..name = 'name'", " ..m2();", " }", "}"]));
4908 resolve(source, []);
4909 assertNoErrors();
4910 verify([source]);
4911 }
4912 void test_newWithAbstractClass_factory() {
4913 Source source = addSource("/test.dart", EngineTestCase.createSource(["abstra ct class A {", " factory A() { return new B(); }", "}", "class B implements A { ", " B() {}", "}", "A f() {", " return new A();", "}"]));
4914 resolve(source, []);
4915 assertNoErrors();
4916 verify([source]);
4917 }
4918 void test_nonBoolExpression_assert_bool() {
4919 Source source = addSource("/test.dart", EngineTestCase.createSource(["f() {" , " assert(true);", "}"]));
4920 resolve(source, []);
4921 assertNoErrors();
4922 verify([source]);
4923 }
4924 void test_nonBoolExpression_assert_functionType() {
4925 Source source = addSource("/test.dart", EngineTestCase.createSource(["bool m akeAssertion() => true;", "f() {", " assert(makeAssertion);", "}"]));
4926 resolve(source, []);
4927 assertNoErrors();
4928 verify([source]);
4929 }
4930 void test_resolveAgainstNull() {
4931 Source source = addSource("/test.dart", EngineTestCase.createSource(["f(var p) {", " return null == p;", "}"]));
4932 resolve(source, []);
4933 assertNoErrors();
4934 verify([source]);
4935 }
4936 void test_returnOfInvalidType_dynamic() {
4937 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {", " static void testLogicalOp() {", " testOr(a, b, onTypeError) {", " try {", " return a || b;", " } on TypeError catch (t) {", " return onTypeError;", " }", " }", " }", "}"]));
4938 resolve(source, []);
4939 assertNoErrors();
4940 verify([source]);
4941 }
4942 void test_returnOfInvalidType_subtype() {
4943 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "A f(B b) { return b; }"]));
4944 resolve(source, []);
4945 assertNoErrors();
4946 verify([source]);
4947 }
4948 void test_returnOfInvalidType_supertype() {
4949 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "B f(A a) { return a; }"]));
4950 resolve(source, []);
4951 assertNoErrors();
4952 verify([source]);
4953 }
4954 void test_typeArgumentNotMatchingBounds_const() {
4955 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class G<E extends A> {", " const G() {}", "}", "f() { return const G<B>(); }"]));
4956 resolve(source, []);
4957 assertNoErrors();
4958 verify([source]);
4959 }
4960 void test_typeArgumentNotMatchingBounds_new() {
4961 Source source = addSource("/test.dart", EngineTestCase.createSource(["class A {}", "class B extends A {}", "class G<E extends A> {}", "f() { return new G<B> (); }"]));
4962 resolve(source, []);
4963 assertNoErrors();
4964 verify([source]);
4965 }
4966 static dartSuite() {
4967 _ut.group('SimpleResolverTest', () {
4968 _ut.test('test_argumentDefinitionTestNonParameter_formalParameter', () {
4969 final __test = new SimpleResolverTest();
4970 runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_form alParameter);
4971 });
4972 _ut.test('test_argumentDefinitionTestNonParameter_namedParameter', () {
4973 final __test = new SimpleResolverTest();
4974 runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_name dParameter);
4975 });
4976 _ut.test('test_argumentDefinitionTestNonParameter_optionalParameter', () {
4977 final __test = new SimpleResolverTest();
4978 runJUnitTest(__test, __test.test_argumentDefinitionTestNonParameter_opti onalParameter);
4979 });
4980 _ut.test('test_breakWithoutLabelInSwitch', () {
4981 final __test = new SimpleResolverTest();
4982 runJUnitTest(__test, __test.test_breakWithoutLabelInSwitch);
4983 });
4984 _ut.test('test_builtInIdentifierAsType_dynamic', () {
4985 final __test = new SimpleResolverTest();
4986 runJUnitTest(__test, __test.test_builtInIdentifierAsType_dynamic);
4987 });
4988 _ut.test('test_caseExpressionTypeImplementsEquals_String', () {
4989 final __test = new SimpleResolverTest();
4990 runJUnitTest(__test, __test.test_caseExpressionTypeImplementsEquals_Stri ng);
4991 });
4992 _ut.test('test_caseExpressionTypeImplementsEquals_int', () {
4993 final __test = new SimpleResolverTest();
4994 runJUnitTest(__test, __test.test_caseExpressionTypeImplementsEquals_int) ;
4995 });
4996 _ut.test('test_class_extends_implements', () {
4997 final __test = new SimpleResolverTest();
4998 runJUnitTest(__test, __test.test_class_extends_implements);
4999 });
5000 _ut.test('test_constConstructorWithNonFinalField_const', () {
5001 final __test = new SimpleResolverTest();
5002 runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_const );
5003 });
5004 _ut.test('test_constConstructorWithNonFinalField_final', () {
5005 final __test = new SimpleResolverTest();
5006 runJUnitTest(__test, __test.test_constConstructorWithNonFinalField_final );
5007 });
5008 _ut.test('test_duplicateDefinition_getter', () {
5009 final __test = new SimpleResolverTest();
5010 runJUnitTest(__test, __test.test_duplicateDefinition_getter);
5011 });
5012 _ut.test('test_empty', () {
5013 final __test = new SimpleResolverTest();
5014 runJUnitTest(__test, __test.test_empty);
5015 });
5016 _ut.test('test_forEachLoops_nonConflicting', () {
5017 final __test = new SimpleResolverTest();
5018 runJUnitTest(__test, __test.test_forEachLoops_nonConflicting);
5019 });
5020 _ut.test('test_forLoops_nonConflicting', () {
5021 final __test = new SimpleResolverTest();
5022 runJUnitTest(__test, __test.test_forLoops_nonConflicting);
5023 });
5024 _ut.test('test_functionTypeAlias', () {
5025 final __test = new SimpleResolverTest();
5026 runJUnitTest(__test, __test.test_functionTypeAlias);
5027 });
5028 _ut.test('test_getterAndSetterWithDifferentTypes', () {
5029 final __test = new SimpleResolverTest();
5030 runJUnitTest(__test, __test.test_getterAndSetterWithDifferentTypes);
5031 });
5032 _ut.test('test_invalidAssignment', () {
5033 final __test = new SimpleResolverTest();
5034 runJUnitTest(__test, __test.test_invalidAssignment);
5035 });
5036 _ut.test('test_invalidAssignment_toDynamic', () {
5037 final __test = new SimpleResolverTest();
5038 runJUnitTest(__test, __test.test_invalidAssignment_toDynamic);
5039 });
5040 _ut.test('test_invocationOfNonFunction_dynamic', () {
5041 final __test = new SimpleResolverTest();
5042 runJUnitTest(__test, __test.test_invocationOfNonFunction_dynamic);
5043 });
5044 _ut.test('test_invocationOfNonFunction_getter', () {
5045 final __test = new SimpleResolverTest();
5046 runJUnitTest(__test, __test.test_invocationOfNonFunction_getter);
5047 });
5048 _ut.test('test_invocationOfNonFunction_localVariable', () {
5049 final __test = new SimpleResolverTest();
5050 runJUnitTest(__test, __test.test_invocationOfNonFunction_localVariable);
5051 });
5052 _ut.test('test_isValidMixin_badSuperclass', () {
5053 final __test = new SimpleResolverTest();
5054 runJUnitTest(__test, __test.test_isValidMixin_badSuperclass);
5055 });
5056 _ut.test('test_isValidMixin_constructor', () {
5057 final __test = new SimpleResolverTest();
5058 runJUnitTest(__test, __test.test_isValidMixin_constructor);
5059 });
5060 _ut.test('test_isValidMixin_super', () {
5061 final __test = new SimpleResolverTest();
5062 runJUnitTest(__test, __test.test_isValidMixin_super);
5063 });
5064 _ut.test('test_isValidMixin_valid', () {
5065 final __test = new SimpleResolverTest();
5066 runJUnitTest(__test, __test.test_isValidMixin_valid);
5067 });
5068 _ut.test('test_methodCascades', () {
5069 final __test = new SimpleResolverTest();
5070 runJUnitTest(__test, __test.test_methodCascades);
5071 });
5072 _ut.test('test_methodCascades_withSetter', () {
5073 final __test = new SimpleResolverTest();
5074 runJUnitTest(__test, __test.test_methodCascades_withSetter);
5075 });
5076 _ut.test('test_newWithAbstractClass_factory', () {
5077 final __test = new SimpleResolverTest();
5078 runJUnitTest(__test, __test.test_newWithAbstractClass_factory);
5079 });
5080 _ut.test('test_nonBoolExpression_assert_bool', () {
5081 final __test = new SimpleResolverTest();
5082 runJUnitTest(__test, __test.test_nonBoolExpression_assert_bool);
5083 });
5084 _ut.test('test_nonBoolExpression_assert_functionType', () {
5085 final __test = new SimpleResolverTest();
5086 runJUnitTest(__test, __test.test_nonBoolExpression_assert_functionType);
5087 });
5088 _ut.test('test_resolveAgainstNull', () {
5089 final __test = new SimpleResolverTest();
5090 runJUnitTest(__test, __test.test_resolveAgainstNull);
5091 });
5092 _ut.test('test_returnOfInvalidType_dynamic', () {
5093 final __test = new SimpleResolverTest();
5094 runJUnitTest(__test, __test.test_returnOfInvalidType_dynamic);
5095 });
5096 _ut.test('test_returnOfInvalidType_subtype', () {
5097 final __test = new SimpleResolverTest();
5098 runJUnitTest(__test, __test.test_returnOfInvalidType_subtype);
5099 });
5100 _ut.test('test_returnOfInvalidType_supertype', () {
5101 final __test = new SimpleResolverTest();
5102 runJUnitTest(__test, __test.test_returnOfInvalidType_supertype);
5103 });
5104 _ut.test('test_typeArgumentNotMatchingBounds_const', () {
5105 final __test = new SimpleResolverTest();
5106 runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_const);
5107 });
5108 _ut.test('test_typeArgumentNotMatchingBounds_new', () {
5109 final __test = new SimpleResolverTest();
5110 runJUnitTest(__test, __test.test_typeArgumentNotMatchingBounds_new);
5111 });
5112 });
5113 }
5114 }
5115 main() {
5116 /*ElementResolverTest.dartSuite();
5117 LibraryElementBuilderTest.dartSuite();
5118 LibraryTest.dartSuite();
5119 StaticTypeAnalyzerTest.dartSuite();
5120 TypeProviderImplTest.dartSuite();
5121 TypeResolverVisitorTest.dartSuite();
5122 EnclosedScopeTest.dartSuite();
5123 LibraryImportScopeTest.dartSuite();
5124 LibraryScopeTest.dartSuite();
5125 ScopeTest.dartSuite();
5126 CompileTimeErrorCodeTest.dartSuite();
5127 ErrorResolverTest.dartSuite();
5128 SimpleResolverTest.dartSuite();
5129 StaticTypeWarningCodeTest.dartSuite();
5130 StaticWarningCodeTest.dartSuite();*/
5131 }
OLDNEW
« no previous file with comments | « pkg/analyzer-experimental/test/generated/parser_test.dart ('k') | pkg/analyzer-experimental/test/generated/scanner_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698