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

Side by Side Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1185443002: Support for parsing HTML in the new task model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.src.task.dart_test; 5 library test.src.task.dart_test;
6 6
7 import 'package:analyzer/src/context/cache.dart'; 7 import 'package:analyzer/src/context/cache.dart';
8 import 'package:analyzer/src/generated/ast.dart'; 8 import 'package:analyzer/src/generated/ast.dart';
9 import 'package:analyzer/src/generated/constant.dart'; 9 import 'package:analyzer/src/generated/constant.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() { 61 test_perform_ClassDeclaration_errors_mixinHasNoConstructors() {
62 Source source = newSource('/test.dart', ''' 62 Source source = newSource('/test.dart', '''
63 class B { 63 class B {
64 B({x}); 64 B({x});
65 } 65 }
66 class M {} 66 class M {}
67 class C extends B with M {} 67 class C extends B with M {}
68 '''); 68 ''');
69 LibraryElement libraryElement; 69 LibraryElement libraryElement;
70 { 70 {
71 _computeResult(source, LIBRARY_ELEMENT5); 71 computeResult(source, LIBRARY_ELEMENT5);
72 libraryElement = outputs[LIBRARY_ELEMENT5]; 72 libraryElement = outputs[LIBRARY_ELEMENT5];
73 } 73 }
74 // prepare C 74 // prepare C
75 ClassElement c = libraryElement.getType('C'); 75 ClassElement c = libraryElement.getType('C');
76 expect(c, isNotNull); 76 expect(c, isNotNull);
77 // build constructors 77 // build constructors
78 _computeResult(c, CONSTRUCTORS); 78 computeResult(c, CONSTRUCTORS);
79 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); 79 expect(task, new isInstanceOf<BuildClassConstructorsTask>());
80 _fillErrorListener(CONSTRUCTORS_ERRORS); 80 _fillErrorListener(CONSTRUCTORS_ERRORS);
81 errorListener.assertErrorsWithCodes( 81 errorListener.assertErrorsWithCodes(
82 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 82 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
83 } 83 }
84 84
85 test_perform_ClassDeclaration_explicitConstructors() { 85 test_perform_ClassDeclaration_explicitConstructors() {
86 Source source = newSource('/test.dart', ''' 86 Source source = newSource('/test.dart', '''
87 class B { 87 class B {
88 B(p); 88 B(p);
89 } 89 }
90 class C extends B { 90 class C extends B {
91 C(int a, String b) {} 91 C(int a, String b) {}
92 } 92 }
93 '''); 93 ''');
94 LibraryElement libraryElement; 94 LibraryElement libraryElement;
95 { 95 {
96 _computeResult(source, LIBRARY_ELEMENT5); 96 computeResult(source, LIBRARY_ELEMENT5);
97 libraryElement = outputs[LIBRARY_ELEMENT5]; 97 libraryElement = outputs[LIBRARY_ELEMENT5];
98 } 98 }
99 // prepare C 99 // prepare C
100 ClassElement c = libraryElement.getType('C'); 100 ClassElement c = libraryElement.getType('C');
101 expect(c, isNotNull); 101 expect(c, isNotNull);
102 // build constructors 102 // build constructors
103 _computeResult(c, CONSTRUCTORS); 103 computeResult(c, CONSTRUCTORS);
104 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); 104 expect(task, new isInstanceOf<BuildClassConstructorsTask>());
105 // no errors 105 // no errors
106 expect(outputs[CONSTRUCTORS_ERRORS], isEmpty); 106 expect(outputs[CONSTRUCTORS_ERRORS], isEmpty);
107 // explicit constructor 107 // explicit constructor
108 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; 108 List<ConstructorElement> constructors = outputs[CONSTRUCTORS];
109 expect(constructors, hasLength(1)); 109 expect(constructors, hasLength(1));
110 expect(constructors[0].parameters, hasLength(2)); 110 expect(constructors[0].parameters, hasLength(2));
111 } 111 }
112 112
113 test_perform_ClassTypeAlias() { 113 test_perform_ClassTypeAlias() {
114 Source source = newSource('/test.dart', ''' 114 Source source = newSource('/test.dart', '''
115 class B { 115 class B {
116 B(int i); 116 B(int i);
117 } 117 }
118 class M1 {} 118 class M1 {}
119 class M2 {} 119 class M2 {}
120 120
121 class C2 = C1 with M2; 121 class C2 = C1 with M2;
122 class C1 = B with M1; 122 class C1 = B with M1;
123 '''); 123 ''');
124 LibraryElement libraryElement; 124 LibraryElement libraryElement;
125 { 125 {
126 _computeResult(source, LIBRARY_ELEMENT5); 126 computeResult(source, LIBRARY_ELEMENT5);
127 libraryElement = outputs[LIBRARY_ELEMENT5]; 127 libraryElement = outputs[LIBRARY_ELEMENT5];
128 } 128 }
129 // prepare C2 129 // prepare C2
130 ClassElement class2 = libraryElement.getType('C2'); 130 ClassElement class2 = libraryElement.getType('C2');
131 expect(class2, isNotNull); 131 expect(class2, isNotNull);
132 // build constructors 132 // build constructors
133 _computeResult(class2, CONSTRUCTORS); 133 computeResult(class2, CONSTRUCTORS);
134 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); 134 expect(task, new isInstanceOf<BuildClassConstructorsTask>());
135 List<ConstructorElement> constructors = outputs[CONSTRUCTORS]; 135 List<ConstructorElement> constructors = outputs[CONSTRUCTORS];
136 expect(constructors, hasLength(1)); 136 expect(constructors, hasLength(1));
137 expect(constructors[0].parameters, hasLength(1)); 137 expect(constructors[0].parameters, hasLength(1));
138 } 138 }
139 139
140 test_perform_ClassTypeAlias_errors_mixinHasNoConstructors() { 140 test_perform_ClassTypeAlias_errors_mixinHasNoConstructors() {
141 Source source = newSource('/test.dart', ''' 141 Source source = newSource('/test.dart', '''
142 class B { 142 class B {
143 B({x}); 143 B({x});
144 } 144 }
145 class M {} 145 class M {}
146 class C = B with M; 146 class C = B with M;
147 '''); 147 ''');
148 LibraryElement libraryElement; 148 LibraryElement libraryElement;
149 { 149 {
150 _computeResult(source, LIBRARY_ELEMENT5); 150 computeResult(source, LIBRARY_ELEMENT5);
151 libraryElement = outputs[LIBRARY_ELEMENT5]; 151 libraryElement = outputs[LIBRARY_ELEMENT5];
152 } 152 }
153 // prepare C 153 // prepare C
154 ClassElement c = libraryElement.getType('C'); 154 ClassElement c = libraryElement.getType('C');
155 expect(c, isNotNull); 155 expect(c, isNotNull);
156 // build constructors 156 // build constructors
157 _computeResult(c, CONSTRUCTORS); 157 computeResult(c, CONSTRUCTORS);
158 expect(task, new isInstanceOf<BuildClassConstructorsTask>()); 158 expect(task, new isInstanceOf<BuildClassConstructorsTask>());
159 _fillErrorListener(CONSTRUCTORS_ERRORS); 159 _fillErrorListener(CONSTRUCTORS_ERRORS);
160 errorListener.assertErrorsWithCodes( 160 errorListener.assertErrorsWithCodes(
161 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]); 161 <ErrorCode>[CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS]);
162 } 162 }
163 } 163 }
164 164
165 @reflectiveTest 165 @reflectiveTest
166 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { 166 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest {
167 Source source; 167 Source source;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 class B = Object with A; 255 class B = Object with A;
256 '''); 256 ''');
257 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 257 CompilationUnit unit = outputs[RESOLVED_UNIT1];
258 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; 258 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT];
259 expect(unit, isNotNull); 259 expect(unit, isNotNull);
260 expect(unitElement, isNotNull); 260 expect(unitElement, isNotNull);
261 // invalidate RESOLVED_UNIT1 261 // invalidate RESOLVED_UNIT1
262 CacheEntry cacheEntry = analysisCache.get(target); 262 CacheEntry cacheEntry = analysisCache.get(target);
263 cacheEntry.setState(RESOLVED_UNIT1, CacheState.INVALID); 263 cacheEntry.setState(RESOLVED_UNIT1, CacheState.INVALID);
264 // compute again 264 // compute again
265 _computeResult(target, RESOLVED_UNIT1); 265 computeResult(target, RESOLVED_UNIT1);
266 expect(outputs[COMPILATION_UNIT_ELEMENT], same(unitElement)); 266 expect(outputs[COMPILATION_UNIT_ELEMENT], same(unitElement));
267 expect(outputs[RESOLVED_UNIT1], isNot(same(unit))); 267 expect(outputs[RESOLVED_UNIT1], isNot(same(unit)));
268 } 268 }
269 269
270 void _performBuildTask(String content) { 270 void _performBuildTask(String content) {
271 source = newSource('/test.dart', content); 271 source = newSource('/test.dart', content);
272 target = new LibrarySpecificUnit(source, source); 272 target = new LibrarySpecificUnit(source, source);
273 _computeResult(target, RESOLVED_UNIT1); 273 computeResult(target, RESOLVED_UNIT1);
274 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>()); 274 expect(task, new isInstanceOf<BuildCompilationUnitElementTask>());
275 } 275 }
276 } 276 }
277 277
278 @reflectiveTest 278 @reflectiveTest
279 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest { 279 class BuildDirectiveElementsTaskTest extends _AbstractDartTaskTest {
280 test_constructor() { 280 test_constructor() {
281 BuildDirectiveElementsTask task = 281 BuildDirectiveElementsTask task =
282 new BuildDirectiveElementsTask(context, emptySource); 282 new BuildDirectiveElementsTask(context, emptySource);
283 expect(task, isNotNull); 283 expect(task, isNotNull);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 library libB; 315 library libB;
316 ''', 316 ''',
317 '/libC.dart': ''' 317 '/libC.dart': '''
318 library libC; 318 library libC;
319 ''' 319 '''
320 }); 320 });
321 Source sourceA = sources[0]; 321 Source sourceA = sources[0];
322 Source sourceB = sources[1]; 322 Source sourceB = sources[1];
323 Source sourceC = sources[2]; 323 Source sourceC = sources[2];
324 // perform task 324 // perform task
325 _computeResult(sourceA, LIBRARY_ELEMENT2); 325 computeResult(sourceA, LIBRARY_ELEMENT2);
326 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 326 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
327 // prepare outputs 327 // prepare outputs
328 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2]; 328 LibraryElement libraryElementA = outputs[LIBRARY_ELEMENT2];
329 LibraryElement libraryElementB = _getImportLibraryInput(sourceB); 329 LibraryElement libraryElementB = _getImportLibraryInput(sourceB);
330 LibraryElement libraryElementC = _getExportLibraryInput(sourceC); 330 LibraryElement libraryElementC = _getExportLibraryInput(sourceC);
331 // no errors 331 // no errors
332 _assertErrorsWithCodes([]); 332 _assertErrorsWithCodes([]);
333 // validate directives 333 // validate directives
334 CompilationUnit libraryUnitA = context 334 CompilationUnit libraryUnitA = context
335 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) 335 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA))
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 '/libA.dart': ''' 368 '/libA.dart': '''
369 library libA; 369 library libA;
370 import 'libB.dart' show A, B hide C, D; 370 import 'libB.dart' show A, B hide C, D;
371 ''', 371 ''',
372 '/libB.dart': ''' 372 '/libB.dart': '''
373 library libB; 373 library libB;
374 ''' 374 '''
375 }); 375 });
376 Source sourceA = sources[0]; 376 Source sourceA = sources[0];
377 // perform task 377 // perform task
378 _computeResult(sourceA, LIBRARY_ELEMENT2); 378 computeResult(sourceA, LIBRARY_ELEMENT2);
379 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 379 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
380 // prepare outputs 380 // prepare outputs
381 CompilationUnit libraryUnitA = context 381 CompilationUnit libraryUnitA = context
382 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) 382 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA))
383 .getValue(RESOLVED_UNIT1); 383 .getValue(RESOLVED_UNIT1);
384 // no errors 384 // no errors
385 _assertErrorsWithCodes([]); 385 _assertErrorsWithCodes([]);
386 // validate directives 386 // validate directives
387 ImportDirective importNode = libraryUnitA.directives[1]; 387 ImportDirective importNode = libraryUnitA.directives[1];
388 ImportElement importElement = importNode.element; 388 ImportElement importElement = importNode.element;
389 List<NamespaceCombinator> combinators = importElement.combinators; 389 List<NamespaceCombinator> combinators = importElement.combinators;
390 expect(combinators, hasLength(2)); 390 expect(combinators, hasLength(2));
391 { 391 {
392 ShowElementCombinator combinator = combinators[0]; 392 ShowElementCombinator combinator = combinators[0];
393 expect(combinator.offset, 33); 393 expect(combinator.offset, 33);
394 expect(combinator.end, 42); 394 expect(combinator.end, 42);
395 expect(combinator.shownNames, ['A', 'B']); 395 expect(combinator.shownNames, ['A', 'B']);
396 } 396 }
397 { 397 {
398 HideElementCombinator combinator = combinators[1]; 398 HideElementCombinator combinator = combinators[1];
399 expect(combinator.hiddenNames, ['C', 'D']); 399 expect(combinator.hiddenNames, ['C', 'D']);
400 } 400 }
401 } 401 }
402 402
403 test_perform_dartCoreContext() { 403 test_perform_dartCoreContext() {
404 List<Source> sources = newSources({'/libA.dart': ''}); 404 List<Source> sources = newSources({'/libA.dart': ''});
405 Source source = sources[0]; 405 Source source = sources[0];
406 // perform task 406 // perform task
407 _computeResult(source, LIBRARY_ELEMENT2); 407 computeResult(source, LIBRARY_ELEMENT2);
408 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 408 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
409 // prepare outputs 409 // prepare outputs
410 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; 410 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2];
411 // verify that dart:core has SDK context 411 // verify that dart:core has SDK context
412 { 412 {
413 LibraryElement coreLibrary = libraryElement.importedLibraries[0]; 413 LibraryElement coreLibrary = libraryElement.importedLibraries[0];
414 DartSdk dartSdk = context.sourceFactory.dartSdk; 414 DartSdk dartSdk = context.sourceFactory.dartSdk;
415 expect(coreLibrary.context, same(dartSdk.context)); 415 expect(coreLibrary.context, same(dartSdk.context));
416 } 416 }
417 } 417 }
418 418
419 test_perform_error_exportOfNonLibrary() { 419 test_perform_error_exportOfNonLibrary() {
420 List<Source> sources = newSources({ 420 List<Source> sources = newSources({
421 '/libA.dart': ''' 421 '/libA.dart': '''
422 library libA; 422 library libA;
423 export 'part.dart'; 423 export 'part.dart';
424 ''', 424 ''',
425 '/part.dart': ''' 425 '/part.dart': '''
426 part of notLib; 426 part of notLib;
427 ''' 427 '''
428 }); 428 });
429 Source sourceA = sources[0]; 429 Source sourceA = sources[0];
430 // perform task 430 // perform task
431 _computeResult(sourceA, LIBRARY_ELEMENT2); 431 computeResult(sourceA, LIBRARY_ELEMENT2);
432 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 432 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
433 // validate errors 433 // validate errors
434 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]); 434 _assertErrorsWithCodes([CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY]);
435 } 435 }
436 436
437 test_perform_error_importOfNonLibrary() { 437 test_perform_error_importOfNonLibrary() {
438 List<Source> sources = newSources({ 438 List<Source> sources = newSources({
439 '/libA.dart': ''' 439 '/libA.dart': '''
440 library libA; 440 library libA;
441 import 'part.dart'; 441 import 'part.dart';
442 ''', 442 ''',
443 '/part.dart': ''' 443 '/part.dart': '''
444 part of notLib; 444 part of notLib;
445 ''' 445 '''
446 }); 446 });
447 Source sourceA = sources[0]; 447 Source sourceA = sources[0];
448 // perform task 448 // perform task
449 _computeResult(sourceA, LIBRARY_ELEMENT2); 449 computeResult(sourceA, LIBRARY_ELEMENT2);
450 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 450 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
451 // validate errors 451 // validate errors
452 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]); 452 _assertErrorsWithCodes([CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY]);
453 } 453 }
454 454
455 test_perform_hasExtUri() { 455 test_perform_hasExtUri() {
456 List<Source> sources = newSources({ 456 List<Source> sources = newSources({
457 '/lib.dart': ''' 457 '/lib.dart': '''
458 import 'dart-ext:doesNotExist.dart'; 458 import 'dart-ext:doesNotExist.dart';
459 ''' 459 '''
460 }); 460 });
461 Source source = sources[0]; 461 Source source = sources[0];
462 // perform task 462 // perform task
463 _computeResult(source, LIBRARY_ELEMENT2); 463 computeResult(source, LIBRARY_ELEMENT2);
464 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 464 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
465 // prepare outputs 465 // prepare outputs
466 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2]; 466 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT2];
467 expect(libraryElement.hasExtUri, isTrue); 467 expect(libraryElement.hasExtUri, isTrue);
468 } 468 }
469 469
470 test_perform_importPrefix() { 470 test_perform_importPrefix() {
471 List<Source> sources = newSources({ 471 List<Source> sources = newSources({
472 '/libA.dart': ''' 472 '/libA.dart': '''
473 library libA; 473 library libA;
474 import 'libB.dart' as pref; 474 import 'libB.dart' as pref;
475 import 'libC.dart' as pref; 475 import 'libC.dart' as pref;
476 ''', 476 ''',
477 '/libB.dart': ''' 477 '/libB.dart': '''
478 library libB; 478 library libB;
479 ''', 479 ''',
480 '/libC.dart': ''' 480 '/libC.dart': '''
481 library libC; 481 library libC;
482 ''' 482 '''
483 }); 483 });
484 Source sourceA = sources[0]; 484 Source sourceA = sources[0];
485 Source sourceB = sources[1]; 485 Source sourceB = sources[1];
486 // perform task 486 // perform task
487 _computeResult(sourceA, LIBRARY_ELEMENT2); 487 computeResult(sourceA, LIBRARY_ELEMENT2);
488 expect(task, new isInstanceOf<BuildDirectiveElementsTask>()); 488 expect(task, new isInstanceOf<BuildDirectiveElementsTask>());
489 // prepare outputs 489 // prepare outputs
490 CompilationUnit libraryUnitA = context 490 CompilationUnit libraryUnitA = context
491 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA)) 491 .getCacheEntry(new LibrarySpecificUnit(sourceA, sourceA))
492 .getValue(RESOLVED_UNIT1); 492 .getValue(RESOLVED_UNIT1);
493 // validate directives 493 // validate directives
494 { 494 {
495 ImportDirective importNodeB = libraryUnitA.directives[1]; 495 ImportDirective importNodeB = libraryUnitA.directives[1];
496 SimpleIdentifier prefixNodeB = importNodeB.prefix; 496 SimpleIdentifier prefixNodeB = importNodeB.prefix;
497 ImportElement importElementB = importNodeB.element; 497 ImportElement importElementB = importNodeB.element;
(...skipping 29 matching lines...) Expand all
527 } 527 }
528 528
529 @reflectiveTest 529 @reflectiveTest
530 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { 530 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest {
531 test_perform() { 531 test_perform() {
532 Source source = newSource('/test.dart', ''' 532 Source source = newSource('/test.dart', '''
533 enum MyEnum { 533 enum MyEnum {
534 A, B 534 A, B
535 } 535 }
536 '''); 536 ''');
537 _computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2); 537 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT2);
538 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>()); 538 expect(task, new isInstanceOf<BuildEnumMemberElementsTask>());
539 CompilationUnit unit = outputs[RESOLVED_UNIT2]; 539 CompilationUnit unit = outputs[RESOLVED_UNIT2];
540 // validate Element 540 // validate Element
541 ClassElement enumElement = unit.element.getEnum('MyEnum'); 541 ClassElement enumElement = unit.element.getEnum('MyEnum');
542 List<FieldElement> fields = enumElement.fields; 542 List<FieldElement> fields = enumElement.fields;
543 expect(fields, hasLength(4)); 543 expect(fields, hasLength(4));
544 { 544 {
545 FieldElementImpl index = fields[0]; 545 FieldElementImpl index = fields[0];
546 expect(index, isNotNull); 546 expect(index, isNotNull);
547 expect(index.name, 'index'); 547 expect(index.name, 'index');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { 592 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest {
593 test_perform_entryPoint() { 593 test_perform_entryPoint() {
594 Source sourceA = newSource('/a.dart', ''' 594 Source sourceA = newSource('/a.dart', '''
595 library lib_a; 595 library lib_a;
596 export 'b.dart'; 596 export 'b.dart';
597 '''); 597 ''');
598 Source sourceB = newSource('/b.dart', ''' 598 Source sourceB = newSource('/b.dart', '''
599 library lib_b; 599 library lib_b;
600 main() {} 600 main() {}
601 '''); 601 ''');
602 _computeResult(sourceA, LIBRARY_ELEMENT4); 602 computeResult(sourceA, LIBRARY_ELEMENT4);
603 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 603 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
604 // validate 604 // validate
605 { 605 {
606 LibraryElement library = outputs[LIBRARY_ELEMENT4]; 606 LibraryElement library = outputs[LIBRARY_ELEMENT4];
607 FunctionElement entryPoint = library.entryPoint; 607 FunctionElement entryPoint = library.entryPoint;
608 expect(entryPoint, isNotNull); 608 expect(entryPoint, isNotNull);
609 expect(entryPoint.source, sourceB); 609 expect(entryPoint.source, sourceB);
610 } 610 }
611 } 611 }
612 612
(...skipping 11 matching lines...) Expand all
624 class B2 {} 624 class B2 {}
625 class B3 {} 625 class B3 {}
626 class _B4 {} 626 class _B4 {}
627 '''); 627 ''');
628 newSource('/c.dart', ''' 628 newSource('/c.dart', '''
629 library lib_c; 629 library lib_c;
630 class C1 {} 630 class C1 {}
631 class C2 {} 631 class C2 {}
632 class C3 {} 632 class C3 {}
633 '''); 633 ''');
634 _computeResult(sourceA, LIBRARY_ELEMENT4); 634 computeResult(sourceA, LIBRARY_ELEMENT4);
635 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 635 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
636 // validate 636 // validate
637 { 637 {
638 LibraryElement library = outputs[LIBRARY_ELEMENT4]; 638 LibraryElement library = outputs[LIBRARY_ELEMENT4];
639 Namespace namespace = library.exportNamespace; 639 Namespace namespace = library.exportNamespace;
640 Iterable<String> definedKeys = namespace.definedNames.keys; 640 Iterable<String> definedKeys = namespace.definedNames.keys;
641 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); 641 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3']));
642 } 642 }
643 } 643 }
644 644
645 test_perform_showCombinator() { 645 test_perform_showCombinator() {
646 Source sourceA = newSource('/a.dart', ''' 646 Source sourceA = newSource('/a.dart', '''
647 library lib_a; 647 library lib_a;
648 export 'b.dart' show B1; 648 export 'b.dart' show B1;
649 class A1 {} 649 class A1 {}
650 class A2 {} 650 class A2 {}
651 class _A3 {} 651 class _A3 {}
652 '''); 652 ''');
653 newSource('/b.dart', ''' 653 newSource('/b.dart', '''
654 library lib_b; 654 library lib_b;
655 class B1 {} 655 class B1 {}
656 class B2 {} 656 class B2 {}
657 class _B3 {} 657 class _B3 {}
658 '''); 658 ''');
659 _computeResult(sourceA, LIBRARY_ELEMENT4); 659 computeResult(sourceA, LIBRARY_ELEMENT4);
660 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 660 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
661 // validate 661 // validate
662 { 662 {
663 LibraryElement library = outputs[LIBRARY_ELEMENT4]; 663 LibraryElement library = outputs[LIBRARY_ELEMENT4];
664 Namespace namespace = library.exportNamespace; 664 Namespace namespace = library.exportNamespace;
665 Iterable<String> definedKeys = namespace.definedNames.keys; 665 Iterable<String> definedKeys = namespace.definedNames.keys;
666 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); 666 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1']));
667 } 667 }
668 } 668 }
669 669
670 test_perform_showCombinator_setter() { 670 test_perform_showCombinator_setter() {
671 Source sourceA = newSource('/a.dart', ''' 671 Source sourceA = newSource('/a.dart', '''
672 library lib_a; 672 library lib_a;
673 export 'b.dart' show topLevelB; 673 export 'b.dart' show topLevelB;
674 class A {} 674 class A {}
675 '''); 675 ''');
676 newSource('/b.dart', ''' 676 newSource('/b.dart', '''
677 library lib_b; 677 library lib_b;
678 int topLevelB; 678 int topLevelB;
679 '''); 679 ''');
680 _computeResult(sourceA, LIBRARY_ELEMENT4); 680 computeResult(sourceA, LIBRARY_ELEMENT4);
681 expect(task, new isInstanceOf<BuildExportNamespaceTask>()); 681 expect(task, new isInstanceOf<BuildExportNamespaceTask>());
682 // validate 682 // validate
683 { 683 {
684 LibraryElement library = outputs[LIBRARY_ELEMENT4]; 684 LibraryElement library = outputs[LIBRARY_ELEMENT4];
685 Namespace namespace = library.exportNamespace; 685 Namespace namespace = library.exportNamespace;
686 Iterable<String> definedKeys = namespace.definedNames.keys; 686 Iterable<String> definedKeys = namespace.definedNames.keys;
687 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); 687 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB=']));
688 } 688 }
689 } 689 }
690 } 690 }
691 691
692 @reflectiveTest 692 @reflectiveTest
693 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest { 693 class BuildFunctionTypeAliasesTaskTest extends _AbstractDartTaskTest {
694 test_perform() { 694 test_perform() {
695 Source source = newSource('/test.dart', ''' 695 Source source = newSource('/test.dart', '''
696 typedef int F(G g); 696 typedef int F(G g);
697 typedef String G(int p); 697 typedef String G(int p);
698 '''); 698 ''');
699 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 699 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
700 _computeResult(target, RESOLVED_UNIT3); 700 computeResult(target, RESOLVED_UNIT3);
701 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); 701 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>());
702 // validate 702 // validate
703 CompilationUnit unit = outputs[RESOLVED_UNIT3]; 703 CompilationUnit unit = outputs[RESOLVED_UNIT3];
704 FunctionTypeAlias nodeF = unit.declarations[0]; 704 FunctionTypeAlias nodeF = unit.declarations[0];
705 FunctionTypeAlias nodeG = unit.declarations[1]; 705 FunctionTypeAlias nodeG = unit.declarations[1];
706 { 706 {
707 FormalParameter parameter = nodeF.parameters.parameters[0]; 707 FormalParameter parameter = nodeF.parameters.parameters[0];
708 DartType parameterType = parameter.element.type; 708 DartType parameterType = parameter.element.type;
709 Element returnTypeElement = nodeF.returnType.type.element; 709 Element returnTypeElement = nodeF.returnType.type.element;
710 expect(returnTypeElement.displayName, 'int'); 710 expect(returnTypeElement.displayName, 'int');
711 expect(parameterType.element, nodeG.element); 711 expect(parameterType.element, nodeG.element);
712 } 712 }
713 { 713 {
714 FormalParameter parameter = nodeG.parameters.parameters[0]; 714 FormalParameter parameter = nodeG.parameters.parameters[0];
715 DartType parameterType = parameter.element.type; 715 DartType parameterType = parameter.element.type;
716 expect(nodeG.returnType.type.element.displayName, 'String'); 716 expect(nodeG.returnType.type.element.displayName, 'String');
717 expect(parameterType.element.displayName, 'int'); 717 expect(parameterType.element.displayName, 'int');
718 } 718 }
719 } 719 }
720 720
721 test_perform_errors() { 721 test_perform_errors() {
722 Source source = newSource('/test.dart', ''' 722 Source source = newSource('/test.dart', '''
723 typedef int F(NoSuchType p); 723 typedef int F(NoSuchType p);
724 '''); 724 ''');
725 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 725 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
726 _computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS); 726 computeResult(target, BUILD_FUNCTION_TYPE_ALIASES_ERRORS);
727 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>()); 727 expect(task, new isInstanceOf<BuildFunctionTypeAliasesTask>());
728 // validate 728 // validate
729 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS); 729 _fillErrorListener(BUILD_FUNCTION_TYPE_ALIASES_ERRORS);
730 errorListener 730 errorListener
731 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); 731 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]);
732 } 732 }
733 } 733 }
734 734
735 @reflectiveTest 735 @reflectiveTest
736 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest { 736 class BuildLibraryConstructorsTaskTest extends _AbstractDartTaskTest {
737 test_perform() { 737 test_perform() {
738 Source source = newSource('/test.dart', ''' 738 Source source = newSource('/test.dart', '''
739 class B { 739 class B {
740 B(int i); 740 B(int i);
741 } 741 }
742 class M1 {} 742 class M1 {}
743 class M2 {} 743 class M2 {}
744 744
745 class C2 = C1 with M2; 745 class C2 = C1 with M2;
746 class C1 = B with M1; 746 class C1 = B with M1;
747 class C3 = B with M2; 747 class C3 = B with M2;
748 '''); 748 ''');
749 _computeResult(source, LIBRARY_ELEMENT6); 749 computeResult(source, LIBRARY_ELEMENT6);
750 expect(task, new isInstanceOf<BuildLibraryConstructorsTask>()); 750 expect(task, new isInstanceOf<BuildLibraryConstructorsTask>());
751 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT6]; 751 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT6];
752 // C1 752 // C1
753 { 753 {
754 ClassElement classElement = libraryElement.getType('C2'); 754 ClassElement classElement = libraryElement.getType('C2');
755 List<ConstructorElement> constructors = classElement.constructors; 755 List<ConstructorElement> constructors = classElement.constructors;
756 expect(constructors, hasLength(1)); 756 expect(constructors, hasLength(1));
757 expect(constructors[0].parameters, hasLength(1)); 757 expect(constructors[0].parameters, hasLength(1));
758 } 758 }
759 // C3 759 // C3
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 } 1037 }
1038 1038
1039 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) { 1039 void _assertErrorsWithCodes(List<ErrorCode> expectedErrorCodes) {
1040 _fillErrorListener(BUILD_LIBRARY_ERRORS); 1040 _fillErrorListener(BUILD_LIBRARY_ERRORS);
1041 errorListener.assertErrorsWithCodes(expectedErrorCodes); 1041 errorListener.assertErrorsWithCodes(expectedErrorCodes);
1042 } 1042 }
1043 1043
1044 void _performBuildTask(Map<String, String> sourceMap) { 1044 void _performBuildTask(Map<String, String> sourceMap) {
1045 List<Source> sources = newSources(sourceMap); 1045 List<Source> sources = newSources(sourceMap);
1046 Source libSource = sources.first; 1046 Source libSource = sources.first;
1047 _computeResult(libSource, LIBRARY_ELEMENT1); 1047 computeResult(libSource, LIBRARY_ELEMENT1);
1048 expect(task, new isInstanceOf<BuildLibraryElementTask>()); 1048 expect(task, new isInstanceOf<BuildLibraryElementTask>());
1049 libraryUnit = context 1049 libraryUnit = context
1050 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource)) 1050 .getCacheEntry(new LibrarySpecificUnit(libSource, libSource))
1051 .getValue(RESOLVED_UNIT1); 1051 .getValue(RESOLVED_UNIT1);
1052 libraryUnitElement = libraryUnit.element; 1052 libraryUnitElement = libraryUnit.element;
1053 librarySource = libraryUnitElement.source; 1053 librarySource = libraryUnitElement.source;
1054 libraryElement = outputs[LIBRARY_ELEMENT1]; 1054 libraryElement = outputs[LIBRARY_ELEMENT1];
1055 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT]; 1055 partUnits = task.inputs[BuildLibraryElementTask.PARTS_UNIT_INPUT];
1056 } 1056 }
1057 } 1057 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 part 'part.dart'; 1100 part 'part.dart';
1101 a() {} 1101 a() {}
1102 _b() {} 1102 _b() {}
1103 ''', 1103 ''',
1104 '/part.dart': ''' 1104 '/part.dart': '''
1105 part of lib; 1105 part of lib;
1106 _c() {} 1106 _c() {}
1107 d() {} 1107 d() {}
1108 ''' 1108 '''
1109 }); 1109 });
1110 _computeResult(sources.first, LIBRARY_ELEMENT3); 1110 computeResult(sources.first, LIBRARY_ELEMENT3);
1111 expect(task, new isInstanceOf<BuildPublicNamespaceTask>()); 1111 expect(task, new isInstanceOf<BuildPublicNamespaceTask>());
1112 // validate 1112 // validate
1113 LibraryElement library = outputs[LIBRARY_ELEMENT3]; 1113 LibraryElement library = outputs[LIBRARY_ELEMENT3];
1114 Namespace namespace = library.publicNamespace; 1114 Namespace namespace = library.publicNamespace;
1115 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd'])); 1115 expect(namespace.definedNames.keys, unorderedEquals(['a', 'd']));
1116 } 1116 }
1117 } 1117 }
1118 1118
1119 @reflectiveTest 1119 @reflectiveTest
1120 class BuildSourceClosuresTaskTest extends _AbstractDartTaskTest { 1120 class BuildSourceClosuresTaskTest extends _AbstractDartTaskTest {
1121 test_perform_exportClosure() { 1121 test_perform_exportClosure() {
1122 Source sourceA = newSource('/a.dart', ''' 1122 Source sourceA = newSource('/a.dart', '''
1123 library lib_a; 1123 library lib_a;
1124 export 'b.dart'; 1124 export 'b.dart';
1125 '''); 1125 ''');
1126 Source sourceB = newSource('/b.dart', ''' 1126 Source sourceB = newSource('/b.dart', '''
1127 library lib_b; 1127 library lib_b;
1128 export 'c.dart'; 1128 export 'c.dart';
1129 '''); 1129 ''');
1130 Source sourceC = newSource('/c.dart', ''' 1130 Source sourceC = newSource('/c.dart', '''
1131 library lib_c; 1131 library lib_c;
1132 export 'a.dart'; 1132 export 'a.dart';
1133 '''); 1133 ''');
1134 Source sourceD = newSource('/d.dart', ''' 1134 Source sourceD = newSource('/d.dart', '''
1135 library lib_d; 1135 library lib_d;
1136 '''); 1136 ''');
1137 // a.dart 1137 // a.dart
1138 { 1138 {
1139 _computeResult(sourceA, EXPORT_SOURCE_CLOSURE); 1139 computeResult(sourceA, EXPORT_SOURCE_CLOSURE);
1140 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1140 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1141 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1141 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
1142 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); 1142 expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
1143 } 1143 }
1144 // c.dart 1144 // c.dart
1145 { 1145 {
1146 _computeResult(sourceC, EXPORT_SOURCE_CLOSURE); 1146 computeResult(sourceC, EXPORT_SOURCE_CLOSURE);
1147 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1147 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1148 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1148 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
1149 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); 1149 expect(closure, unorderedEquals([sourceA, sourceB, sourceC]));
1150 } 1150 }
1151 // d.dart 1151 // d.dart
1152 { 1152 {
1153 _computeResult(sourceD, EXPORT_SOURCE_CLOSURE); 1153 computeResult(sourceD, EXPORT_SOURCE_CLOSURE);
1154 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1154 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1155 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE]; 1155 List<Source> closure = outputs[EXPORT_SOURCE_CLOSURE];
1156 expect(closure, unorderedEquals([sourceD])); 1156 expect(closure, unorderedEquals([sourceD]));
1157 } 1157 }
1158 } 1158 }
1159 1159
1160 test_perform_importClosure() { 1160 test_perform_importClosure() {
1161 Source sourceA = newSource('/a.dart', ''' 1161 Source sourceA = newSource('/a.dart', '''
1162 library lib_a; 1162 library lib_a;
1163 import 'b.dart'; 1163 import 'b.dart';
1164 '''); 1164 ''');
1165 Source sourceB = newSource('/b.dart', ''' 1165 Source sourceB = newSource('/b.dart', '''
1166 library lib_b; 1166 library lib_b;
1167 import 'c.dart'; 1167 import 'c.dart';
1168 '''); 1168 ''');
1169 Source sourceC = newSource('/c.dart', ''' 1169 Source sourceC = newSource('/c.dart', '''
1170 library lib_c; 1170 library lib_c;
1171 import 'a.dart'; 1171 import 'a.dart';
1172 '''); 1172 ''');
1173 Source sourceD = newSource('/d.dart', ''' 1173 Source sourceD = newSource('/d.dart', '''
1174 library lib_d; 1174 library lib_d;
1175 '''); 1175 ''');
1176 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); 1176 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core');
1177 // a.dart 1177 // a.dart
1178 { 1178 {
1179 _computeResult(sourceA, IMPORT_SOURCE_CLOSURE); 1179 computeResult(sourceA, IMPORT_SOURCE_CLOSURE);
1180 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1180 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1181 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; 1181 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE];
1182 expect(closure, contains(sourceA)); 1182 expect(closure, contains(sourceA));
1183 expect(closure, contains(sourceB)); 1183 expect(closure, contains(sourceB));
1184 expect(closure, contains(sourceC)); 1184 expect(closure, contains(sourceC));
1185 expect(closure, contains(coreSource)); 1185 expect(closure, contains(coreSource));
1186 } 1186 }
1187 // c.dart 1187 // c.dart
1188 { 1188 {
1189 _computeResult(sourceC, IMPORT_SOURCE_CLOSURE); 1189 computeResult(sourceC, IMPORT_SOURCE_CLOSURE);
1190 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1190 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1191 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; 1191 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE];
1192 expect(closure, contains(sourceA)); 1192 expect(closure, contains(sourceA));
1193 expect(closure, contains(sourceB)); 1193 expect(closure, contains(sourceB));
1194 expect(closure, contains(sourceC)); 1194 expect(closure, contains(sourceC));
1195 expect(closure, contains(coreSource)); 1195 expect(closure, contains(coreSource));
1196 } 1196 }
1197 // d.dart 1197 // d.dart
1198 { 1198 {
1199 _computeResult(sourceD, IMPORT_SOURCE_CLOSURE); 1199 computeResult(sourceD, IMPORT_SOURCE_CLOSURE);
1200 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1200 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1201 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; 1201 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE];
1202 expect(closure, contains(sourceD)); 1202 expect(closure, contains(sourceD));
1203 expect(closure, contains(coreSource)); 1203 expect(closure, contains(coreSource));
1204 } 1204 }
1205 } 1205 }
1206 1206
1207 test_perform_importExportClosure() { 1207 test_perform_importExportClosure() {
1208 Source sourceA = newSource('/a.dart', ''' 1208 Source sourceA = newSource('/a.dart', '''
1209 library lib_a; 1209 library lib_a;
1210 '''); 1210 ''');
1211 Source sourceB = newSource('/b.dart', ''' 1211 Source sourceB = newSource('/b.dart', '''
1212 library lib_b; 1212 library lib_b;
1213 export 'a.dart'; 1213 export 'a.dart';
1214 '''); 1214 ''');
1215 Source sourceC = newSource('/c.dart', ''' 1215 Source sourceC = newSource('/c.dart', '''
1216 library lib_c; 1216 library lib_c;
1217 import 'b.dart'; 1217 import 'b.dart';
1218 '''); 1218 ''');
1219 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); 1219 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core');
1220 // c.dart 1220 // c.dart
1221 { 1221 {
1222 _computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE); 1222 computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE);
1223 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1223 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1224 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; 1224 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE];
1225 expect(closure, contains(sourceA)); 1225 expect(closure, contains(sourceA));
1226 expect(closure, contains(sourceB)); 1226 expect(closure, contains(sourceB));
1227 expect(closure, contains(sourceC)); 1227 expect(closure, contains(sourceC));
1228 expect(closure, contains(coreSource)); 1228 expect(closure, contains(coreSource));
1229 } 1229 }
1230 // b.dart 1230 // b.dart
1231 { 1231 {
1232 _computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE); 1232 computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE);
1233 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1233 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1234 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; 1234 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE];
1235 expect(closure, contains(sourceA)); 1235 expect(closure, contains(sourceA));
1236 expect(closure, contains(sourceB)); 1236 expect(closure, contains(sourceB));
1237 expect(closure, contains(coreSource)); 1237 expect(closure, contains(coreSource));
1238 } 1238 }
1239 } 1239 }
1240 1240
1241 test_perform_isClient_false() { 1241 test_perform_isClient_false() {
1242 Source sourceA = newSource('/a.dart', ''' 1242 Source sourceA = newSource('/a.dart', '''
1243 library lib_a; 1243 library lib_a;
1244 import 'b.dart'; 1244 import 'b.dart';
1245 '''); 1245 ''');
1246 newSource('/b.dart', ''' 1246 newSource('/b.dart', '''
1247 library lib_b; 1247 library lib_b;
1248 '''); 1248 ''');
1249 _computeResult(sourceA, IS_CLIENT); 1249 computeResult(sourceA, IS_CLIENT);
1250 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1250 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1251 expect(outputs[IS_CLIENT], isFalse); 1251 expect(outputs[IS_CLIENT], isFalse);
1252 } 1252 }
1253 1253
1254 test_perform_isClient_true_export_indirect() { 1254 test_perform_isClient_true_export_indirect() {
1255 newSource('/exports_html.dart', ''' 1255 newSource('/exports_html.dart', '''
1256 library lib_exports_html; 1256 library lib_exports_html;
1257 export 'dart:html'; 1257 export 'dart:html';
1258 '''); 1258 ''');
1259 Source source = newSource('/test.dart', ''' 1259 Source source = newSource('/test.dart', '''
1260 import 'exports_html.dart'; 1260 import 'exports_html.dart';
1261 '''); 1261 ''');
1262 _computeResult(source, IS_CLIENT); 1262 computeResult(source, IS_CLIENT);
1263 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1263 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1264 expect(outputs[IS_CLIENT], isTrue); 1264 expect(outputs[IS_CLIENT], isTrue);
1265 } 1265 }
1266 1266
1267 test_perform_isClient_true_import_direct() { 1267 test_perform_isClient_true_import_direct() {
1268 Source sourceA = newSource('/a.dart', ''' 1268 Source sourceA = newSource('/a.dart', '''
1269 library lib_a; 1269 library lib_a;
1270 import 'dart:html'; 1270 import 'dart:html';
1271 '''); 1271 ''');
1272 _computeResult(sourceA, IS_CLIENT); 1272 computeResult(sourceA, IS_CLIENT);
1273 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1273 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1274 expect(outputs[IS_CLIENT], isTrue); 1274 expect(outputs[IS_CLIENT], isTrue);
1275 } 1275 }
1276 1276
1277 test_perform_isClient_true_import_indirect() { 1277 test_perform_isClient_true_import_indirect() {
1278 Source sourceA = newSource('/a.dart', ''' 1278 Source sourceA = newSource('/a.dart', '''
1279 library lib_a; 1279 library lib_a;
1280 import 'b.dart'; 1280 import 'b.dart';
1281 '''); 1281 ''');
1282 newSource('/b.dart', ''' 1282 newSource('/b.dart', '''
1283 library lib_b; 1283 library lib_b;
1284 import 'dart:html'; 1284 import 'dart:html';
1285 '''); 1285 ''');
1286 _computeResult(sourceA, IS_CLIENT); 1286 computeResult(sourceA, IS_CLIENT);
1287 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); 1287 expect(task, new isInstanceOf<BuildSourceClosuresTask>());
1288 expect(outputs[IS_CLIENT], isTrue); 1288 expect(outputs[IS_CLIENT], isTrue);
1289 } 1289 }
1290 } 1290 }
1291 1291
1292 @reflectiveTest 1292 @reflectiveTest
1293 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest { 1293 class BuildTypeProviderTaskTest extends _AbstractDartTaskTest {
1294 test_perform() { 1294 test_perform() {
1295 _computeResult(AnalysisContextTarget.request, TYPE_PROVIDER); 1295 computeResult(AnalysisContextTarget.request, TYPE_PROVIDER);
1296 expect(task, new isInstanceOf<BuildTypeProviderTask>()); 1296 expect(task, new isInstanceOf<BuildTypeProviderTask>());
1297 // validate 1297 // validate
1298 TypeProvider typeProvider = outputs[TYPE_PROVIDER]; 1298 TypeProvider typeProvider = outputs[TYPE_PROVIDER];
1299 expect(typeProvider, isNotNull); 1299 expect(typeProvider, isNotNull);
1300 expect(typeProvider.boolType, isNotNull); 1300 expect(typeProvider.boolType, isNotNull);
1301 expect(typeProvider.intType, isNotNull); 1301 expect(typeProvider.intType, isNotNull);
1302 expect(typeProvider.futureType, isNotNull); 1302 expect(typeProvider.futureType, isNotNull);
1303 } 1303 }
1304 } 1304 }
1305 1305
(...skipping 12 matching lines...) Expand all
1318 1318
1319 test_annotation_with_args() { 1319 test_annotation_with_args() {
1320 Source source = newSource('/test.dart', ''' 1320 Source source = newSource('/test.dart', '''
1321 const x = 1; 1321 const x = 1;
1322 @D(x) class C {} 1322 @D(x) class C {}
1323 class D { const D(value); } 1323 class D { const D(value); }
1324 '''); 1324 ''');
1325 // First compute the resolved unit for the source. 1325 // First compute the resolved unit for the source.
1326 LibrarySpecificUnit librarySpecificUnit = 1326 LibrarySpecificUnit librarySpecificUnit =
1327 new LibrarySpecificUnit(source, source); 1327 new LibrarySpecificUnit(source, source);
1328 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); 1328 computeResult(librarySpecificUnit, RESOLVED_UNIT1);
1329 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 1329 CompilationUnit unit = outputs[RESOLVED_UNIT1];
1330 // Find the elements for x and D's constructor, and the annotation on C. 1330 // Find the elements for x and D's constructor, and the annotation on C.
1331 List<PropertyAccessorElement> accessors = unit.element.accessors; 1331 List<PropertyAccessorElement> accessors = unit.element.accessors;
1332 Element x = accessors.firstWhere((PropertyAccessorElement accessor) => 1332 Element x = accessors.firstWhere((PropertyAccessorElement accessor) =>
1333 accessor.isGetter && accessor.name == 'x').variable; 1333 accessor.isGetter && accessor.name == 'x').variable;
1334 List<ClassElement> types = unit.element.types; 1334 List<ClassElement> types = unit.element.types;
1335 Element constructorForD = 1335 Element constructorForD =
1336 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; 1336 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0];
1337 Annotation annotation = findClassAnnotation(unit, 'C'); 1337 Annotation annotation = findClassAnnotation(unit, 'C');
1338 // Now compute the dependencies for the annotation, and check that it is 1338 // Now compute the dependencies for the annotation, and check that it is
1339 // the set [x, constructorForD]. 1339 // the set [x, constructorForD].
1340 // TODO(paulberry): test librarySource != source 1340 // TODO(paulberry): test librarySource != source
1341 _computeResult(new ConstantEvaluationTarget_Annotation( 1341 computeResult(new ConstantEvaluationTarget_Annotation(
1342 context, source, source, annotation), CONSTANT_DEPENDENCIES); 1342 context, source, source, annotation), CONSTANT_DEPENDENCIES);
1343 expect( 1343 expect(
1344 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); 1344 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet());
1345 } 1345 }
1346 1346
1347 test_annotation_without_args() { 1347 test_annotation_without_args() {
1348 Source source = newSource('/test.dart', ''' 1348 Source source = newSource('/test.dart', '''
1349 const x = 1; 1349 const x = 1;
1350 @x class C {} 1350 @x class C {}
1351 '''); 1351 ''');
1352 // First compute the resolved unit for the source. 1352 // First compute the resolved unit for the source.
1353 LibrarySpecificUnit librarySpecificUnit = 1353 LibrarySpecificUnit librarySpecificUnit =
1354 new LibrarySpecificUnit(source, source); 1354 new LibrarySpecificUnit(source, source);
1355 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); 1355 computeResult(librarySpecificUnit, RESOLVED_UNIT1);
1356 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 1356 CompilationUnit unit = outputs[RESOLVED_UNIT1];
1357 // Find the element for x and the annotation on C. 1357 // Find the element for x and the annotation on C.
1358 List<PropertyAccessorElement> accessors = unit.element.accessors; 1358 List<PropertyAccessorElement> accessors = unit.element.accessors;
1359 Element x = accessors.firstWhere((PropertyAccessorElement accessor) => 1359 Element x = accessors.firstWhere((PropertyAccessorElement accessor) =>
1360 accessor.isGetter && accessor.name == 'x').variable; 1360 accessor.isGetter && accessor.name == 'x').variable;
1361 Annotation annotation = findClassAnnotation(unit, 'C'); 1361 Annotation annotation = findClassAnnotation(unit, 'C');
1362 // Now compute the dependencies for the annotation, and check that it is 1362 // Now compute the dependencies for the annotation, and check that it is
1363 // the list [x]. 1363 // the list [x].
1364 _computeResult(new ConstantEvaluationTarget_Annotation( 1364 computeResult(new ConstantEvaluationTarget_Annotation(
1365 context, source, source, annotation), CONSTANT_DEPENDENCIES); 1365 context, source, source, annotation), CONSTANT_DEPENDENCIES);
1366 expect(outputs[CONSTANT_DEPENDENCIES], [x]); 1366 expect(outputs[CONSTANT_DEPENDENCIES], [x]);
1367 } 1367 }
1368 1368
1369 test_enumConstant() { 1369 test_enumConstant() {
1370 Source source = newSource('/test.dart', ''' 1370 Source source = newSource('/test.dart', '''
1371 enum E {A, B, C} 1371 enum E {A, B, C}
1372 '''); 1372 ''');
1373 // First compute the resolved unit for the source. 1373 // First compute the resolved unit for the source.
1374 LibrarySpecificUnit librarySpecificUnit = 1374 LibrarySpecificUnit librarySpecificUnit =
1375 new LibrarySpecificUnit(source, source); 1375 new LibrarySpecificUnit(source, source);
1376 _computeResult(librarySpecificUnit, RESOLVED_UNIT2); 1376 computeResult(librarySpecificUnit, RESOLVED_UNIT2);
1377 CompilationUnit unit = outputs[RESOLVED_UNIT2]; 1377 CompilationUnit unit = outputs[RESOLVED_UNIT2];
1378 // Find the element for 'A' 1378 // Find the element for 'A'
1379 EnumDeclaration enumDeclaration = unit.declarations[0]; 1379 EnumDeclaration enumDeclaration = unit.declarations[0];
1380 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; 1380 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0];
1381 FieldElement constantElement = constantDeclaration.element; 1381 FieldElement constantElement = constantDeclaration.element;
1382 // Now compute the dependencies for the constant and check that there are 1382 // Now compute the dependencies for the constant and check that there are
1383 // none. 1383 // none.
1384 _computeResult(constantElement, CONSTANT_DEPENDENCIES); 1384 computeResult(constantElement, CONSTANT_DEPENDENCIES);
1385 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); 1385 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty);
1386 } 1386 }
1387 1387
1388 test_perform() { 1388 test_perform() {
1389 Source source = newSource('/test.dart', ''' 1389 Source source = newSource('/test.dart', '''
1390 const x = y; 1390 const x = y;
1391 const y = 1; 1391 const y = 1;
1392 '''); 1392 ''');
1393 // First compute the resolved unit for the source. 1393 // First compute the resolved unit for the source.
1394 LibrarySpecificUnit librarySpecificUnit = 1394 LibrarySpecificUnit librarySpecificUnit =
1395 new LibrarySpecificUnit(source, source); 1395 new LibrarySpecificUnit(source, source);
1396 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); 1396 computeResult(librarySpecificUnit, RESOLVED_UNIT1);
1397 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 1397 CompilationUnit unit = outputs[RESOLVED_UNIT1];
1398 // Find the elements for the constants x and y. 1398 // Find the elements for the constants x and y.
1399 List<PropertyAccessorElement> accessors = unit.element.accessors; 1399 List<PropertyAccessorElement> accessors = unit.element.accessors;
1400 Element x = accessors.firstWhere((PropertyAccessorElement accessor) => 1400 Element x = accessors.firstWhere((PropertyAccessorElement accessor) =>
1401 accessor.isGetter && accessor.name == 'x').variable; 1401 accessor.isGetter && accessor.name == 'x').variable;
1402 Element y = accessors.firstWhere((PropertyAccessorElement accessor) => 1402 Element y = accessors.firstWhere((PropertyAccessorElement accessor) =>
1403 accessor.isGetter && accessor.name == 'y').variable; 1403 accessor.isGetter && accessor.name == 'y').variable;
1404 // Now compute the dependencies for x, and check that it is the list [y]. 1404 // Now compute the dependencies for x, and check that it is the list [y].
1405 _computeResult(x, CONSTANT_DEPENDENCIES); 1405 computeResult(x, CONSTANT_DEPENDENCIES);
1406 expect(outputs[CONSTANT_DEPENDENCIES], [y]); 1406 expect(outputs[CONSTANT_DEPENDENCIES], [y]);
1407 } 1407 }
1408 } 1408 }
1409 1409
1410 @reflectiveTest 1410 @reflectiveTest
1411 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { 1411 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest {
1412 EvaluationResultImpl computeClassAnnotation( 1412 EvaluationResultImpl computeClassAnnotation(
1413 Source source, CompilationUnit unit, String className) { 1413 Source source, CompilationUnit unit, String className) {
1414 for (CompilationUnitMember member in unit.declarations) { 1414 for (CompilationUnitMember member in unit.declarations) {
1415 if (member is ClassDeclaration && member.name.name == className) { 1415 if (member is ClassDeclaration && member.name.name == className) {
1416 expect(member.metadata, hasLength(1)); 1416 expect(member.metadata, hasLength(1));
1417 Annotation annotation = member.metadata[0]; 1417 Annotation annotation = member.metadata[0];
1418 ConstantEvaluationTarget_Annotation target = 1418 ConstantEvaluationTarget_Annotation target =
1419 new ConstantEvaluationTarget_Annotation( 1419 new ConstantEvaluationTarget_Annotation(
1420 context, source, source, annotation); 1420 context, source, source, annotation);
1421 _computeResult(target, CONSTANT_VALUE); 1421 computeResult(target, CONSTANT_VALUE);
1422 expect(outputs[CONSTANT_VALUE], same(target)); 1422 expect(outputs[CONSTANT_VALUE], same(target));
1423 EvaluationResultImpl evaluationResult = 1423 EvaluationResultImpl evaluationResult =
1424 (annotation.elementAnnotation as ElementAnnotationImpl).evaluationRe sult; 1424 (annotation.elementAnnotation as ElementAnnotationImpl).evaluationRe sult;
1425 return evaluationResult; 1425 return evaluationResult;
1426 } 1426 }
1427 } 1427 }
1428 fail('Annotation not found'); 1428 fail('Annotation not found');
1429 return null; 1429 return null;
1430 } 1430 }
1431 1431
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 EvaluationResultImpl _computeTopLevelVariableConstValue( 1581 EvaluationResultImpl _computeTopLevelVariableConstValue(
1582 String variableName, String content) { 1582 String variableName, String content) {
1583 return _evaluateConstant(_resolveUnit(content), variableName); 1583 return _evaluateConstant(_resolveUnit(content), variableName);
1584 } 1584 }
1585 1585
1586 EvaluationResultImpl _evaluateConstant( 1586 EvaluationResultImpl _evaluateConstant(
1587 CompilationUnit unit, String variableName) { 1587 CompilationUnit unit, String variableName) {
1588 // Find the element for the given constant. 1588 // Find the element for the given constant.
1589 PropertyInducingElement variableElement = _findVariable(unit, variableName); 1589 PropertyInducingElement variableElement = _findVariable(unit, variableName);
1590 // Now compute the value of the constant. 1590 // Now compute the value of the constant.
1591 _computeResult(variableElement, CONSTANT_VALUE); 1591 computeResult(variableElement, CONSTANT_VALUE);
1592 expect(outputs[CONSTANT_VALUE], same(variableElement)); 1592 expect(outputs[CONSTANT_VALUE], same(variableElement));
1593 EvaluationResultImpl evaluationResult = 1593 EvaluationResultImpl evaluationResult =
1594 (variableElement as TopLevelVariableElementImpl).evaluationResult; 1594 (variableElement as TopLevelVariableElementImpl).evaluationResult;
1595 return evaluationResult; 1595 return evaluationResult;
1596 } 1596 }
1597 1597
1598 void _expectCircularityError(EvaluationResultImpl evaluationResult) { 1598 void _expectCircularityError(EvaluationResultImpl evaluationResult) {
1599 expect(evaluationResult, isNotNull); 1599 expect(evaluationResult, isNotNull);
1600 expect(evaluationResult.value, isNull); 1600 expect(evaluationResult.value, isNull);
1601 expect(evaluationResult.errors, hasLength(1)); 1601 expect(evaluationResult.errors, hasLength(1));
1602 expect(evaluationResult.errors[0].errorCode, 1602 expect(evaluationResult.errors[0].errorCode,
1603 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT); 1603 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
1604 } 1604 }
1605 1605
1606 PropertyInducingElement _findVariable( 1606 PropertyInducingElement _findVariable(
1607 CompilationUnit unit, String variableName) { 1607 CompilationUnit unit, String variableName) {
1608 // Find the element for the given constant. 1608 // Find the element for the given constant.
1609 return unit.element.topLevelVariables.firstWhere( 1609 return unit.element.topLevelVariables.firstWhere(
1610 (TopLevelVariableElement variable) => variable.name == variableName); 1610 (TopLevelVariableElement variable) => variable.name == variableName);
1611 } 1611 }
1612 1612
1613 CompilationUnit _resolveSource(Source source) { 1613 CompilationUnit _resolveSource(Source source) {
1614 LibrarySpecificUnit librarySpecificUnit = 1614 LibrarySpecificUnit librarySpecificUnit =
1615 new LibrarySpecificUnit(source, source); 1615 new LibrarySpecificUnit(source, source);
1616 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); 1616 computeResult(librarySpecificUnit, RESOLVED_UNIT1);
1617 CompilationUnit unit = outputs[RESOLVED_UNIT1]; 1617 CompilationUnit unit = outputs[RESOLVED_UNIT1];
1618 return unit; 1618 return unit;
1619 } 1619 }
1620 1620
1621 CompilationUnit _resolveUnit(String content) => 1621 CompilationUnit _resolveUnit(String content) =>
1622 _resolveSource(newSource('/test.dart', content)); 1622 _resolveSource(newSource('/test.dart', content));
1623 } 1623 }
1624 1624
1625 @reflectiveTest 1625 @reflectiveTest
1626 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest { 1626 class ContainingLibrariesTaskTest extends _AbstractDartTaskTest {
(...skipping 26 matching lines...) Expand all
1653 expect(task.description, isNotNull); 1653 expect(task.description, isNotNull);
1654 } 1654 }
1655 1655
1656 test_descriptor() { 1656 test_descriptor() {
1657 TaskDescriptor descriptor = ContainingLibrariesTask.DESCRIPTOR; 1657 TaskDescriptor descriptor = ContainingLibrariesTask.DESCRIPTOR;
1658 expect(descriptor, isNotNull); 1658 expect(descriptor, isNotNull);
1659 } 1659 }
1660 1660
1661 test_perform_definingCompilationUnit() { 1661 test_perform_definingCompilationUnit() {
1662 AnalysisTarget library = newSource('/test.dart', 'library test;'); 1662 AnalysisTarget library = newSource('/test.dart', 'library test;');
1663 _computeResult(library, INCLUDED_PARTS); 1663 computeResult(library, INCLUDED_PARTS);
1664 _computeResult(library, CONTAINING_LIBRARIES); 1664 computeResult(library, CONTAINING_LIBRARIES);
1665 expect(task, new isInstanceOf<ContainingLibrariesTask>()); 1665 expect(task, new isInstanceOf<ContainingLibrariesTask>());
1666 expect(outputs, hasLength(1)); 1666 expect(outputs, hasLength(1));
1667 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 1667 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
1668 expect(containingLibraries, unorderedEquals([library])); 1668 expect(containingLibraries, unorderedEquals([library]));
1669 } 1669 }
1670 1670
1671 test_perform_partInMultipleLibraries() { 1671 test_perform_partInMultipleLibraries() {
1672 AnalysisTarget library1 = 1672 AnalysisTarget library1 =
1673 newSource('/lib1.dart', 'library test; part "part.dart";'); 1673 newSource('/lib1.dart', 'library test; part "part.dart";');
1674 AnalysisTarget library2 = 1674 AnalysisTarget library2 =
1675 newSource('/lib2.dart', 'library test; part "part.dart";'); 1675 newSource('/lib2.dart', 'library test; part "part.dart";');
1676 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 1676 AnalysisTarget part = newSource('/part.dart', 'part of test;');
1677 _computeResult(library1, INCLUDED_PARTS); 1677 computeResult(library1, INCLUDED_PARTS);
1678 _computeResult(library2, INCLUDED_PARTS); 1678 computeResult(library2, INCLUDED_PARTS);
1679 _computeResult(part, SOURCE_KIND); 1679 computeResult(part, SOURCE_KIND);
1680 _computeResult(part, CONTAINING_LIBRARIES); 1680 computeResult(part, CONTAINING_LIBRARIES);
1681 expect(task, new isInstanceOf<ContainingLibrariesTask>()); 1681 expect(task, new isInstanceOf<ContainingLibrariesTask>());
1682 expect(outputs, hasLength(1)); 1682 expect(outputs, hasLength(1));
1683 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 1683 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
1684 expect(containingLibraries, unorderedEquals([library1, library2])); 1684 expect(containingLibraries, unorderedEquals([library1, library2]));
1685 } 1685 }
1686 1686
1687 test_perform_partInSingleLibrary() { 1687 test_perform_partInSingleLibrary() {
1688 AnalysisTarget library = 1688 AnalysisTarget library =
1689 newSource('/lib.dart', 'library test; part "part.dart";'); 1689 newSource('/lib.dart', 'library test; part "part.dart";');
1690 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 1690 AnalysisTarget part = newSource('/part.dart', 'part of test;');
1691 _computeResult(library, INCLUDED_PARTS); 1691 computeResult(library, INCLUDED_PARTS);
1692 _computeResult(part, SOURCE_KIND); 1692 computeResult(part, SOURCE_KIND);
1693 _computeResult(part, CONTAINING_LIBRARIES); 1693 computeResult(part, CONTAINING_LIBRARIES);
1694 expect(task, new isInstanceOf<ContainingLibrariesTask>()); 1694 expect(task, new isInstanceOf<ContainingLibrariesTask>());
1695 expect(outputs, hasLength(1)); 1695 expect(outputs, hasLength(1));
1696 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES]; 1696 List<Source> containingLibraries = outputs[CONTAINING_LIBRARIES];
1697 expect(containingLibraries, unorderedEquals([library])); 1697 expect(containingLibraries, unorderedEquals([library]));
1698 } 1698 }
1699 } 1699 }
1700 1700
1701 @reflectiveTest 1701 @reflectiveTest
1702 class DartErrorsTaskTest extends _AbstractDartTaskTest { 1702 class DartErrorsTaskTest extends _AbstractDartTaskTest {
1703 test_buildInputs() { 1703 test_buildInputs() {
(...skipping 28 matching lines...) Expand all
1732 } 1732 }
1733 1733
1734 test_descriptor() { 1734 test_descriptor() {
1735 TaskDescriptor descriptor = DartErrorsTask.DESCRIPTOR; 1735 TaskDescriptor descriptor = DartErrorsTask.DESCRIPTOR;
1736 expect(descriptor, isNotNull); 1736 expect(descriptor, isNotNull);
1737 } 1737 }
1738 1738
1739 test_perform_definingCompilationUnit() { 1739 test_perform_definingCompilationUnit() {
1740 AnalysisTarget library = 1740 AnalysisTarget library =
1741 newSource('/test.dart', 'library test; import "dart:math";'); 1741 newSource('/test.dart', 'library test; import "dart:math";');
1742 _computeResult(library, INCLUDED_PARTS); 1742 computeResult(library, INCLUDED_PARTS);
1743 _computeResult(library, DART_ERRORS); 1743 computeResult(library, DART_ERRORS);
1744 expect(task, new isInstanceOf<DartErrorsTask>()); 1744 expect(task, new isInstanceOf<DartErrorsTask>());
1745 expect(outputs, hasLength(1)); 1745 expect(outputs, hasLength(1));
1746 List<AnalysisError> errors = outputs[DART_ERRORS]; 1746 List<AnalysisError> errors = outputs[DART_ERRORS];
1747 expect(errors, hasLength(1)); 1747 expect(errors, hasLength(1));
1748 } 1748 }
1749 1749
1750 test_perform_partInSingleLibrary() { 1750 test_perform_partInSingleLibrary() {
1751 AnalysisTarget library = newSource( 1751 AnalysisTarget library = newSource(
1752 '/lib.dart', 'library test; import "dart:math"; part "part.dart";'); 1752 '/lib.dart', 'library test; import "dart:math"; part "part.dart";');
1753 AnalysisTarget part = 1753 AnalysisTarget part =
1754 newSource('/part.dart', 'part of test; class A extends A {}'); 1754 newSource('/part.dart', 'part of test; class A extends A {}');
1755 _computeResult(library, INCLUDED_PARTS); 1755 computeResult(library, INCLUDED_PARTS);
1756 _computeResult(library, DART_ERRORS); 1756 computeResult(library, DART_ERRORS);
1757 _computeResult(part, DART_ERRORS); 1757 computeResult(part, DART_ERRORS);
1758 expect(task, new isInstanceOf<DartErrorsTask>()); 1758 expect(task, new isInstanceOf<DartErrorsTask>());
1759 expect(outputs, hasLength(1)); 1759 expect(outputs, hasLength(1));
1760 List<AnalysisError> errors = outputs[DART_ERRORS]; 1760 List<AnalysisError> errors = outputs[DART_ERRORS];
1761 // This should contain only the errors in the part file, not the ones in the 1761 // This should contain only the errors in the part file, not the ones in the
1762 // library. 1762 // library.
1763 expect(errors, hasLength(1)); 1763 expect(errors, hasLength(1));
1764 } 1764 }
1765 } 1765 }
1766 1766
1767 @reflectiveTest 1767 @reflectiveTest
1768 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { 1768 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest {
1769 test_perform() { 1769 test_perform() {
1770 Source source = newSource('/test.dart', ''' 1770 Source source = newSource('/test.dart', '''
1771 class C { 1771 class C {
1772 const C(); 1772 const C();
1773 } 1773 }
1774 1774
1775 @x 1775 @x
1776 f() {} 1776 f() {}
1777 1777
1778 const x = const C(); 1778 const x = const C();
1779 '''); 1779 ''');
1780 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1780 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1781 _computeResult(target, RESOLVED_UNIT); 1781 computeResult(target, RESOLVED_UNIT);
1782 expect(task, new isInstanceOf<EvaluateUnitConstantsTask>()); 1782 expect(task, new isInstanceOf<EvaluateUnitConstantsTask>());
1783 CompilationUnit unit = outputs[RESOLVED_UNIT]; 1783 CompilationUnit unit = outputs[RESOLVED_UNIT];
1784 CompilationUnitElement unitElement = unit.element; 1784 CompilationUnitElement unitElement = unit.element;
1785 expect((unitElement.types[0].constructors[ 1785 expect((unitElement.types[0].constructors[
1786 0] as ConstructorElementImpl).isCycleFree, isTrue); 1786 0] as ConstructorElementImpl).isCycleFree, isTrue);
1787 expect((unitElement.functions[0].metadata[ 1787 expect((unitElement.functions[0].metadata[
1788 0] as ElementAnnotationImpl).evaluationResult, isNotNull); 1788 0] as ElementAnnotationImpl).evaluationResult, isNotNull);
1789 expect((unitElement.topLevelVariables[ 1789 expect((unitElement.topLevelVariables[
1790 0] as TopLevelVariableElementImpl).evaluationResult, isNotNull); 1790 0] as TopLevelVariableElementImpl).evaluationResult, isNotNull);
1791 } 1791 }
(...skipping 19 matching lines...) Expand all
1811 main() { 1811 main() {
1812 new A(); 1812 new A();
1813 }'''); 1813 }''');
1814 _computeUsedElements(source); 1814 _computeUsedElements(source);
1815 // validate 1815 // validate
1816 expect(usedElementNames, unorderedEquals(['A'])); 1816 expect(usedElementNames, unorderedEquals(['A']));
1817 } 1817 }
1818 1818
1819 void _computeUsedElements(Source source) { 1819 void _computeUsedElements(Source source) {
1820 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1820 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1821 _computeResult(target, USED_IMPORTED_ELEMENTS); 1821 computeResult(target, USED_IMPORTED_ELEMENTS);
1822 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>()); 1822 expect(task, new isInstanceOf<GatherUsedImportedElementsTask>());
1823 usedElements = outputs[USED_IMPORTED_ELEMENTS]; 1823 usedElements = outputs[USED_IMPORTED_ELEMENTS];
1824 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); 1824 usedElementNames = usedElements.elements.map((e) => e.name).toSet();
1825 } 1825 }
1826 } 1826 }
1827 1827
1828 @reflectiveTest 1828 @reflectiveTest
1829 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { 1829 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest {
1830 UsedLocalElements usedElements; 1830 UsedLocalElements usedElements;
1831 Set<String> usedElementNames; 1831 Set<String> usedElementNames;
(...skipping 23 matching lines...) Expand all
1855 } 1855 }
1856 '''); 1856 ''');
1857 _computeUsedElements(source); 1857 _computeUsedElements(source);
1858 // validate 1858 // validate
1859 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); 1859 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2']));
1860 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); 1860 expect(usedElements.members, unorderedEquals(['_m2', '_m3']));
1861 } 1861 }
1862 1862
1863 void _computeUsedElements(Source source) { 1863 void _computeUsedElements(Source source) {
1864 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1864 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1865 _computeResult(target, USED_LOCAL_ELEMENTS); 1865 computeResult(target, USED_LOCAL_ELEMENTS);
1866 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>()); 1866 expect(task, new isInstanceOf<GatherUsedLocalElementsTask>());
1867 usedElements = outputs[USED_LOCAL_ELEMENTS]; 1867 usedElements = outputs[USED_LOCAL_ELEMENTS];
1868 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); 1868 usedElementNames = usedElements.elements.map((e) => e.name).toSet();
1869 } 1869 }
1870 } 1870 }
1871 1871
1872 @reflectiveTest 1872 @reflectiveTest
1873 class GenerateHintsTaskTest extends _AbstractDartTaskTest { 1873 class GenerateHintsTaskTest extends _AbstractDartTaskTest {
1874 test_perform_bestPractices_missingReturn() { 1874 test_perform_bestPractices_missingReturn() {
1875 Source source = newSource('/test.dart', ''' 1875 Source source = newSource('/test.dart', '''
1876 int main() { 1876 int main() {
1877 } 1877 }
1878 '''); 1878 ''');
1879 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1879 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1880 _computeResult(target, HINTS); 1880 computeResult(target, HINTS);
1881 expect(task, new isInstanceOf<GenerateHintsTask>()); 1881 expect(task, new isInstanceOf<GenerateHintsTask>());
1882 // validate 1882 // validate
1883 _fillErrorListener(HINTS); 1883 _fillErrorListener(HINTS);
1884 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); 1884 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]);
1885 } 1885 }
1886 1886
1887 test_perform_dart2js() { 1887 test_perform_dart2js() {
1888 Source source = newSource('/test.dart', ''' 1888 Source source = newSource('/test.dart', '''
1889 main(p) { 1889 main(p) {
1890 if (p is double) { 1890 if (p is double) {
1891 print('double'); 1891 print('double');
1892 } 1892 }
1893 } 1893 }
1894 '''); 1894 ''');
1895 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1895 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1896 _computeResult(target, HINTS); 1896 computeResult(target, HINTS);
1897 expect(task, new isInstanceOf<GenerateHintsTask>()); 1897 expect(task, new isInstanceOf<GenerateHintsTask>());
1898 // validate 1898 // validate
1899 _fillErrorListener(HINTS); 1899 _fillErrorListener(HINTS);
1900 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); 1900 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]);
1901 } 1901 }
1902 1902
1903 test_perform_deadCode() { 1903 test_perform_deadCode() {
1904 Source source = newSource('/test.dart', ''' 1904 Source source = newSource('/test.dart', '''
1905 main() { 1905 main() {
1906 if (false) { 1906 if (false) {
1907 print('how?'); 1907 print('how?');
1908 } 1908 }
1909 } 1909 }
1910 '''); 1910 ''');
1911 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1911 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1912 _computeResult(target, HINTS); 1912 computeResult(target, HINTS);
1913 expect(task, new isInstanceOf<GenerateHintsTask>()); 1913 expect(task, new isInstanceOf<GenerateHintsTask>());
1914 // validate 1914 // validate
1915 _fillErrorListener(HINTS); 1915 _fillErrorListener(HINTS);
1916 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); 1916 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]);
1917 } 1917 }
1918 1918
1919 test_perform_disabled() { 1919 test_perform_disabled() {
1920 context.analysisOptions = 1920 context.analysisOptions =
1921 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false; 1921 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false;
1922 Source source = newSource('/test.dart', ''' 1922 Source source = newSource('/test.dart', '''
1923 int main() { 1923 int main() {
1924 } 1924 }
1925 '''); 1925 ''');
1926 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1926 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1927 _computeResult(target, HINTS); 1927 computeResult(target, HINTS);
1928 expect(task, new isInstanceOf<GenerateHintsTask>()); 1928 expect(task, new isInstanceOf<GenerateHintsTask>());
1929 // validate 1929 // validate
1930 _fillErrorListener(HINTS); 1930 _fillErrorListener(HINTS);
1931 errorListener.assertNoErrors(); 1931 errorListener.assertNoErrors();
1932 } 1932 }
1933 1933
1934 test_perform_imports_duplicateImport() { 1934 test_perform_imports_duplicateImport() {
1935 newSource('/a.dart', r''' 1935 newSource('/a.dart', r'''
1936 library lib_a; 1936 library lib_a;
1937 class A {} 1937 class A {}
1938 '''); 1938 ''');
1939 Source source = newSource('/test.dart', r''' 1939 Source source = newSource('/test.dart', r'''
1940 import 'a.dart'; 1940 import 'a.dart';
1941 import 'a.dart'; 1941 import 'a.dart';
1942 main() { 1942 main() {
1943 new A(); 1943 new A();
1944 } 1944 }
1945 '''); 1945 ''');
1946 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1946 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1947 _computeResult(target, HINTS); 1947 computeResult(target, HINTS);
1948 expect(task, new isInstanceOf<GenerateHintsTask>()); 1948 expect(task, new isInstanceOf<GenerateHintsTask>());
1949 // validate 1949 // validate
1950 _fillErrorListener(HINTS); 1950 _fillErrorListener(HINTS);
1951 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); 1951 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]);
1952 } 1952 }
1953 1953
1954 test_perform_imports_unusedImport_one() { 1954 test_perform_imports_unusedImport_one() {
1955 newSource('/a.dart', r''' 1955 newSource('/a.dart', r'''
1956 library lib_a; 1956 library lib_a;
1957 class A {} 1957 class A {}
1958 '''); 1958 ''');
1959 newSource('/b.dart', r''' 1959 newSource('/b.dart', r'''
1960 library lib_b; 1960 library lib_b;
1961 class B {} 1961 class B {}
1962 '''); 1962 ''');
1963 Source source = newSource('/test.dart', r''' 1963 Source source = newSource('/test.dart', r'''
1964 import 'a.dart'; 1964 import 'a.dart';
1965 import 'b.dart'; 1965 import 'b.dart';
1966 main() { 1966 main() {
1967 new A(); 1967 new A();
1968 }'''); 1968 }''');
1969 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1969 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1970 _computeResult(target, HINTS); 1970 computeResult(target, HINTS);
1971 expect(task, new isInstanceOf<GenerateHintsTask>()); 1971 expect(task, new isInstanceOf<GenerateHintsTask>());
1972 // validate 1972 // validate
1973 _fillErrorListener(HINTS); 1973 _fillErrorListener(HINTS);
1974 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); 1974 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]);
1975 } 1975 }
1976 1976
1977 test_perform_imports_unusedImport_zero() { 1977 test_perform_imports_unusedImport_zero() {
1978 newSource('/a.dart', r''' 1978 newSource('/a.dart', r'''
1979 library lib_a; 1979 library lib_a;
1980 class A {} 1980 class A {}
1981 '''); 1981 ''');
1982 Source source = newSource('/test.dart', r''' 1982 Source source = newSource('/test.dart', r'''
1983 import 'a.dart'; 1983 import 'a.dart';
1984 main() { 1984 main() {
1985 new A(); 1985 new A();
1986 }'''); 1986 }''');
1987 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 1987 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
1988 _computeResult(target, HINTS); 1988 computeResult(target, HINTS);
1989 expect(task, new isInstanceOf<GenerateHintsTask>()); 1989 expect(task, new isInstanceOf<GenerateHintsTask>());
1990 // validate 1990 // validate
1991 _fillErrorListener(HINTS); 1991 _fillErrorListener(HINTS);
1992 errorListener.assertNoErrors(); 1992 errorListener.assertNoErrors();
1993 } 1993 }
1994 1994
1995 test_perform_overrideVerifier() { 1995 test_perform_overrideVerifier() {
1996 Source source = newSource('/test.dart', ''' 1996 Source source = newSource('/test.dart', '''
1997 class A {} 1997 class A {}
1998 class B { 1998 class B {
1999 @override 1999 @override
2000 m() {} 2000 m() {}
2001 } 2001 }
2002 '''); 2002 ''');
2003 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2003 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2004 _computeResult(target, HINTS); 2004 computeResult(target, HINTS);
2005 expect(task, new isInstanceOf<GenerateHintsTask>()); 2005 expect(task, new isInstanceOf<GenerateHintsTask>());
2006 // validate 2006 // validate
2007 _fillErrorListener(HINTS); 2007 _fillErrorListener(HINTS);
2008 errorListener.assertErrorsWithCodes( 2008 errorListener.assertErrorsWithCodes(
2009 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); 2009 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]);
2010 } 2010 }
2011 2011
2012 test_perform_todo() { 2012 test_perform_todo() {
2013 Source source = newSource('/test.dart', ''' 2013 Source source = newSource('/test.dart', '''
2014 main() { 2014 main() {
2015 // TODO(developer) foo bar 2015 // TODO(developer) foo bar
2016 } 2016 }
2017 '''); 2017 ''');
2018 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2018 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2019 _computeResult(target, HINTS); 2019 computeResult(target, HINTS);
2020 expect(task, new isInstanceOf<GenerateHintsTask>()); 2020 expect(task, new isInstanceOf<GenerateHintsTask>());
2021 // validate 2021 // validate
2022 _fillErrorListener(HINTS); 2022 _fillErrorListener(HINTS);
2023 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); 2023 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]);
2024 } 2024 }
2025 2025
2026 test_perform_unusedLocalElements_class() { 2026 test_perform_unusedLocalElements_class() {
2027 Source source = newSource('/test.dart', ''' 2027 Source source = newSource('/test.dart', '''
2028 class _A {} 2028 class _A {}
2029 class _B {} 2029 class _B {}
2030 main() { 2030 main() {
2031 new _A(); 2031 new _A();
2032 } 2032 }
2033 '''); 2033 ''');
2034 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2034 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2035 _computeResult(target, HINTS); 2035 computeResult(target, HINTS);
2036 expect(task, new isInstanceOf<GenerateHintsTask>()); 2036 expect(task, new isInstanceOf<GenerateHintsTask>());
2037 // validate 2037 // validate
2038 _fillErrorListener(HINTS); 2038 _fillErrorListener(HINTS);
2039 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); 2039 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]);
2040 } 2040 }
2041 2041
2042 test_perform_unusedLocalElements_localVariable() { 2042 test_perform_unusedLocalElements_localVariable() {
2043 Source source = newSource('/test.dart', ''' 2043 Source source = newSource('/test.dart', '''
2044 main() { 2044 main() {
2045 var v = 42; 2045 var v = 42;
2046 } 2046 }
2047 '''); 2047 ''');
2048 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2048 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2049 _computeResult(target, HINTS); 2049 computeResult(target, HINTS);
2050 expect(task, new isInstanceOf<GenerateHintsTask>()); 2050 expect(task, new isInstanceOf<GenerateHintsTask>());
2051 // validate 2051 // validate
2052 _fillErrorListener(HINTS); 2052 _fillErrorListener(HINTS);
2053 errorListener 2053 errorListener
2054 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); 2054 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]);
2055 } 2055 }
2056 2056
2057 test_perform_unusedLocalElements_method() { 2057 test_perform_unusedLocalElements_method() {
2058 Source source = newSource('/my_lib.dart', ''' 2058 Source source = newSource('/my_lib.dart', '''
2059 library my_lib; 2059 library my_lib;
2060 part 'my_part.dart'; 2060 part 'my_part.dart';
2061 class A { 2061 class A {
2062 _ma() {} 2062 _ma() {}
2063 _mb() {} 2063 _mb() {}
2064 _mc() {} 2064 _mc() {}
2065 } 2065 }
2066 '''); 2066 ''');
2067 newSource('/my_part.dart', ''' 2067 newSource('/my_part.dart', '''
2068 part of my_lib; 2068 part of my_lib;
2069 2069
2070 f(A a) { 2070 f(A a) {
2071 a._mb(); 2071 a._mb();
2072 } 2072 }
2073 '''); 2073 ''');
2074 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2074 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2075 _computeResult(target, HINTS); 2075 computeResult(target, HINTS);
2076 expect(task, new isInstanceOf<GenerateHintsTask>()); 2076 expect(task, new isInstanceOf<GenerateHintsTask>());
2077 // validate 2077 // validate
2078 _fillErrorListener(HINTS); 2078 _fillErrorListener(HINTS);
2079 errorListener.assertErrorsWithCodes( 2079 errorListener.assertErrorsWithCodes(
2080 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); 2080 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]);
2081 } 2081 }
2082 } 2082 }
2083 2083
2084 @reflectiveTest 2084 @reflectiveTest
2085 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { 2085 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest {
2086 test_perform() { 2086 test_perform() {
2087 Source library = newSource('/lib.dart', r''' 2087 Source library = newSource('/lib.dart', r'''
2088 library lib; 2088 library lib;
2089 part 'part1.dart'; 2089 part 'part1.dart';
2090 part 'part2.dart'; 2090 part 'part2.dart';
2091 X v1; 2091 X v1;
2092 '''); 2092 ''');
2093 Source part1 = newSource('/part1.dart', r''' 2093 Source part1 = newSource('/part1.dart', r'''
2094 part of lib; 2094 part of lib;
2095 X v2; 2095 X v2;
2096 '''); 2096 ''');
2097 Source part2 = newSource('/part2.dart', r''' 2097 Source part2 = newSource('/part2.dart', r'''
2098 part of lib; 2098 part of lib;
2099 X v3; 2099 X v3;
2100 '''); 2100 ''');
2101 _computeResult(library, LIBRARY_ERRORS_READY); 2101 computeResult(library, LIBRARY_ERRORS_READY);
2102 expect(task, new isInstanceOf<LibraryErrorsReadyTask>()); 2102 expect(task, new isInstanceOf<LibraryErrorsReadyTask>());
2103 expect(outputs, hasLength(1)); 2103 expect(outputs, hasLength(1));
2104 bool ready = outputs[LIBRARY_ERRORS_READY]; 2104 bool ready = outputs[LIBRARY_ERRORS_READY];
2105 expect(ready, isTrue); 2105 expect(ready, isTrue);
2106 expect(context.getErrors(library).errors, hasLength(1)); 2106 expect(context.getErrors(library).errors, hasLength(1));
2107 expect(context.getErrors(part1).errors, hasLength(1)); 2107 expect(context.getErrors(part1).errors, hasLength(1));
2108 expect(context.getErrors(part2).errors, hasLength(1)); 2108 expect(context.getErrors(part2).errors, hasLength(1));
2109 } 2109 }
2110 } 2110 }
2111 2111
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 } 2148 }
2149 2149
2150 test_descriptor() { 2150 test_descriptor() {
2151 TaskDescriptor descriptor = LibraryUnitErrorsTask.DESCRIPTOR; 2151 TaskDescriptor descriptor = LibraryUnitErrorsTask.DESCRIPTOR;
2152 expect(descriptor, isNotNull); 2152 expect(descriptor, isNotNull);
2153 } 2153 }
2154 2154
2155 test_perform_definingCompilationUnit() { 2155 test_perform_definingCompilationUnit() {
2156 AnalysisTarget library = 2156 AnalysisTarget library =
2157 newSource('/test.dart', 'library test; import "dart:math";'); 2157 newSource('/test.dart', 'library test; import "dart:math";');
2158 _computeResult( 2158 computeResult(
2159 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS); 2159 new LibrarySpecificUnit(library, library), LIBRARY_UNIT_ERRORS);
2160 expect(task, new isInstanceOf<LibraryUnitErrorsTask>()); 2160 expect(task, new isInstanceOf<LibraryUnitErrorsTask>());
2161 expect(outputs, hasLength(1)); 2161 expect(outputs, hasLength(1));
2162 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; 2162 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
2163 expect(errors, hasLength(1)); 2163 expect(errors, hasLength(1));
2164 } 2164 }
2165 2165
2166 test_perform_partInSingleLibrary() { 2166 test_perform_partInSingleLibrary() {
2167 AnalysisTarget library = 2167 AnalysisTarget library =
2168 newSource('/lib.dart', 'library test; part "part.dart";'); 2168 newSource('/lib.dart', 'library test; part "part.dart";');
2169 AnalysisTarget part = newSource('/part.dart', 'part of test;'); 2169 AnalysisTarget part = newSource('/part.dart', 'part of test;');
2170 _computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS); 2170 computeResult(new LibrarySpecificUnit(library, part), LIBRARY_UNIT_ERRORS);
2171 expect(task, new isInstanceOf<LibraryUnitErrorsTask>()); 2171 expect(task, new isInstanceOf<LibraryUnitErrorsTask>());
2172 expect(outputs, hasLength(1)); 2172 expect(outputs, hasLength(1));
2173 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS]; 2173 List<AnalysisError> errors = outputs[LIBRARY_UNIT_ERRORS];
2174 expect(errors, hasLength(0)); 2174 expect(errors, hasLength(0));
2175 } 2175 }
2176 } 2176 }
2177 2177
2178 @reflectiveTest 2178 @reflectiveTest
2179 class ParseDartTaskTest extends _AbstractDartTaskTest { 2179 class ParseDartTaskTest extends _AbstractDartTaskTest {
2180 test_buildInputs() { 2180 test_buildInputs() {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 2221 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
2222 expect(outputs[INCLUDED_PARTS], hasLength(0)); 2222 expect(outputs[INCLUDED_PARTS], hasLength(0));
2223 expect(outputs[PARSE_ERRORS], hasLength(0)); 2223 expect(outputs[PARSE_ERRORS], hasLength(0));
2224 expect(outputs[PARSED_UNIT], isNotNull); 2224 expect(outputs[PARSED_UNIT], isNotNull);
2225 expect(outputs[SOURCE_KIND], SourceKind.PART); 2225 expect(outputs[SOURCE_KIND], SourceKind.PART);
2226 expect(outputs[UNITS], hasLength(1)); 2226 expect(outputs[UNITS], hasLength(1));
2227 } 2227 }
2228 2228
2229 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { 2229 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() {
2230 // Parse "lib.dart" to let the context know that "test.dart" is included. 2230 // Parse "lib.dart" to let the context know that "test.dart" is included.
2231 _computeResult(newSource('/lib.dart', r''' 2231 computeResult(newSource('/lib.dart', r'''
2232 library lib; 2232 library lib;
2233 part 'test.dart'; 2233 part 'test.dart';
2234 '''), PARSED_UNIT); 2234 '''), PARSED_UNIT);
2235 // If there are no the "part of" directive, then it is not a part. 2235 // If there are no the "part of" directive, then it is not a part.
2236 _performParseTask(''); 2236 _performParseTask('');
2237 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); 2237 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY);
2238 } 2238 }
2239 2239
2240 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { 2240 test_perform_computeSourceKind_noDirectives_noContainingLibrary() {
2241 _performParseTask(''); 2241 _performParseTask('');
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
2302 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); 2302 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1);
2303 expect(outputs[INCLUDED_PARTS], hasLength(0)); 2303 expect(outputs[INCLUDED_PARTS], hasLength(0));
2304 expect(outputs[PARSE_ERRORS], hasLength(0)); 2304 expect(outputs[PARSE_ERRORS], hasLength(0));
2305 expect(outputs[PARSED_UNIT], isNotNull); 2305 expect(outputs[PARSED_UNIT], isNotNull);
2306 expect(outputs[SOURCE_KIND], SourceKind.PART); 2306 expect(outputs[SOURCE_KIND], SourceKind.PART);
2307 expect(outputs[UNITS], hasLength(1)); 2307 expect(outputs[UNITS], hasLength(1));
2308 } 2308 }
2309 2309
2310 void _performParseTask(String content) { 2310 void _performParseTask(String content) {
2311 AnalysisTarget target = newSource('/test.dart', content); 2311 AnalysisTarget target = newSource('/test.dart', content);
2312 _computeResult(target, PARSED_UNIT); 2312 computeResult(target, PARSED_UNIT);
2313 expect(task, new isInstanceOf<ParseDartTask>()); 2313 expect(task, new isInstanceOf<ParseDartTask>());
2314 } 2314 }
2315 2315
2316 static void _assertHasCore(List<Source> sources, int lenght) { 2316 static void _assertHasCore(List<Source> sources, int lenght) {
2317 expect(sources, hasLength(lenght)); 2317 expect(sources, hasLength(lenght));
2318 expect(sources, contains(predicate((Source s) { 2318 expect(sources, contains(predicate((Source s) {
2319 return s.fullName.endsWith('core.dart'); 2319 return s.fullName.endsWith('core.dart');
2320 }))); 2320 })));
2321 } 2321 }
2322 } 2322 }
2323 2323
2324 @reflectiveTest 2324 @reflectiveTest
2325 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { 2325 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest {
2326 test_perform() { 2326 test_perform() {
2327 Source sourceLib = newSource('/my_lib.dart', ''' 2327 Source sourceLib = newSource('/my_lib.dart', '''
2328 library my_lib; 2328 library my_lib;
2329 part 'my_part.dart'; 2329 part 'my_part.dart';
2330 class A {} 2330 class A {}
2331 class B extends A {} 2331 class B extends A {}
2332 '''); 2332 ''');
2333 newSource('/my_part.dart', ''' 2333 newSource('/my_part.dart', '''
2334 part of my_lib; 2334 part of my_lib;
2335 class C extends A {} 2335 class C extends A {}
2336 '''); 2336 ''');
2337 _computeResult(sourceLib, LIBRARY_ELEMENT5); 2337 computeResult(sourceLib, LIBRARY_ELEMENT5);
2338 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); 2338 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>());
2339 // validate 2339 // validate
2340 LibraryElement library = outputs[LIBRARY_ELEMENT5]; 2340 LibraryElement library = outputs[LIBRARY_ELEMENT5];
2341 { 2341 {
2342 ClassElement classB = library.getType('B'); 2342 ClassElement classB = library.getType('B');
2343 expect(classB.supertype.displayName, 'A'); 2343 expect(classB.supertype.displayName, 'A');
2344 } 2344 }
2345 { 2345 {
2346 ClassElement classC = library.getType('C'); 2346 ClassElement classC = library.getType('C');
2347 expect(classC.supertype.displayName, 'A'); 2347 expect(classC.supertype.displayName, 'A');
(...skipping 13 matching lines...) Expand all
2361 class B extends B2 {} 2361 class B extends B2 {}
2362 '''); 2362 ''');
2363 newSource('/b2.dart', ''' 2363 newSource('/b2.dart', '''
2364 part of b; 2364 part of b;
2365 class B2 extends C {} 2365 class B2 extends C {}
2366 '''); 2366 ''');
2367 newSource('/c.dart', ''' 2367 newSource('/c.dart', '''
2368 library c; 2368 library c;
2369 class C {} 2369 class C {}
2370 '''); 2370 ''');
2371 _computeResult(sourceA, LIBRARY_ELEMENT5); 2371 computeResult(sourceA, LIBRARY_ELEMENT5);
2372 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>()); 2372 expect(task, new isInstanceOf<ResolveLibraryTypeNamesTask>());
2373 // validate 2373 // validate
2374 LibraryElement library = outputs[LIBRARY_ELEMENT5]; 2374 LibraryElement library = outputs[LIBRARY_ELEMENT5];
2375 { 2375 {
2376 ClassElement clazz = library.getType('A'); 2376 ClassElement clazz = library.getType('A');
2377 expect(clazz.displayName, 'A'); 2377 expect(clazz.displayName, 'A');
2378 clazz = clazz.supertype.element; 2378 clazz = clazz.supertype.element;
2379 expect(clazz.displayName, 'B'); 2379 expect(clazz.displayName, 'B');
2380 clazz = clazz.supertype.element; 2380 clazz = clazz.supertype.element;
2381 expect(clazz.displayName, 'B2'); 2381 expect(clazz.displayName, 'B2');
(...skipping 12 matching lines...) Expand all
2394 Source source = newSource('/test.dart', ''' 2394 Source source = newSource('/test.dart', '''
2395 class A { 2395 class A {
2396 m() {} 2396 m() {}
2397 } 2397 }
2398 main(A a) { 2398 main(A a) {
2399 a.m(); 2399 a.m();
2400 } 2400 }
2401 '''); 2401 ''');
2402 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2402 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2403 // prepare unit and "a.m()" invocation 2403 // prepare unit and "a.m()" invocation
2404 _computeResult(target, RESOLVED_UNIT6); 2404 computeResult(target, RESOLVED_UNIT6);
2405 CompilationUnit unit = outputs[RESOLVED_UNIT6]; 2405 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2406 // walk the AST 2406 // walk the AST
2407 FunctionDeclaration function = unit.declarations[1]; 2407 FunctionDeclaration function = unit.declarations[1];
2408 BlockFunctionBody body = function.functionExpression.body; 2408 BlockFunctionBody body = function.functionExpression.body;
2409 ExpressionStatement statement = body.block.statements[0]; 2409 ExpressionStatement statement = body.block.statements[0];
2410 MethodInvocation invocation = statement.expression; 2410 MethodInvocation invocation = statement.expression;
2411 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); 2411 expect(task, new isInstanceOf<ResolveUnitReferencesTask>());
2412 expect(unit, same(outputs[RESOLVED_UNIT6])); 2412 expect(unit, same(outputs[RESOLVED_UNIT6]));
2413 // a.m() is resolved now 2413 // a.m() is resolved now
2414 expect(invocation.methodName.staticElement, isNotNull); 2414 expect(invocation.methodName.staticElement, isNotNull);
2415 } 2415 }
2416 2416
2417 test_perform_errors() { 2417 test_perform_errors() {
2418 Source source = newSource('/test.dart', ''' 2418 Source source = newSource('/test.dart', '''
2419 class A { 2419 class A {
2420 } 2420 }
2421 main(A a) { 2421 main(A a) {
2422 a.unknownMethod(); 2422 a.unknownMethod();
2423 } 2423 }
2424 '''); 2424 ''');
2425 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2425 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2426 _computeResult(target, RESOLVED_UNIT6); 2426 computeResult(target, RESOLVED_UNIT6);
2427 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); 2427 expect(task, new isInstanceOf<ResolveUnitReferencesTask>());
2428 // validate 2428 // validate
2429 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); 2429 _fillErrorListener(RESOLVE_REFERENCES_ERRORS);
2430 errorListener.assertErrorsWithCodes( 2430 errorListener.assertErrorsWithCodes(
2431 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); 2431 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]);
2432 } 2432 }
2433 2433
2434 test_perform_importExport() { 2434 test_perform_importExport() {
2435 newSource('/a.dart', ''' 2435 newSource('/a.dart', '''
2436 library a; 2436 library a;
2437 class A<T> { 2437 class A<T> {
2438 T m() {} 2438 T m() {}
2439 } 2439 }
2440 '''); 2440 ''');
2441 newSource('/b.dart', ''' 2441 newSource('/b.dart', '''
2442 library b; 2442 library b;
2443 export 'a.dart'; 2443 export 'a.dart';
2444 '''); 2444 ''');
2445 Source sourceC = newSource('/c.dart', ''' 2445 Source sourceC = newSource('/c.dart', '''
2446 library c; 2446 library c;
2447 import 'b.dart'; 2447 import 'b.dart';
2448 main() { 2448 main() {
2449 new A<int>().m(); 2449 new A<int>().m();
2450 } 2450 }
2451 '''); 2451 ''');
2452 _computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6); 2452 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6);
2453 expect(task, new isInstanceOf<ResolveUnitReferencesTask>()); 2453 expect(task, new isInstanceOf<ResolveUnitReferencesTask>());
2454 // validate 2454 // validate
2455 CompilationUnit unit = outputs[RESOLVED_UNIT6]; 2455 CompilationUnit unit = outputs[RESOLVED_UNIT6];
2456 expect(unit, isNotNull); 2456 expect(unit, isNotNull);
2457 { 2457 {
2458 FunctionDeclaration functionDeclaration = unit.declarations[0]; 2458 FunctionDeclaration functionDeclaration = unit.declarations[0];
2459 BlockFunctionBody body = functionDeclaration.functionExpression.body; 2459 BlockFunctionBody body = functionDeclaration.functionExpression.body;
2460 List<Statement> statements = body.block.statements; 2460 List<Statement> statements = body.block.statements;
2461 ExpressionStatement statement = statements[0]; 2461 ExpressionStatement statement = statements[0];
2462 MethodInvocation invocation = statement.expression; 2462 MethodInvocation invocation = statement.expression;
2463 MethodElement methodElement = invocation.methodName.staticElement; 2463 MethodElement methodElement = invocation.methodName.staticElement;
2464 expect(methodElement, isNotNull); 2464 expect(methodElement, isNotNull);
2465 expect(methodElement.type, isNotNull); 2465 expect(methodElement.type, isNotNull);
2466 expect(methodElement.returnType.toString(), 'int'); 2466 expect(methodElement.returnType.toString(), 'int');
2467 } 2467 }
2468 } 2468 }
2469 } 2469 }
2470 2470
2471 @reflectiveTest 2471 @reflectiveTest
2472 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { 2472 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest {
2473 test_perform() { 2473 test_perform() {
2474 Source source = newSource('/test.dart', ''' 2474 Source source = newSource('/test.dart', '''
2475 class A {} 2475 class A {}
2476 class B extends A {} 2476 class B extends A {}
2477 int f(String p) => p.length; 2477 int f(String p) => p.length;
2478 '''); 2478 ''');
2479 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2479 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2480 _computeResult(target, RESOLVED_UNIT4); 2480 computeResult(target, RESOLVED_UNIT4);
2481 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); 2481 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>());
2482 // validate 2482 // validate
2483 CompilationUnit unit = outputs[RESOLVED_UNIT4]; 2483 CompilationUnit unit = outputs[RESOLVED_UNIT4];
2484 { 2484 {
2485 ClassDeclaration nodeA = unit.declarations[0]; 2485 ClassDeclaration nodeA = unit.declarations[0];
2486 ClassDeclaration nodeB = unit.declarations[1]; 2486 ClassDeclaration nodeB = unit.declarations[1];
2487 DartType extendsType = nodeB.extendsClause.superclass.type; 2487 DartType extendsType = nodeB.extendsClause.superclass.type;
2488 expect(extendsType, nodeA.element.type); 2488 expect(extendsType, nodeA.element.type);
2489 } 2489 }
2490 { 2490 {
2491 FunctionDeclaration functionNode = unit.declarations[2]; 2491 FunctionDeclaration functionNode = unit.declarations[2];
2492 DartType returnType = functionNode.returnType.type; 2492 DartType returnType = functionNode.returnType.type;
2493 List<FormalParameter> parameters = 2493 List<FormalParameter> parameters =
2494 functionNode.functionExpression.parameters.parameters; 2494 functionNode.functionExpression.parameters.parameters;
2495 expect(returnType.displayName, 'int'); 2495 expect(returnType.displayName, 'int');
2496 expect(parameters[0].element.type.displayName, 'String'); 2496 expect(parameters[0].element.type.displayName, 'String');
2497 } 2497 }
2498 } 2498 }
2499 2499
2500 test_perform_errors() { 2500 test_perform_errors() {
2501 Source source = newSource('/test.dart', ''' 2501 Source source = newSource('/test.dart', '''
2502 NoSuchClass f() => null; 2502 NoSuchClass f() => null;
2503 '''); 2503 ''');
2504 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2504 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2505 _computeResult(target, RESOLVE_TYPE_NAMES_ERRORS); 2505 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS);
2506 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>()); 2506 expect(task, new isInstanceOf<ResolveUnitTypeNamesTask>());
2507 // validate 2507 // validate
2508 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); 2508 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS);
2509 errorListener 2509 errorListener
2510 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); 2510 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]);
2511 } 2511 }
2512 } 2512 }
2513 2513
2514 @reflectiveTest 2514 @reflectiveTest
2515 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { 2515 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest {
2516 /** 2516 /**
2517 * Verify that the mutated states of the given [variable] correspond to the 2517 * Verify that the mutated states of the given [variable] correspond to the
2518 * [mutatedInClosure] and [mutatedInScope] matchers. 2518 * [mutatedInClosure] and [mutatedInScope] matchers.
2519 */ 2519 */
2520 void expectMutated(VariableElement variable, Matcher mutatedInClosure, 2520 void expectMutated(VariableElement variable, Matcher mutatedInClosure,
2521 Matcher mutatedInScope) { 2521 Matcher mutatedInScope) {
2522 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure); 2522 expect(variable.isPotentiallyMutatedInClosure, mutatedInClosure);
2523 expect(variable.isPotentiallyMutatedInScope, mutatedInScope); 2523 expect(variable.isPotentiallyMutatedInScope, mutatedInScope);
2524 } 2524 }
2525 2525
2526 test_perform_buildClosureLibraryElements() { 2526 test_perform_buildClosureLibraryElements() {
2527 Source source = newSource('/test.dart', ''' 2527 Source source = newSource('/test.dart', '''
2528 main() { 2528 main() {
2529 } 2529 }
2530 '''); 2530 ''');
2531 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2531 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2532 _computeResult(target, RESOLVED_UNIT5); 2532 computeResult(target, RESOLVED_UNIT5);
2533 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); 2533 expect(task, new isInstanceOf<ResolveVariableReferencesTask>());
2534 } 2534 }
2535 2535
2536 test_perform_local() { 2536 test_perform_local() {
2537 Source source = newSource('/test.dart', ''' 2537 Source source = newSource('/test.dart', '''
2538 main() { 2538 main() {
2539 var v1 = 1; 2539 var v1 = 1;
2540 var v2 = 1; 2540 var v2 = 1;
2541 var v3 = 1; 2541 var v3 = 1;
2542 var v4 = 1; 2542 var v4 = 1;
2543 v2 = 2; 2543 v2 = 2;
2544 v4 = 2; 2544 v4 = 2;
2545 localFunction() { 2545 localFunction() {
2546 v3 = 3; 2546 v3 = 3;
2547 v4 = 3; 2547 v4 = 3;
2548 } 2548 }
2549 } 2549 }
2550 '''); 2550 ''');
2551 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2551 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2552 _computeResult(target, RESOLVED_UNIT5); 2552 computeResult(target, RESOLVED_UNIT5);
2553 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); 2553 expect(task, new isInstanceOf<ResolveVariableReferencesTask>());
2554 // validate 2554 // validate
2555 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2555 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2556 FunctionElement main = unit.element.functions[0]; 2556 FunctionElement main = unit.element.functions[0];
2557 expectMutated(main.localVariables[0], isFalse, isFalse); 2557 expectMutated(main.localVariables[0], isFalse, isFalse);
2558 expectMutated(main.localVariables[1], isFalse, isTrue); 2558 expectMutated(main.localVariables[1], isFalse, isTrue);
2559 expectMutated(main.localVariables[2], isTrue, isTrue); 2559 expectMutated(main.localVariables[2], isTrue, isTrue);
2560 expectMutated(main.localVariables[3], isTrue, isTrue); 2560 expectMutated(main.localVariables[3], isTrue, isTrue);
2561 } 2561 }
2562 2562
2563 test_perform_parameter() { 2563 test_perform_parameter() {
2564 Source source = newSource('/test.dart', ''' 2564 Source source = newSource('/test.dart', '''
2565 main(p1, p2, p3, p4) { 2565 main(p1, p2, p3, p4) {
2566 p2 = 2; 2566 p2 = 2;
2567 p4 = 2; 2567 p4 = 2;
2568 localFunction() { 2568 localFunction() {
2569 p3 = 3; 2569 p3 = 3;
2570 p4 = 3; 2570 p4 = 3;
2571 } 2571 }
2572 } 2572 }
2573 '''); 2573 ''');
2574 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2574 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2575 _computeResult(target, RESOLVED_UNIT5); 2575 computeResult(target, RESOLVED_UNIT5);
2576 expect(task, new isInstanceOf<ResolveVariableReferencesTask>()); 2576 expect(task, new isInstanceOf<ResolveVariableReferencesTask>());
2577 // validate 2577 // validate
2578 CompilationUnit unit = outputs[RESOLVED_UNIT5]; 2578 CompilationUnit unit = outputs[RESOLVED_UNIT5];
2579 FunctionElement main = unit.element.functions[0]; 2579 FunctionElement main = unit.element.functions[0];
2580 expectMutated(main.parameters[0], isFalse, isFalse); 2580 expectMutated(main.parameters[0], isFalse, isFalse);
2581 expectMutated(main.parameters[1], isFalse, isTrue); 2581 expectMutated(main.parameters[1], isFalse, isTrue);
2582 expectMutated(main.parameters[2], isTrue, isTrue); 2582 expectMutated(main.parameters[2], isTrue, isTrue);
2583 expectMutated(main.parameters[3], isTrue, isTrue); 2583 expectMutated(main.parameters[3], isTrue, isTrue);
2584 } 2584 }
2585 } 2585 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2627 test_perform_noErrors() { 2627 test_perform_noErrors() {
2628 _performScanTask('class A {}'); 2628 _performScanTask('class A {}');
2629 expect(outputs, hasLength(3)); 2629 expect(outputs, hasLength(3));
2630 expect(outputs[LINE_INFO], isNotNull); 2630 expect(outputs[LINE_INFO], isNotNull);
2631 expect(outputs[SCAN_ERRORS], hasLength(0)); 2631 expect(outputs[SCAN_ERRORS], hasLength(0));
2632 expect(outputs[TOKEN_STREAM], isNotNull); 2632 expect(outputs[TOKEN_STREAM], isNotNull);
2633 } 2633 }
2634 2634
2635 void _performScanTask(String content) { 2635 void _performScanTask(String content) {
2636 AnalysisTarget target = newSource('/test.dart', content); 2636 AnalysisTarget target = newSource('/test.dart', content);
2637 _computeResult(target, TOKEN_STREAM); 2637 computeResult(target, TOKEN_STREAM);
2638 expect(task, new isInstanceOf<ScanDartTask>()); 2638 expect(task, new isInstanceOf<ScanDartTask>());
2639 } 2639 }
2640 } 2640 }
2641 2641
2642 @reflectiveTest 2642 @reflectiveTest
2643 class VerifyUnitTaskTest extends _AbstractDartTaskTest { 2643 class VerifyUnitTaskTest extends _AbstractDartTaskTest {
2644 test_perform_constantError() { 2644 test_perform_constantError() {
2645 Source source = newSource('/test.dart', ''' 2645 Source source = newSource('/test.dart', '''
2646 main(int p) { 2646 main(int p) {
2647 const v = p; 2647 const v = p;
2648 } 2648 }
2649 '''); 2649 ''');
2650 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2650 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2651 _computeResult(target, VERIFY_ERRORS); 2651 computeResult(target, VERIFY_ERRORS);
2652 expect(task, new isInstanceOf<VerifyUnitTask>()); 2652 expect(task, new isInstanceOf<VerifyUnitTask>());
2653 // validate 2653 // validate
2654 _fillErrorListener(VERIFY_ERRORS); 2654 _fillErrorListener(VERIFY_ERRORS);
2655 errorListener.assertErrorsWithCodes(<ErrorCode>[ 2655 errorListener.assertErrorsWithCodes(<ErrorCode>[
2656 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE 2656 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE
2657 ]); 2657 ]);
2658 } 2658 }
2659 2659
2660 test_perform_directiveError() { 2660 test_perform_directiveError() {
2661 Source source = newSource('/test.dart', ''' 2661 Source source = newSource('/test.dart', '''
2662 import 'no-such-file.dart'; 2662 import 'no-such-file.dart';
2663 '''); 2663 ''');
2664 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2664 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2665 _computeResult(target, VERIFY_ERRORS); 2665 computeResult(target, VERIFY_ERRORS);
2666 expect(task, new isInstanceOf<VerifyUnitTask>()); 2666 expect(task, new isInstanceOf<VerifyUnitTask>());
2667 // validate 2667 // validate
2668 _fillErrorListener(VERIFY_ERRORS); 2668 _fillErrorListener(VERIFY_ERRORS);
2669 errorListener.assertErrorsWithCodes( 2669 errorListener.assertErrorsWithCodes(
2670 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); 2670 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]);
2671 } 2671 }
2672 2672
2673 test_perform_verifyError() { 2673 test_perform_verifyError() {
2674 Source source = newSource('/test.dart', ''' 2674 Source source = newSource('/test.dart', '''
2675 main() { 2675 main() {
2676 if (42) { 2676 if (42) {
2677 print('Not bool!'); 2677 print('Not bool!');
2678 } 2678 }
2679 } 2679 }
2680 '''); 2680 ''');
2681 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); 2681 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source);
2682 _computeResult(target, VERIFY_ERRORS); 2682 computeResult(target, VERIFY_ERRORS);
2683 expect(task, new isInstanceOf<VerifyUnitTask>()); 2683 expect(task, new isInstanceOf<VerifyUnitTask>());
2684 // validate 2684 // validate
2685 _fillErrorListener(VERIFY_ERRORS); 2685 _fillErrorListener(VERIFY_ERRORS);
2686 errorListener.assertErrorsWithCodes( 2686 errorListener.assertErrorsWithCodes(
2687 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]); 2687 <ErrorCode>[StaticTypeWarningCode.NON_BOOL_CONDITION]);
2688 } 2688 }
2689 } 2689 }
2690 2690
2691 class _AbstractDartTaskTest extends AbstractContextTest { 2691 class _AbstractDartTaskTest extends AbstractContextTest {
2692 Source emptySource; 2692 Source emptySource;
2693 2693
2694 AnalysisTask task;
2695 Map<ResultDescriptor<dynamic>, dynamic> oldOutputs;
2696 Map<ResultDescriptor<dynamic>, dynamic> outputs;
2697 GatheringErrorListener errorListener = new GatheringErrorListener(); 2694 GatheringErrorListener errorListener = new GatheringErrorListener();
2698 2695
2699 void assertIsInvalid(AnalysisTarget target, ResultDescriptor descriptor) { 2696 void assertIsInvalid(AnalysisTarget target, ResultDescriptor descriptor) {
2700 CacheEntry entry = context.getCacheEntry(target); 2697 CacheEntry entry = context.getCacheEntry(target);
2701 expect(entry.isInvalid(descriptor), isTrue); 2698 expect(entry.isInvalid(descriptor), isTrue);
2702 } 2699 }
2703 2700
2704 void assertIsValid(AnalysisTarget target, ResultDescriptor descriptor) { 2701 void assertIsValid(AnalysisTarget target, ResultDescriptor descriptor) {
2705 CacheEntry entry = context.getCacheEntry(target); 2702 CacheEntry entry = context.getCacheEntry(target);
2706 expect(entry.isValid(descriptor), isTrue); 2703 expect(entry.isValid(descriptor), isTrue);
2707 } 2704 }
2708 2705
2709 void assertSameResults(List<ResultDescriptor> descriptors) { 2706 void assertSameResults(List<ResultDescriptor> descriptors) {
2710 descriptors.forEach((descriptor) { 2707 descriptors.forEach((descriptor) {
2711 var oldResult = oldOutputs[descriptor]; 2708 var oldResult = oldOutputs[descriptor];
2712 var newResult = outputs[descriptor]; 2709 var newResult = outputs[descriptor];
2713 expect(newResult, same(oldResult), reason: descriptor.name); 2710 expect(newResult, same(oldResult), reason: descriptor.name);
2714 }); 2711 });
2715 } 2712 }
2716 2713
2717 void setUp() { 2714 void setUp() {
2718 super.setUp(); 2715 super.setUp();
2719 emptySource = newSource('/test.dart'); 2716 emptySource = newSource('/test.dart');
2720 } 2717 }
2721 2718
2722 void _computeResult(AnalysisTarget target, ResultDescriptor result) {
2723 oldOutputs = outputs;
2724 task = analysisDriver.computeResult(target, result);
2725 expect(task, isNotNull);
2726 expect(task.caughtException, isNull);
2727 outputs = task.outputs;
2728 }
2729
2730 /** 2719 /**
2731 * Fill [errorListener] with [result] errors in the current [task]. 2720 * Fill [errorListener] with [result] errors in the current [task].
2732 */ 2721 */
2733 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 2722 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
2734 List<AnalysisError> errors = task.outputs[result]; 2723 List<AnalysisError> errors = task.outputs[result];
2735 expect(errors, isNotNull, reason: result.name); 2724 expect(errors, isNotNull, reason: result.name);
2736 errorListener = new GatheringErrorListener(); 2725 errorListener = new GatheringErrorListener();
2737 errorListener.addAll(errors); 2726 errorListener.addAll(errors);
2738 } 2727 }
2739 } 2728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698