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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/driver_test.dart

Issue 2975253002: Format analyzer, analysis_server, analyzer_plugin, front_end and kernel with the latest dartfmt. (Closed)
Patch Set: Created 3 years, 5 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart';
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 driver.removeFile(a); 356 driver.removeFile(a);
357 expect(driver.addedFiles, isNot(contains(a))); 357 expect(driver.addedFiles, isNot(contains(a)));
358 expect(driver.addedFiles, isNot(contains(b))); 358 expect(driver.addedFiles, isNot(contains(b)));
359 } 359 }
360 360
361 test_addFile_shouldRefresh() async { 361 test_addFile_shouldRefresh() async {
362 var a = _p('/test/lib/a.dart'); 362 var a = _p('/test/lib/a.dart');
363 var b = _p('/test/lib/b.dart'); 363 var b = _p('/test/lib/b.dart');
364 364
365 provider.newFile(a, 'class A {}'); 365 provider.newFile(a, 'class A {}');
366 provider.newFile( 366 provider.newFile(b, r'''
367 b,
368 r'''
369 import 'a.dart'; 367 import 'a.dart';
370 '''); 368 ''');
371 369
372 driver.addFile(a); 370 driver.addFile(a);
373 driver.addFile(b); 371 driver.addFile(b);
374 372
375 void assertNumberOfErrorsInB(int n) { 373 void assertNumberOfErrorsInB(int n) {
376 var bResult = allResults.singleWhere((r) => r.path == b); 374 var bResult = allResults.singleWhere((r) => r.path == b);
377 expect(bResult.errors, hasLength(n)); 375 expect(bResult.errors, hasLength(n));
378 allResults.clear(); 376 allResults.clear();
379 } 377 }
380 378
381 // Initial analysis, 'b' does not use 'a', so there is a hint. 379 // Initial analysis, 'b' does not use 'a', so there is a hint.
382 await scheduler.waitForIdle(); 380 await scheduler.waitForIdle();
383 assertNumberOfErrorsInB(1); 381 assertNumberOfErrorsInB(1);
384 382
385 // Update 'b' to use 'a', no more hints. 383 // Update 'b' to use 'a', no more hints.
386 provider.newFile( 384 provider.newFile(b, r'''
387 b,
388 r'''
389 import 'a.dart'; 385 import 'a.dart';
390 main() { 386 main() {
391 print(A); 387 print(A);
392 } 388 }
393 '''); 389 ''');
394 driver.changeFile(b); 390 driver.changeFile(b);
395 await scheduler.waitForIdle(); 391 await scheduler.waitForIdle();
396 assertNumberOfErrorsInB(0); 392 assertNumberOfErrorsInB(0);
397 393
398 // Change 'b' content so that it has a hint. 394 // Change 'b' content so that it has a hint.
399 // Remove 'b' and add it again. 395 // Remove 'b' and add it again.
400 // The file 'b' must be refreshed, and the hint must be reported. 396 // The file 'b' must be refreshed, and the hint must be reported.
401 provider.newFile( 397 provider.newFile(b, r'''
402 b,
403 r'''
404 import 'a.dart'; 398 import 'a.dart';
405 '''); 399 ''');
406 driver.removeFile(b); 400 driver.removeFile(b);
407 driver.addFile(b); 401 driver.addFile(b);
408 await scheduler.waitForIdle(); 402 await scheduler.waitForIdle();
409 assertNumberOfErrorsInB(1); 403 assertNumberOfErrorsInB(1);
410 } 404 }
411 405
412 test_addFile_thenRemove() async { 406 test_addFile_thenRemove() async {
413 var a = _p('/test/lib/a.dart'); 407 var a = _p('/test/lib/a.dart');
(...skipping 10 matching lines...) Expand all
424 418
425 // Only 'b' has been analyzed, because 'a' was removed before we started. 419 // Only 'b' has been analyzed, because 'a' was removed before we started.
426 expect(allResults, hasLength(1)); 420 expect(allResults, hasLength(1));
427 expect(allResults[0].path, b); 421 expect(allResults[0].path, b);
428 } 422 }
429 423
430 test_analyze_resolveDirectives() async { 424 test_analyze_resolveDirectives() async {
431 var lib = _p('/test/lib.dart'); 425 var lib = _p('/test/lib.dart');
432 var part1 = _p('/test/part1.dart'); 426 var part1 = _p('/test/part1.dart');
433 var part2 = _p('/test/part2.dart'); 427 var part2 = _p('/test/part2.dart');
434 provider.newFile( 428 provider.newFile(lib, '''
435 lib,
436 '''
437 library lib; 429 library lib;
438 part 'part1.dart'; 430 part 'part1.dart';
439 part 'part2.dart'; 431 part 'part2.dart';
440 '''); 432 ''');
441 provider.newFile( 433 provider.newFile(part1, '''
442 part1,
443 '''
444 part of lib; 434 part of lib;
445 '''); 435 ''');
446 provider.newFile( 436 provider.newFile(part2, '''
447 part2,
448 '''
449 part of 'lib.dart'; 437 part of 'lib.dart';
450 '''); 438 ''');
451 439
452 AnalysisResult libResult = await driver.getResult(lib); 440 AnalysisResult libResult = await driver.getResult(lib);
453 AnalysisResult partResult1 = await driver.getResult(part1); 441 AnalysisResult partResult1 = await driver.getResult(part1);
454 AnalysisResult partResult2 = await driver.getResult(part2); 442 AnalysisResult partResult2 = await driver.getResult(part2);
455 443
456 CompilationUnit libUnit = libResult.unit; 444 CompilationUnit libUnit = libResult.unit;
457 CompilationUnit partUnit1 = partResult1.unit; 445 CompilationUnit partUnit1 = partResult1.unit;
458 CompilationUnit partUnit2 = partResult2.unit; 446 CompilationUnit partUnit2 = partResult2.unit;
(...skipping 21 matching lines...) Expand all
480 468
481 { 469 {
482 var partOf = partUnit2.directives.single as PartOfDirective; 470 var partOf = partUnit2.directives.single as PartOfDirective;
483 expect(partOf.element, libraryElement); 471 expect(partOf.element, libraryElement);
484 } 472 }
485 } 473 }
486 474
487 test_analyze_resolveDirectives_error_missingLibraryDirective() async { 475 test_analyze_resolveDirectives_error_missingLibraryDirective() async {
488 var lib = _p('/test/lib.dart'); 476 var lib = _p('/test/lib.dart');
489 var part = _p('/test/part.dart'); 477 var part = _p('/test/part.dart');
490 provider.newFile( 478 provider.newFile(lib, '''
491 lib,
492 '''
493 part 'part.dart'; 479 part 'part.dart';
494 '''); 480 ''');
495 provider.newFile( 481 provider.newFile(part, '''
496 part,
497 '''
498 part of lib; 482 part of lib;
499 '''); 483 ''');
500 484
501 driver.addFile(lib); 485 driver.addFile(lib);
502 486
503 AnalysisResult libResult = await driver.getResult(lib); 487 AnalysisResult libResult = await driver.getResult(lib);
504 List<AnalysisError> errors = libResult.errors; 488 List<AnalysisError> errors = libResult.errors;
505 if (libResult.unit.element.context.analysisOptions.enableUriInPartOf) { 489 if (libResult.unit.element.context.analysisOptions.enableUriInPartOf) {
506 expect(errors, hasLength(1)); 490 expect(errors, hasLength(1));
507 expect(errors[0].errorCode, ResolverErrorCode.PART_OF_UNNAMED_LIBRARY); 491 expect(errors[0].errorCode, ResolverErrorCode.PART_OF_UNNAMED_LIBRARY);
508 } else { 492 } else {
509 expect(errors, hasLength(1)); 493 expect(errors, hasLength(1));
510 expect(errors[0].errorCode, 494 expect(errors[0].errorCode,
511 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART); 495 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART);
512 } 496 }
513 } 497 }
514 498
515 test_analyze_resolveDirectives_error_partOfDifferentLibrary_byName() async { 499 test_analyze_resolveDirectives_error_partOfDifferentLibrary_byName() async {
516 var lib = _p('/test/lib.dart'); 500 var lib = _p('/test/lib.dart');
517 var part = _p('/test/part.dart'); 501 var part = _p('/test/part.dart');
518 provider.newFile( 502 provider.newFile(lib, '''
519 lib,
520 '''
521 library lib; 503 library lib;
522 part 'part.dart'; 504 part 'part.dart';
523 '''); 505 ''');
524 provider.newFile( 506 provider.newFile(part, '''
525 part,
526 '''
527 part of someOtherLib; 507 part of someOtherLib;
528 '''); 508 ''');
529 509
530 driver.addFile(lib); 510 driver.addFile(lib);
531 511
532 AnalysisResult libResult = await driver.getResult(lib); 512 AnalysisResult libResult = await driver.getResult(lib);
533 List<AnalysisError> errors = libResult.errors; 513 List<AnalysisError> errors = libResult.errors;
534 expect(errors, hasLength(1)); 514 expect(errors, hasLength(1));
535 expect(errors[0].errorCode, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY); 515 expect(errors[0].errorCode, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY);
536 } 516 }
537 517
538 test_analyze_resolveDirectives_error_partOfDifferentLibrary_byUri() async { 518 test_analyze_resolveDirectives_error_partOfDifferentLibrary_byUri() async {
539 var lib = _p('/test/lib.dart'); 519 var lib = _p('/test/lib.dart');
540 var part = _p('/test/part.dart'); 520 var part = _p('/test/part.dart');
541 provider.newFile( 521 provider.newFile(lib, '''
542 lib,
543 '''
544 library lib; 522 library lib;
545 part 'part.dart'; 523 part 'part.dart';
546 '''); 524 ''');
547 provider.newFile( 525 provider.newFile(part, '''
548 part,
549 '''
550 part of 'other_lib.dart'; 526 part of 'other_lib.dart';
551 '''); 527 ''');
552 528
553 driver.addFile(lib); 529 driver.addFile(lib);
554 530
555 AnalysisResult libResult = await driver.getResult(lib); 531 AnalysisResult libResult = await driver.getResult(lib);
556 List<AnalysisError> errors = libResult.errors; 532 List<AnalysisError> errors = libResult.errors;
557 expect(errors, hasLength(1)); 533 expect(errors, hasLength(1));
558 expect(errors[0].errorCode, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY); 534 expect(errors[0].errorCode, StaticWarningCode.PART_OF_DIFFERENT_LIBRARY);
559 } 535 }
560 536
561 test_analyze_resolveDirectives_error_partOfNonPart() async { 537 test_analyze_resolveDirectives_error_partOfNonPart() async {
562 var lib = _p('/test/lib.dart'); 538 var lib = _p('/test/lib.dart');
563 var part = _p('/test/part.dart'); 539 var part = _p('/test/part.dart');
564 provider.newFile( 540 provider.newFile(lib, '''
565 lib,
566 '''
567 library lib; 541 library lib;
568 part 'part.dart'; 542 part 'part.dart';
569 '''); 543 ''');
570 provider.newFile( 544 provider.newFile(part, '''
571 part,
572 '''
573 // no part of directive 545 // no part of directive
574 '''); 546 ''');
575 547
576 driver.addFile(lib); 548 driver.addFile(lib);
577 549
578 AnalysisResult libResult = await driver.getResult(lib); 550 AnalysisResult libResult = await driver.getResult(lib);
579 List<AnalysisError> errors = libResult.errors; 551 List<AnalysisError> errors = libResult.errors;
580 expect(errors, hasLength(1)); 552 expect(errors, hasLength(1));
581 expect(errors[0].errorCode, CompileTimeErrorCode.PART_OF_NON_PART); 553 expect(errors[0].errorCode, CompileTimeErrorCode.PART_OF_NON_PART);
582 } 554 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 expect(driver.test.priorityResults, isEmpty); 636 expect(driver.test.priorityResults, isEmpty);
665 637
666 // The file is not priority, so its result is not cached. 638 // The file is not priority, so its result is not cached.
667 AnalysisResult result2 = await driver.getResult(a); 639 AnalysisResult result2 = await driver.getResult(a);
668 expect(result2, isNot(same(result1))); 640 expect(result2, isNot(same(result1)));
669 } 641 }
670 642
671 test_changeFile_implicitlyAnalyzed() async { 643 test_changeFile_implicitlyAnalyzed() async {
672 var a = _p('/test/lib/a.dart'); 644 var a = _p('/test/lib/a.dart');
673 var b = _p('/test/lib/b.dart'); 645 var b = _p('/test/lib/b.dart');
674 provider.newFile( 646 provider.newFile(a, r'''
675 a,
676 r'''
677 import 'b.dart'; 647 import 'b.dart';
678 var A = B; 648 var A = B;
679 '''); 649 ''');
680 provider.newFile(b, 'var B = 1;'); 650 provider.newFile(b, 'var B = 1;');
681 651
682 driver.priorityFiles = [a]; 652 driver.priorityFiles = [a];
683 driver.addFile(a); 653 driver.addFile(a);
684 654
685 // We have a result only for "a". 655 // We have a result only for "a".
686 await scheduler.waitForIdle(); 656 await scheduler.waitForIdle();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 await scheduler.waitForIdle(); 696 await scheduler.waitForIdle();
727 expect(allResults, isEmpty); 697 expect(allResults, isEmpty);
728 698
729 // This should not add "b" to the file state. 699 // This should not add "b" to the file state.
730 expect(driver.fsState.knownFilePaths, isNot(contains(b))); 700 expect(driver.fsState.knownFilePaths, isNot(contains(b)));
731 } 701 }
732 702
733 test_changeFile_selfConsistent() async { 703 test_changeFile_selfConsistent() async {
734 var a = _p('/test/lib/a.dart'); 704 var a = _p('/test/lib/a.dart');
735 var b = _p('/test/lib/b.dart'); 705 var b = _p('/test/lib/b.dart');
736 provider.newFile( 706 provider.newFile(a, r'''
737 a,
738 r'''
739 import 'b.dart'; 707 import 'b.dart';
740 var A1 = 1; 708 var A1 = 1;
741 var A2 = B1; 709 var A2 = B1;
742 '''); 710 ''');
743 provider.newFile( 711 provider.newFile(b, r'''
744 b,
745 r'''
746 import 'a.dart'; 712 import 'a.dart';
747 var B1 = A1; 713 var B1 = A1;
748 '''); 714 ''');
749 715
750 driver.priorityFiles = [a, b]; 716 driver.priorityFiles = [a, b];
751 driver.addFile(a); 717 driver.addFile(a);
752 driver.addFile(b); 718 driver.addFile(b);
753 await scheduler.waitForIdle(); 719 await scheduler.waitForIdle();
754 720
755 // We have results for both "a" and "b". 721 // We have results for both "a" and "b".
756 expect(allResults, hasLength(2)); 722 expect(allResults, hasLength(2));
757 { 723 {
758 AnalysisResult ar = allResults.firstWhere((r) => r.path == a); 724 AnalysisResult ar = allResults.firstWhere((r) => r.path == a);
759 expect(_getTopLevelVarType(ar.unit, 'A1'), 'int'); 725 expect(_getTopLevelVarType(ar.unit, 'A1'), 'int');
760 expect(_getTopLevelVarType(ar.unit, 'A2'), 'int'); 726 expect(_getTopLevelVarType(ar.unit, 'A2'), 'int');
761 } 727 }
762 { 728 {
763 AnalysisResult br = allResults.firstWhere((r) => r.path == b); 729 AnalysisResult br = allResults.firstWhere((r) => r.path == b);
764 expect(_getTopLevelVarType(br.unit, 'B1'), 'int'); 730 expect(_getTopLevelVarType(br.unit, 'B1'), 'int');
765 } 731 }
766 732
767 // Clear the results and update "a". 733 // Clear the results and update "a".
768 allResults.clear(); 734 allResults.clear();
769 provider.updateFile( 735 provider.updateFile(a, r'''
770 a,
771 r'''
772 import 'b.dart'; 736 import 'b.dart';
773 var A1 = 1.2; 737 var A1 = 1.2;
774 var A2 = B1; 738 var A2 = B1;
775 '''); 739 ''');
776 driver.changeFile(a); 740 driver.changeFile(a);
777 741
778 // We again get results for both "a" and "b". 742 // We again get results for both "a" and "b".
779 // The results are consistent. 743 // The results are consistent.
780 await scheduler.waitForIdle(); 744 await scheduler.waitForIdle();
781 expect(allResults, hasLength(2)); 745 expect(allResults, hasLength(2));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 import 'foo.dart'; 915 import 'foo.dart';
952 '''); 916 ''');
953 917
954 AnalysisResult result = await driver.getResult(testFile); 918 AnalysisResult result = await driver.getResult(testFile);
955 List<AnalysisError> errors = result.errors; 919 List<AnalysisError> errors = result.errors;
956 expect(errors, hasLength(1)); 920 expect(errors, hasLength(1));
957 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST); 921 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST);
958 } 922 }
959 923
960 test_errors_uriDoesNotExist_import_deferred() async { 924 test_errors_uriDoesNotExist_import_deferred() async {
961 addTestFile( 925 addTestFile(r'''
962 r'''
963 import 'foo.dart' deferred as foo; 926 import 'foo.dart' deferred as foo;
964 main() { 927 main() {
965 foo.loadLibrary(); 928 foo.loadLibrary();
966 } 929 }
967 ''', 930 ''', priority: true);
968 priority: true);
969 931
970 AnalysisResult result = await driver.getResult(testFile); 932 AnalysisResult result = await driver.getResult(testFile);
971 List<AnalysisError> errors = result.errors; 933 List<AnalysisError> errors = result.errors;
972 expect(errors, hasLength(1)); 934 expect(errors, hasLength(1));
973 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST); 935 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST);
974 } 936 }
975 937
976 test_errors_uriDoesNotExist_part() async { 938 test_errors_uriDoesNotExist_part() async {
977 addTestFile(r''' 939 addTestFile(r'''
978 library lib; 940 library lib;
979 part 'foo.dart'; 941 part 'foo.dart';
980 '''); 942 ''');
981 943
982 AnalysisResult result = await driver.getResult(testFile); 944 AnalysisResult result = await driver.getResult(testFile);
983 List<AnalysisError> errors = result.errors; 945 List<AnalysisError> errors = result.errors;
984 expect(errors, hasLength(1)); 946 expect(errors, hasLength(1));
985 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST); 947 expect(errors[0].errorCode, CompileTimeErrorCode.URI_DOES_NOT_EXIST);
986 } 948 }
987 949
988 test_externalSummaries() async { 950 test_externalSummaries() async {
989 var a = _p('/a.dart'); 951 var a = _p('/a.dart');
990 var b = _p('/b.dart'); 952 var b = _p('/b.dart');
991 provider.newFile( 953 provider.newFile(a, r'''
992 a,
993 r'''
994 class A {} 954 class A {}
995 '''); 955 ''');
996 provider.newFile( 956 provider.newFile(b, r'''
997 b,
998 r'''
999 import 'a.dart'; 957 import 'a.dart';
1000 var a = new A(); 958 var a = new A();
1001 '''); 959 ''');
1002 960
1003 // Prepare the store with a.dart and everything it needs. 961 // Prepare the store with a.dart and everything it needs.
1004 SummaryDataStore summaryStore = 962 SummaryDataStore summaryStore =
1005 createAnalysisDriver().test.getSummaryStore(a); 963 createAnalysisDriver().test.getSummaryStore(a);
1006 964
1007 // There are at least a.dart and dart:core libraries. 965 // There are at least a.dart and dart:core libraries.
1008 String aUri = provider.pathContext.toUri(a).toString(); 966 String aUri = provider.pathContext.toUri(a).toString();
(...skipping 11 matching lines...) Expand all
1020 createAnalysisDriver(externalSummaries: summaryStore); 978 createAnalysisDriver(externalSummaries: summaryStore);
1021 AnalysisResult result = await driver.getResult(b); 979 AnalysisResult result = await driver.getResult(b);
1022 expect(result.errors, isEmpty); 980 expect(result.errors, isEmpty);
1023 } 981 }
1024 982
1025 test_generatedFile() async { 983 test_generatedFile() async {
1026 Uri uri = Uri.parse('package:aaa/foo.dart'); 984 Uri uri = Uri.parse('package:aaa/foo.dart');
1027 String templatePath = _p('/aaa/lib/foo.dart'); 985 String templatePath = _p('/aaa/lib/foo.dart');
1028 String generatedPath = _p('/generated/aaa/lib/foo.dart'); 986 String generatedPath = _p('/generated/aaa/lib/foo.dart');
1029 987
1030 provider.newFile( 988 provider.newFile(templatePath, r'''
1031 templatePath,
1032 r'''
1033 a() {} 989 a() {}
1034 b() {} 990 b() {}
1035 '''); 991 ''');
1036 992
1037 provider.newFile( 993 provider.newFile(generatedPath, r'''
1038 generatedPath,
1039 r'''
1040 aaa() {} 994 aaa() {}
1041 bbb() {} 995 bbb() {}
1042 '''); 996 ''');
1043 997
1044 Source generatedSource = new _SourceMock(); 998 Source generatedSource = new _SourceMock();
1045 when(generatedSource.uri).thenReturn(uri); 999 when(generatedSource.uri).thenReturn(uri);
1046 when(generatedSource.fullName).thenReturn(generatedPath); 1000 when(generatedSource.fullName).thenReturn(generatedPath);
1047 1001
1048 when(generatedUriResolver.resolveAbsolute(uri, uri)) 1002 when(generatedUriResolver.resolveAbsolute(uri, uri))
1049 .thenReturn(generatedSource); 1003 .thenReturn(generatedSource);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 1126
1173 AnalysisDriverUnitIndex index = await driver.getIndex(testFile); 1127 AnalysisDriverUnitIndex index = await driver.getIndex(testFile);
1174 1128
1175 int unitId = index.strings.indexOf('package:test/test.dart'); 1129 int unitId = index.strings.indexOf('package:test/test.dart');
1176 int fooId = index.strings.indexOf('foo'); 1130 int fooId = index.strings.indexOf('foo');
1177 expect(unitId, isNonNegative); 1131 expect(unitId, isNonNegative);
1178 expect(fooId, isNonNegative); 1132 expect(fooId, isNonNegative);
1179 } 1133 }
1180 1134
1181 test_getLibraryByUri_external_resynthesize() async { 1135 test_getLibraryByUri_external_resynthesize() async {
1182 provider.newFile( 1136 provider.newFile(testFile, r'''
1183 testFile,
1184 r'''
1185 class Test {} 1137 class Test {}
1186 '''); 1138 ''');
1187 1139
1188 // Prepare the store with package:test/test.dart URI. 1140 // Prepare the store with package:test/test.dart URI.
1189 SummaryDataStore summaryStore = 1141 SummaryDataStore summaryStore =
1190 createAnalysisDriver().test.getSummaryStore(testFile); 1142 createAnalysisDriver().test.getSummaryStore(testFile);
1191 1143
1192 // package:test/test.dart is in the store. 1144 // package:test/test.dart is in the store.
1193 String uri = 'package:test/test.dart'; 1145 String uri = 'package:test/test.dart';
1194 expect(summaryStore.unlinkedMap.keys, contains(uri)); 1146 expect(summaryStore.unlinkedMap.keys, contains(uri));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 1205
1254 // The same result is also received through the stream. 1206 // The same result is also received through the stream.
1255 await scheduler.waitForIdle(); 1207 await scheduler.waitForIdle();
1256 expect(allResults, [result]); 1208 expect(allResults, [result]);
1257 } 1209 }
1258 1210
1259 test_getResult_constants_defaultParameterValue_localFunction() async { 1211 test_getResult_constants_defaultParameterValue_localFunction() async {
1260 var a = _p('/test/bin/a.dart'); 1212 var a = _p('/test/bin/a.dart');
1261 var b = _p('/test/bin/b.dart'); 1213 var b = _p('/test/bin/b.dart');
1262 provider.newFile(a, 'const C = 42;'); 1214 provider.newFile(a, 'const C = 42;');
1263 provider.newFile( 1215 provider.newFile(b, r'''
1264 b,
1265 r'''
1266 import 'a.dart'; 1216 import 'a.dart';
1267 main() { 1217 main() {
1268 foo({int p: C}) {} 1218 foo({int p: C}) {}
1269 foo(); 1219 foo();
1270 } 1220 }
1271 '''); 1221 ''');
1272 driver.addFile(a); 1222 driver.addFile(a);
1273 driver.addFile(b); 1223 driver.addFile(b);
1274 await scheduler.waitForIdle(); 1224 await scheduler.waitForIdle();
1275 1225
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 addTestFile(content, priority: true); 1294 addTestFile(content, priority: true);
1345 1295
1346 var result = await driver.getResult(testFile); 1296 var result = await driver.getResult(testFile);
1347 expect(result.errors, isEmpty); 1297 expect(result.errors, isEmpty);
1348 } 1298 }
1349 1299
1350 test_getResult_importLibrary_thenRemoveIt() async { 1300 test_getResult_importLibrary_thenRemoveIt() async {
1351 var a = _p('/test/lib/a.dart'); 1301 var a = _p('/test/lib/a.dart');
1352 var b = _p('/test/lib/b.dart'); 1302 var b = _p('/test/lib/b.dart');
1353 provider.newFile(a, 'class A {}'); 1303 provider.newFile(a, 'class A {}');
1354 provider.newFile( 1304 provider.newFile(b, r'''
1355 b,
1356 r'''
1357 import 'a.dart'; 1305 import 'a.dart';
1358 class B extends A {} 1306 class B extends A {}
1359 '''); 1307 ''');
1360 1308
1361 driver.addFile(a); 1309 driver.addFile(a);
1362 driver.addFile(b); 1310 driver.addFile(b);
1363 await scheduler.waitForIdle(); 1311 await scheduler.waitForIdle();
1364 1312
1365 // No errors in b.dart 1313 // No errors in b.dart
1366 { 1314 {
(...skipping 19 matching lines...) Expand all
1386 driver.addFile(a); 1334 driver.addFile(a);
1387 1335
1388 // No errors in b.dart again. 1336 // No errors in b.dart again.
1389 { 1337 {
1390 AnalysisResult result = await driver.getResult(b); 1338 AnalysisResult result = await driver.getResult(b);
1391 expect(result.errors, isEmpty); 1339 expect(result.errors, isEmpty);
1392 } 1340 }
1393 } 1341 }
1394 1342
1395 test_getResult_inferTypes_finalField() async { 1343 test_getResult_inferTypes_finalField() async {
1396 addTestFile( 1344 addTestFile(r'''
1397 r'''
1398 class C { 1345 class C {
1399 final f = 42; 1346 final f = 42;
1400 } 1347 }
1401 ''', 1348 ''', priority: true);
1402 priority: true);
1403 await scheduler.waitForIdle(); 1349 await scheduler.waitForIdle();
1404 1350
1405 AnalysisResult result = await driver.getResult(testFile); 1351 AnalysisResult result = await driver.getResult(testFile);
1406 expect(_getClassFieldType(result.unit, 'C', 'f'), 'int'); 1352 expect(_getClassFieldType(result.unit, 'C', 'f'), 'int');
1407 } 1353 }
1408 1354
1409 test_getResult_inferTypes_instanceMethod() async { 1355 test_getResult_inferTypes_instanceMethod() async {
1410 addTestFile( 1356 addTestFile(r'''
1411 r'''
1412 class A { 1357 class A {
1413 int m(double p) => 1; 1358 int m(double p) => 1;
1414 } 1359 }
1415 class B extends A { 1360 class B extends A {
1416 m(double p) => 2; 1361 m(double p) => 2;
1417 } 1362 }
1418 ''', 1363 ''', priority: true);
1419 priority: true);
1420 await scheduler.waitForIdle(); 1364 await scheduler.waitForIdle();
1421 1365
1422 AnalysisResult result = await driver.getResult(testFile); 1366 AnalysisResult result = await driver.getResult(testFile);
1423 expect(_getClassMethodReturnType(result.unit, 'A', 'm'), 'int'); 1367 expect(_getClassMethodReturnType(result.unit, 'A', 'm'), 'int');
1424 expect(_getClassMethodReturnType(result.unit, 'B', 'm'), 'int'); 1368 expect(_getClassMethodReturnType(result.unit, 'B', 'm'), 'int');
1425 } 1369 }
1426 1370
1427 test_getResult_invalid_annotation_functionAsConstructor() async { 1371 test_getResult_invalid_annotation_functionAsConstructor() async {
1428 addTestFile( 1372 addTestFile(r'''
1429 r'''
1430 fff() {} 1373 fff() {}
1431 1374
1432 @fff() 1375 @fff()
1433 class C {} 1376 class C {}
1434 ''', 1377 ''', priority: true);
1435 priority: true);
1436 1378
1437 AnalysisResult result = await driver.getResult(testFile); 1379 AnalysisResult result = await driver.getResult(testFile);
1438 ClassDeclaration c = result.unit.declarations[1] as ClassDeclaration; 1380 ClassDeclaration c = result.unit.declarations[1] as ClassDeclaration;
1439 Annotation a = c.metadata[0]; 1381 Annotation a = c.metadata[0];
1440 expect(a.name.name, 'fff'); 1382 expect(a.name.name, 'fff');
1441 expect(a.name.staticElement, new isInstanceOf<FunctionElement>()); 1383 expect(a.name.staticElement, new isInstanceOf<FunctionElement>());
1442 } 1384 }
1443 1385
1444 test_getResult_invalidUri() async { 1386 test_getResult_invalidUri() async {
1445 String content = r''' 1387 String content = r'''
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 '''; 1460 ''';
1519 addTestFile(content); 1461 addTestFile(content);
1520 await driver.getResult(testFile); 1462 await driver.getResult(testFile);
1521 } 1463 }
1522 1464
1523 test_getResult_mix_fileAndPackageUris() async { 1465 test_getResult_mix_fileAndPackageUris() async {
1524 var a = _p('/test/bin/a.dart'); 1466 var a = _p('/test/bin/a.dart');
1525 var b = _p('/test/bin/b.dart'); 1467 var b = _p('/test/bin/b.dart');
1526 var c = _p('/test/lib/c.dart'); 1468 var c = _p('/test/lib/c.dart');
1527 var d = _p('/test/test/d.dart'); 1469 var d = _p('/test/test/d.dart');
1528 provider.newFile( 1470 provider.newFile(a, r'''
1529 a,
1530 r'''
1531 import 'package:test/c.dart'; 1471 import 'package:test/c.dart';
1532 int x = y; 1472 int x = y;
1533 '''); 1473 ''');
1534 provider.newFile( 1474 provider.newFile(b, r'''
1535 b,
1536 r'''
1537 import '../lib/c.dart'; 1475 import '../lib/c.dart';
1538 int x = y; 1476 int x = y;
1539 '''); 1477 ''');
1540 provider.newFile( 1478 provider.newFile(c, r'''
1541 c,
1542 r'''
1543 import '../test/d.dart'; 1479 import '../test/d.dart';
1544 var y = z; 1480 var y = z;
1545 '''); 1481 ''');
1546 provider.newFile( 1482 provider.newFile(d, r'''
1547 d,
1548 r'''
1549 String z = "string"; 1483 String z = "string";
1550 '''); 1484 ''');
1551 1485
1552 driver.addFile(a); 1486 driver.addFile(a);
1553 driver.addFile(b); 1487 driver.addFile(b);
1554 driver.addFile(c); 1488 driver.addFile(c);
1555 driver.addFile(d); 1489 driver.addFile(d);
1556 1490
1557 // Analysis of my_pkg/bin/a.dart produces no error because 1491 // Analysis of my_pkg/bin/a.dart produces no error because
1558 // file:///my_pkg/bin/a.dart imports package:my_pkg/c.dart, and 1492 // file:///my_pkg/bin/a.dart imports package:my_pkg/c.dart, and
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 addTestFile(content); 1551 addTestFile(content);
1618 // Should not throw exceptions. 1552 // Should not throw exceptions.
1619 await driver.getResult(testFile); 1553 await driver.getResult(testFile);
1620 } 1554 }
1621 1555
1622 test_getResult_sameFile_twoUris() async { 1556 test_getResult_sameFile_twoUris() async {
1623 var a = _p('/test/lib/a.dart'); 1557 var a = _p('/test/lib/a.dart');
1624 var b = _p('/test/lib/b.dart'); 1558 var b = _p('/test/lib/b.dart');
1625 var c = _p('/test/test/c.dart'); 1559 var c = _p('/test/test/c.dart');
1626 provider.newFile(a, 'class A<T> {}'); 1560 provider.newFile(a, 'class A<T> {}');
1627 provider.newFile( 1561 provider.newFile(b, r'''
1628 b,
1629 r'''
1630 import 'a.dart'; 1562 import 'a.dart';
1631 var VB = new A<int>(); 1563 var VB = new A<int>();
1632 '''); 1564 ''');
1633 provider.newFile( 1565 provider.newFile(c, r'''
1634 c,
1635 r'''
1636 import '../lib/a.dart'; 1566 import '../lib/a.dart';
1637 var VC = new A<double>(); 1567 var VC = new A<double>();
1638 '''); 1568 ''');
1639 1569
1640 driver.addFile(a); 1570 driver.addFile(a);
1641 driver.addFile(b); 1571 driver.addFile(b);
1642 await scheduler.waitForIdle(); 1572 await scheduler.waitForIdle();
1643 1573
1644 { 1574 {
1645 AnalysisResult result = await driver.getResult(b); 1575 AnalysisResult result = await driver.getResult(b);
1646 expect(_getImportSource(result.unit, 0).uri.toString(), 1576 expect(_getImportSource(result.unit, 0).uri.toString(),
1647 'package:test/a.dart'); 1577 'package:test/a.dart');
1648 expect(_getTopLevelVarType(result.unit, 'VB'), 'A<int>'); 1578 expect(_getTopLevelVarType(result.unit, 'VB'), 'A<int>');
1649 } 1579 }
1650 1580
1651 { 1581 {
1652 AnalysisResult result = await driver.getResult(c); 1582 AnalysisResult result = await driver.getResult(c);
1653 expect(_getImportSource(result.unit, 0).uri, 1583 expect(_getImportSource(result.unit, 0).uri,
1654 provider.pathContext.toUri(_p('/test/lib/a.dart'))); 1584 provider.pathContext.toUri(_p('/test/lib/a.dart')));
1655 expect(_getTopLevelVarType(result.unit, 'VC'), 'A<double>'); 1585 expect(_getTopLevelVarType(result.unit, 'VC'), 'A<double>');
1656 } 1586 }
1657 } 1587 }
1658 1588
1659 test_getResult_selfConsistent() async { 1589 test_getResult_selfConsistent() async {
1660 var a = _p('/test/lib/a.dart'); 1590 var a = _p('/test/lib/a.dart');
1661 var b = _p('/test/lib/b.dart'); 1591 var b = _p('/test/lib/b.dart');
1662 provider.newFile( 1592 provider.newFile(a, r'''
1663 a,
1664 r'''
1665 import 'b.dart'; 1593 import 'b.dart';
1666 var A1 = 1; 1594 var A1 = 1;
1667 var A2 = B1; 1595 var A2 = B1;
1668 '''); 1596 ''');
1669 provider.newFile( 1597 provider.newFile(b, r'''
1670 b,
1671 r'''
1672 import 'a.dart'; 1598 import 'a.dart';
1673 var B1 = A1; 1599 var B1 = A1;
1674 '''); 1600 ''');
1675 1601
1676 driver.addFile(a); 1602 driver.addFile(a);
1677 driver.addFile(b); 1603 driver.addFile(b);
1678 await scheduler.waitForIdle(); 1604 await scheduler.waitForIdle();
1679 1605
1680 { 1606 {
1681 AnalysisResult result = await driver.getResult(a); 1607 AnalysisResult result = await driver.getResult(a);
1682 expect(_getTopLevelVarType(result.unit, 'A1'), 'int'); 1608 expect(_getTopLevelVarType(result.unit, 'A1'), 'int');
1683 expect(_getTopLevelVarType(result.unit, 'A2'), 'int'); 1609 expect(_getTopLevelVarType(result.unit, 'A2'), 'int');
1684 } 1610 }
1685 1611
1686 // Update "a" so that "A1" is now "double". 1612 // Update "a" so that "A1" is now "double".
1687 // Get result for "a". 1613 // Get result for "a".
1688 // 1614 //
1689 // We get "double" for "A2", even though "A2" has the type from "b". 1615 // We get "double" for "A2", even though "A2" has the type from "b".
1690 // That's because we check for "a" API signature consistency, and because 1616 // That's because we check for "a" API signature consistency, and because
1691 // it has changed, we invalidated the dependency cache, relinked libraries 1617 // it has changed, we invalidated the dependency cache, relinked libraries
1692 // and recomputed types. 1618 // and recomputed types.
1693 provider.updateFile( 1619 provider.updateFile(a, r'''
1694 a,
1695 r'''
1696 import 'b.dart'; 1620 import 'b.dart';
1697 var A1 = 1.2; 1621 var A1 = 1.2;
1698 var A2 = B1; 1622 var A2 = B1;
1699 '''); 1623 ''');
1700 driver.changeFile(a); 1624 driver.changeFile(a);
1701 1625
1702 { 1626 {
1703 AnalysisResult result = await driver.getResult(a); 1627 AnalysisResult result = await driver.getResult(a);
1704 expect(_getTopLevelVarType(result.unit, 'A1'), 'double'); 1628 expect(_getTopLevelVarType(result.unit, 'A1'), 'double');
1705 expect(_getTopLevelVarType(result.unit, 'A2'), 'double'); 1629 expect(_getTopLevelVarType(result.unit, 'A2'), 'double');
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1705
1782 _assertTopLevelDeclarations( 1706 _assertTopLevelDeclarations(
1783 await driver.getTopLevelNameDeclarations('X'), [], []); 1707 await driver.getTopLevelNameDeclarations('X'), [], []);
1784 } 1708 }
1785 1709
1786 test_getTopLevelNameDeclarations_parts() async { 1710 test_getTopLevelNameDeclarations_parts() async {
1787 var a = _p('/test/lib/a.dart'); 1711 var a = _p('/test/lib/a.dart');
1788 var b = _p('/test/lib/b.dart'); 1712 var b = _p('/test/lib/b.dart');
1789 var c = _p('/test/lib/c.dart'); 1713 var c = _p('/test/lib/c.dart');
1790 1714
1791 provider.newFile( 1715 provider.newFile(a, r'''
1792 a,
1793 r'''
1794 library lib; 1716 library lib;
1795 part 'b.dart'; 1717 part 'b.dart';
1796 part 'c.dart'; 1718 part 'c.dart';
1797 class A {} 1719 class A {}
1798 '''); 1720 ''');
1799 provider.newFile(b, 'part of lib; class B {}'); 1721 provider.newFile(b, 'part of lib; class B {}');
1800 provider.newFile(c, 'part of lib; class C {}'); 1722 provider.newFile(c, 'part of lib; class C {}');
1801 1723
1802 driver.addFile(a); 1724 driver.addFile(a);
1803 driver.addFile(b); 1725 driver.addFile(b);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1811
1890 // Request of referenced names is not analysis of a file. 1812 // Request of referenced names is not analysis of a file.
1891 driver.getFilesReferencingName('X'); 1813 driver.getFilesReferencingName('X');
1892 expect(driver.hasFilesToAnalyze, isFalse); 1814 expect(driver.hasFilesToAnalyze, isFalse);
1893 } 1815 }
1894 1816
1895 test_hermetic_modifyLibraryFile_resolvePart() async { 1817 test_hermetic_modifyLibraryFile_resolvePart() async {
1896 var a = _p('/test/lib/a.dart'); 1818 var a = _p('/test/lib/a.dart');
1897 var b = _p('/test/lib/b.dart'); 1819 var b = _p('/test/lib/b.dart');
1898 1820
1899 provider.newFile( 1821 provider.newFile(a, r'''
1900 a,
1901 r'''
1902 library a; 1822 library a;
1903 part 'b.dart'; 1823 part 'b.dart';
1904 class C { 1824 class C {
1905 int foo; 1825 int foo;
1906 } 1826 }
1907 '''); 1827 ''');
1908 provider.newFile( 1828 provider.newFile(b, r'''
1909 b,
1910 r'''
1911 part of a; 1829 part of a;
1912 var c = new C(); 1830 var c = new C();
1913 '''); 1831 ''');
1914 1832
1915 driver.addFile(a); 1833 driver.addFile(a);
1916 driver.addFile(b); 1834 driver.addFile(b);
1917 1835
1918 await driver.getResult(b); 1836 await driver.getResult(b);
1919 1837
1920 // Modify the library, but don't notify the driver. 1838 // Modify the library, but don't notify the driver.
1921 // The driver should use the previous library content and elements. 1839 // The driver should use the previous library content and elements.
1922 provider.newFile( 1840 provider.newFile(a, r'''
1923 a,
1924 r'''
1925 library a; 1841 library a;
1926 part 'b.dart'; 1842 part 'b.dart';
1927 class C { 1843 class C {
1928 int bar; 1844 int bar;
1929 } 1845 }
1930 '''); 1846 ''');
1931 1847
1932 var result = await driver.getResult(b); 1848 var result = await driver.getResult(b);
1933 var c = _getTopLevelVar(result.unit, 'c'); 1849 var c = _getTopLevelVar(result.unit, 'c');
1934 var typeC = c.element.type as InterfaceType; 1850 var typeC = c.element.type as InterfaceType;
(...skipping 19 matching lines...) Expand all
1954 AnalysisResult result = await driver.getResult(a); 1870 AnalysisResult result = await driver.getResult(a);
1955 expect(result.errors, isEmpty); 1871 expect(result.errors, isEmpty);
1956 expect(_getTopLevelVarType(result.unit, 'b'), 'B'); 1872 expect(_getTopLevelVarType(result.unit, 'b'), 'B');
1957 } 1873 }
1958 1874
1959 test_knownFiles() async { 1875 test_knownFiles() async {
1960 var a = _p('/test/lib/a.dart'); 1876 var a = _p('/test/lib/a.dart');
1961 var b = _p('/test/lib/b.dart'); 1877 var b = _p('/test/lib/b.dart');
1962 var c = _p('/test/lib/c.dart'); 1878 var c = _p('/test/lib/c.dart');
1963 1879
1964 provider.newFile( 1880 provider.newFile(a, r'''
1965 a,
1966 r'''
1967 import 'b.dart'; 1881 import 'b.dart';
1968 '''); 1882 ''');
1969 provider.newFile(b, ''); 1883 provider.newFile(b, '');
1970 provider.newFile(c, ''); 1884 provider.newFile(c, '');
1971 1885
1972 driver.addFile(a); 1886 driver.addFile(a);
1973 driver.addFile(c); 1887 driver.addFile(c);
1974 await scheduler.waitForIdle(); 1888 await scheduler.waitForIdle();
1975 1889
1976 expect(driver.knownFiles, contains(a)); 1890 expect(driver.knownFiles, contains(a));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 1942
2029 ParseResult parseResult = await driver.parseFile(p); 1943 ParseResult parseResult = await driver.parseFile(p);
2030 var clazz = parseResult.unit.declarations[0] as ClassDeclaration; 1944 var clazz = parseResult.unit.declarations[0] as ClassDeclaration;
2031 expect(clazz.name.name, 'A2'); 1945 expect(clazz.name.name, 'A2');
2032 } 1946 }
2033 1947
2034 test_part_getErrors_afterLibrary() async { 1948 test_part_getErrors_afterLibrary() async {
2035 var a = _p('/test/lib/a.dart'); 1949 var a = _p('/test/lib/a.dart');
2036 var b = _p('/test/lib/b.dart'); 1950 var b = _p('/test/lib/b.dart');
2037 var c = _p('/test/lib/c.dart'); 1951 var c = _p('/test/lib/c.dart');
2038 provider.newFile( 1952 provider.newFile(a, r'''
2039 a,
2040 r'''
2041 library a; 1953 library a;
2042 import 'b.dart'; 1954 import 'b.dart';
2043 part 'c.dart'; 1955 part 'c.dart';
2044 class A {} 1956 class A {}
2045 var c = new C(); 1957 var c = new C();
2046 '''); 1958 ''');
2047 provider.newFile(b, 'class B {}'); 1959 provider.newFile(b, 'class B {}');
2048 provider.newFile( 1960 provider.newFile(c, r'''
2049 c,
2050 r'''
2051 part of a; 1961 part of a;
2052 class C {} 1962 class C {}
2053 var a = new A(); 1963 var a = new A();
2054 var b = new B(); 1964 var b = new B();
2055 '''); 1965 ''');
2056 1966
2057 driver.addFile(a); 1967 driver.addFile(a);
2058 driver.addFile(b); 1968 driver.addFile(b);
2059 driver.addFile(c); 1969 driver.addFile(c);
2060 1970
2061 // Process a.dart so that we know that it's a library for c.dart later. 1971 // Process a.dart so that we know that it's a library for c.dart later.
2062 { 1972 {
2063 ErrorsResult result = await driver.getErrors(a); 1973 ErrorsResult result = await driver.getErrors(a);
2064 expect(result.errors, isEmpty); 1974 expect(result.errors, isEmpty);
2065 } 1975 }
2066 1976
2067 // c.dart does not have errors in the context of a.dart 1977 // c.dart does not have errors in the context of a.dart
2068 { 1978 {
2069 ErrorsResult result = await driver.getErrors(c); 1979 ErrorsResult result = await driver.getErrors(c);
2070 expect(result.errors, isEmpty); 1980 expect(result.errors, isEmpty);
2071 } 1981 }
2072 } 1982 }
2073 1983
2074 test_part_getErrors_beforeLibrary() async { 1984 test_part_getErrors_beforeLibrary() async {
2075 var a = _p('/test/lib/a.dart'); 1985 var a = _p('/test/lib/a.dart');
2076 var b = _p('/test/lib/b.dart'); 1986 var b = _p('/test/lib/b.dart');
2077 var c = _p('/test/lib/c.dart'); 1987 var c = _p('/test/lib/c.dart');
2078 provider.newFile( 1988 provider.newFile(a, r'''
2079 a,
2080 r'''
2081 library a; 1989 library a;
2082 import 'b.dart'; 1990 import 'b.dart';
2083 part 'c.dart'; 1991 part 'c.dart';
2084 class A {} 1992 class A {}
2085 var c = new C(); 1993 var c = new C();
2086 '''); 1994 ''');
2087 provider.newFile(b, 'class B {}'); 1995 provider.newFile(b, 'class B {}');
2088 provider.newFile( 1996 provider.newFile(c, r'''
2089 c,
2090 r'''
2091 part of a; 1997 part of a;
2092 class C {} 1998 class C {}
2093 var a = new A(); 1999 var a = new A();
2094 var b = new B(); 2000 var b = new B();
2095 '''); 2001 ''');
2096 2002
2097 driver.addFile(a); 2003 driver.addFile(a);
2098 driver.addFile(b); 2004 driver.addFile(b);
2099 driver.addFile(c); 2005 driver.addFile(c);
2100 2006
2101 // c.dart is resolve in the context of a.dart, so have no errors 2007 // c.dart is resolve in the context of a.dart, so have no errors
2102 { 2008 {
2103 ErrorsResult result = await driver.getErrors(c); 2009 ErrorsResult result = await driver.getErrors(c);
2104 expect(result.errors, isEmpty); 2010 expect(result.errors, isEmpty);
2105 } 2011 }
2106 } 2012 }
2107 2013
2108 test_part_getResult_afterLibrary() async { 2014 test_part_getResult_afterLibrary() async {
2109 var a = _p('/test/lib/a.dart'); 2015 var a = _p('/test/lib/a.dart');
2110 var b = _p('/test/lib/b.dart'); 2016 var b = _p('/test/lib/b.dart');
2111 var c = _p('/test/lib/c.dart'); 2017 var c = _p('/test/lib/c.dart');
2112 provider.newFile( 2018 provider.newFile(a, r'''
2113 a,
2114 r'''
2115 library a; 2019 library a;
2116 import 'b.dart'; 2020 import 'b.dart';
2117 part 'c.dart'; 2021 part 'c.dart';
2118 class A {} 2022 class A {}
2119 var c = new C(); 2023 var c = new C();
2120 '''); 2024 ''');
2121 provider.newFile(b, 'class B {}'); 2025 provider.newFile(b, 'class B {}');
2122 provider.newFile( 2026 provider.newFile(c, r'''
2123 c,
2124 r'''
2125 part of a; 2027 part of a;
2126 class C {} 2028 class C {}
2127 var a = new A(); 2029 var a = new A();
2128 var b = new B(); 2030 var b = new B();
2129 '''); 2031 ''');
2130 2032
2131 driver.addFile(a); 2033 driver.addFile(a);
2132 driver.addFile(b); 2034 driver.addFile(b);
2133 driver.addFile(c); 2035 driver.addFile(c);
2134 2036
(...skipping 10 matching lines...) Expand all
2145 expect(result.errors, isEmpty); 2047 expect(result.errors, isEmpty);
2146 expect(_getTopLevelVarType(result.unit, 'a'), 'A'); 2048 expect(_getTopLevelVarType(result.unit, 'a'), 'A');
2147 expect(_getTopLevelVarType(result.unit, 'b'), 'B'); 2049 expect(_getTopLevelVarType(result.unit, 'b'), 'B');
2148 } 2050 }
2149 } 2051 }
2150 2052
2151 test_part_getResult_beforeLibrary() async { 2053 test_part_getResult_beforeLibrary() async {
2152 var a = _p('/test/lib/a.dart'); 2054 var a = _p('/test/lib/a.dart');
2153 var b = _p('/test/lib/b.dart'); 2055 var b = _p('/test/lib/b.dart');
2154 var c = _p('/test/lib/c.dart'); 2056 var c = _p('/test/lib/c.dart');
2155 provider.newFile( 2057 provider.newFile(a, r'''
2156 a,
2157 r'''
2158 library a; 2058 library a;
2159 import 'b.dart'; 2059 import 'b.dart';
2160 part 'c.dart'; 2060 part 'c.dart';
2161 class A {} 2061 class A {}
2162 var c = new C(); 2062 var c = new C();
2163 '''); 2063 ''');
2164 provider.newFile(b, 'class B {}'); 2064 provider.newFile(b, 'class B {}');
2165 provider.newFile( 2065 provider.newFile(c, r'''
2166 c,
2167 r'''
2168 part of a; 2066 part of a;
2169 class C {} 2067 class C {}
2170 var a = new A(); 2068 var a = new A();
2171 var b = new B(); 2069 var b = new B();
2172 '''); 2070 ''');
2173 2071
2174 driver.addFile(a); 2072 driver.addFile(a);
2175 driver.addFile(b); 2073 driver.addFile(b);
2176 driver.addFile(c); 2074 driver.addFile(c);
2177 2075
2178 // b.dart will be analyzed after a.dart is analyzed. 2076 // b.dart will be analyzed after a.dart is analyzed.
2179 // So, A and B references are resolved. 2077 // So, A and B references are resolved.
2180 AnalysisResult result = await driver.getResult(c); 2078 AnalysisResult result = await driver.getResult(c);
2181 expect(result.errors, isEmpty); 2079 expect(result.errors, isEmpty);
2182 expect(_getTopLevelVarType(result.unit, 'a'), 'A'); 2080 expect(_getTopLevelVarType(result.unit, 'a'), 'A');
2183 expect(_getTopLevelVarType(result.unit, 'b'), 'B'); 2081 expect(_getTopLevelVarType(result.unit, 'b'), 'B');
2184 } 2082 }
2185 2083
2186 test_part_getResult_noLibrary() async { 2084 test_part_getResult_noLibrary() async {
2187 var c = _p('/test/lib/c.dart'); 2085 var c = _p('/test/lib/c.dart');
2188 provider.newFile( 2086 provider.newFile(c, r'''
2189 c,
2190 r'''
2191 part of a; 2087 part of a;
2192 class C {} 2088 class C {}
2193 var a = new A(); 2089 var a = new A();
2194 var b = new B(); 2090 var b = new B();
2195 '''); 2091 ''');
2196 2092
2197 driver.addFile(c); 2093 driver.addFile(c);
2198 2094
2199 // There is no library which c.dart is a part of, so it has unresolved 2095 // There is no library which c.dart is a part of, so it has unresolved
2200 // A and B references. 2096 // A and B references.
2201 AnalysisResult result = await driver.getResult(c); 2097 AnalysisResult result = await driver.getResult(c);
2202 expect(result.errors, isNotEmpty); 2098 expect(result.errors, isNotEmpty);
2203 expect(result.unit, isNotNull); 2099 expect(result.unit, isNotNull);
2204 } 2100 }
2205 2101
2206 test_part_results_afterLibrary() async { 2102 test_part_results_afterLibrary() async {
2207 var a = _p('/test/lib/a.dart'); 2103 var a = _p('/test/lib/a.dart');
2208 var b = _p('/test/lib/b.dart'); 2104 var b = _p('/test/lib/b.dart');
2209 var c = _p('/test/lib/c.dart'); 2105 var c = _p('/test/lib/c.dart');
2210 provider.newFile( 2106 provider.newFile(a, r'''
2211 a,
2212 r'''
2213 library a; 2107 library a;
2214 import 'b.dart'; 2108 import 'b.dart';
2215 part 'c.dart'; 2109 part 'c.dart';
2216 class A {} 2110 class A {}
2217 var c = new C(); 2111 var c = new C();
2218 '''); 2112 ''');
2219 provider.newFile(b, 'class B {}'); 2113 provider.newFile(b, 'class B {}');
2220 provider.newFile( 2114 provider.newFile(c, r'''
2221 c,
2222 r'''
2223 part of a; 2115 part of a;
2224 class C {} 2116 class C {}
2225 var a = new A(); 2117 var a = new A();
2226 var b = new B(); 2118 var b = new B();
2227 '''); 2119 ''');
2228 2120
2229 // The order is important for creating the test case. 2121 // The order is important for creating the test case.
2230 driver.addFile(a); 2122 driver.addFile(a);
2231 driver.addFile(b); 2123 driver.addFile(b);
2232 driver.addFile(c); 2124 driver.addFile(c);
(...skipping 19 matching lines...) Expand all
2252 AnalysisResult result = allResults.lastWhere((r) => r.path == c); 2144 AnalysisResult result = allResults.lastWhere((r) => r.path == c);
2253 expect(result.errors, isNotEmpty); 2145 expect(result.errors, isNotEmpty);
2254 expect(result.unit, isNull); 2146 expect(result.unit, isNull);
2255 } 2147 }
2256 } 2148 }
2257 2149
2258 test_part_results_beforeLibrary() async { 2150 test_part_results_beforeLibrary() async {
2259 var a = _p('/test/lib/a.dart'); 2151 var a = _p('/test/lib/a.dart');
2260 var b = _p('/test/lib/b.dart'); 2152 var b = _p('/test/lib/b.dart');
2261 var c = _p('/test/lib/c.dart'); 2153 var c = _p('/test/lib/c.dart');
2262 provider.newFile( 2154 provider.newFile(a, r'''
2263 a,
2264 r'''
2265 library a; 2155 library a;
2266 import 'b.dart'; 2156 import 'b.dart';
2267 part 'c.dart'; 2157 part 'c.dart';
2268 class A {} 2158 class A {}
2269 var c = new C(); 2159 var c = new C();
2270 '''); 2160 ''');
2271 provider.newFile(b, 'class B {}'); 2161 provider.newFile(b, 'class B {}');
2272 provider.newFile( 2162 provider.newFile(c, r'''
2273 c,
2274 r'''
2275 part of a; 2163 part of a;
2276 class C {} 2164 class C {}
2277 var a = new A(); 2165 var a = new A();
2278 var b = new B(); 2166 var b = new B();
2279 '''); 2167 ''');
2280 2168
2281 // The order is important for creating the test case. 2169 // The order is important for creating the test case.
2282 driver.addFile(c); 2170 driver.addFile(c);
2283 driver.addFile(a); 2171 driver.addFile(a);
2284 driver.addFile(b); 2172 driver.addFile(b);
2285 2173
2286 await scheduler.waitForIdle(); 2174 await scheduler.waitForIdle();
2287 2175
2288 // c.dart was added before a.dart, so we attempt to analyze it before 2176 // c.dart was added before a.dart, so we attempt to analyze it before
2289 // a.dart, but we cannot find the library for it, so we delay analysis 2177 // a.dart, but we cannot find the library for it, so we delay analysis
2290 // until all other files are analyzed, including a.dart, after which we 2178 // until all other files are analyzed, including a.dart, after which we
2291 // analyze the delayed parts. 2179 // analyze the delayed parts.
2292 AnalysisResult result = allResults.lastWhere((r) => r.path == c); 2180 AnalysisResult result = allResults.lastWhere((r) => r.path == c);
2293 expect(result.errors, isEmpty); 2181 expect(result.errors, isEmpty);
2294 expect(result.unit, isNull); 2182 expect(result.unit, isNull);
2295 } 2183 }
2296 2184
2297 test_part_results_noLibrary() async { 2185 test_part_results_noLibrary() async {
2298 var c = _p('/test/lib/c.dart'); 2186 var c = _p('/test/lib/c.dart');
2299 provider.newFile( 2187 provider.newFile(c, r'''
2300 c,
2301 r'''
2302 part of a; 2188 part of a;
2303 class C {} 2189 class C {}
2304 var a = new A(); 2190 var a = new A();
2305 var b = new B(); 2191 var b = new B();
2306 '''); 2192 ''');
2307 2193
2308 driver.addFile(c); 2194 driver.addFile(c);
2309 2195
2310 await scheduler.waitForIdle(); 2196 await scheduler.waitForIdle();
2311 2197
2312 // There is no library which c.dart is a part of, so it has unresolved 2198 // There is no library which c.dart is a part of, so it has unresolved
2313 // A and B references. 2199 // A and B references.
2314 AnalysisResult result = allResults.lastWhere((r) => r.path == c); 2200 AnalysisResult result = allResults.lastWhere((r) => r.path == c);
2315 expect(result.errors, isNotEmpty); 2201 expect(result.errors, isNotEmpty);
2316 expect(result.unit, isNull); 2202 expect(result.unit, isNull);
2317 } 2203 }
2318 2204
2319 test_part_results_priority_beforeLibrary() async { 2205 test_part_results_priority_beforeLibrary() async {
2320 var a = _p('/test/lib/a.dart'); 2206 var a = _p('/test/lib/a.dart');
2321 var b = _p('/test/lib/b.dart'); 2207 var b = _p('/test/lib/b.dart');
2322 var c = _p('/test/lib/c.dart'); 2208 var c = _p('/test/lib/c.dart');
2323 provider.newFile( 2209 provider.newFile(a, r'''
2324 a,
2325 r'''
2326 library a; 2210 library a;
2327 import 'b.dart'; 2211 import 'b.dart';
2328 part 'c.dart'; 2212 part 'c.dart';
2329 class A {} 2213 class A {}
2330 var c = new C(); 2214 var c = new C();
2331 '''); 2215 ''');
2332 provider.newFile(b, 'class B {}'); 2216 provider.newFile(b, 'class B {}');
2333 provider.newFile( 2217 provider.newFile(c, r'''
2334 c,
2335 r'''
2336 part of a; 2218 part of a;
2337 class C {} 2219 class C {}
2338 var a = new A(); 2220 var a = new A();
2339 var b = new B(); 2221 var b = new B();
2340 '''); 2222 ''');
2341 2223
2342 // The order is important for creating the test case. 2224 // The order is important for creating the test case.
2343 driver.priorityFiles = [c]; 2225 driver.priorityFiles = [c];
2344 driver.addFile(c); 2226 driver.addFile(c);
2345 driver.addFile(a); 2227 driver.addFile(a);
2346 driver.addFile(b); 2228 driver.addFile(b);
2347 2229
2348 await scheduler.waitForIdle(); 2230 await scheduler.waitForIdle();
2349 2231
2350 // c.dart was added before a.dart, so we attempt to analyze it before 2232 // c.dart was added before a.dart, so we attempt to analyze it before
2351 // a.dart, but we cannot find the library for it, so we delay analysis 2233 // a.dart, but we cannot find the library for it, so we delay analysis
2352 // until all other files are analyzed, including a.dart, after which we 2234 // until all other files are analyzed, including a.dart, after which we
2353 // analyze the delayed parts. 2235 // analyze the delayed parts.
2354 AnalysisResult result = allResults.lastWhere((r) => r.path == c); 2236 AnalysisResult result = allResults.lastWhere((r) => r.path == c);
2355 expect(result.errors, isEmpty); 2237 expect(result.errors, isEmpty);
2356 expect(result.unit, isNotNull); 2238 expect(result.unit, isNotNull);
2357 } 2239 }
2358 2240
2359 test_removeFile_changeFile_implicitlyAnalyzed() async { 2241 test_removeFile_changeFile_implicitlyAnalyzed() async {
2360 var a = _p('/test/lib/a.dart'); 2242 var a = _p('/test/lib/a.dart');
2361 var b = _p('/test/lib/b.dart'); 2243 var b = _p('/test/lib/b.dart');
2362 provider.newFile( 2244 provider.newFile(a, r'''
2363 a,
2364 r'''
2365 import 'b.dart'; 2245 import 'b.dart';
2366 var A = B; 2246 var A = B;
2367 '''); 2247 ''');
2368 provider.newFile(b, 'var B = 1;'); 2248 provider.newFile(b, 'var B = 1;');
2369 2249
2370 driver.priorityFiles = [a, b]; 2250 driver.priorityFiles = [a, b];
2371 driver.addFile(a); 2251 driver.addFile(a);
2372 driver.addFile(b); 2252 driver.addFile(b);
2373 2253
2374 // We have results for both "a" and "b". 2254 // We have results for both "a" and "b".
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 allResults.clear(); 2322 allResults.clear();
2443 } 2323 }
2444 2324
2445 test_results_order() async { 2325 test_results_order() async {
2446 var a = _p('/test/lib/a.dart'); 2326 var a = _p('/test/lib/a.dart');
2447 var b = _p('/test/lib/b.dart'); 2327 var b = _p('/test/lib/b.dart');
2448 var c = _p('/test/lib/c.dart'); 2328 var c = _p('/test/lib/c.dart');
2449 var d = _p('/test/lib/d.dart'); 2329 var d = _p('/test/lib/d.dart');
2450 var e = _p('/test/lib/e.dart'); 2330 var e = _p('/test/lib/e.dart');
2451 var f = _p('/test/lib/f.dart'); 2331 var f = _p('/test/lib/f.dart');
2452 provider.newFile( 2332 provider.newFile(a, r'''
2453 a,
2454 r'''
2455 import 'd.dart'; 2333 import 'd.dart';
2456 '''); 2334 ''');
2457 provider.newFile(b, ''); 2335 provider.newFile(b, '');
2458 provider.newFile( 2336 provider.newFile(c, r'''
2459 c,
2460 r'''
2461 import 'd.dart'; 2337 import 'd.dart';
2462 '''); 2338 ''');
2463 provider.newFile( 2339 provider.newFile(d, r'''
2464 d,
2465 r'''
2466 import 'b.dart'; 2340 import 'b.dart';
2467 '''); 2341 ''');
2468 provider.newFile( 2342 provider.newFile(e, r'''
2469 e,
2470 r'''
2471 export 'b.dart'; 2343 export 'b.dart';
2472 '''); 2344 ''');
2473 provider.newFile( 2345 provider.newFile(f, r'''
2474 f,
2475 r'''
2476 import 'e.dart'; 2346 import 'e.dart';
2477 class F extends X {} 2347 class F extends X {}
2478 '''); 2348 ''');
2479 2349
2480 driver.addFile(a); 2350 driver.addFile(a);
2481 driver.addFile(b); 2351 driver.addFile(b);
2482 driver.addFile(c); 2352 driver.addFile(c);
2483 driver.addFile(d); 2353 driver.addFile(d);
2484 driver.addFile(e); 2354 driver.addFile(e);
2485 driver.addFile(f); 2355 driver.addFile(f);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2786 expect(() { 2656 expect(() {
2787 driver.changeFile(path); 2657 driver.changeFile(path);
2788 }, throwsStateError); 2658 }, throwsStateError);
2789 } 2659 }
2790 2660
2791 test_getResult_libraryUnits() async { 2661 test_getResult_libraryUnits() async {
2792 var lib = _p('/lib.dart'); 2662 var lib = _p('/lib.dart');
2793 var part1 = _p('/part1.dart'); 2663 var part1 = _p('/part1.dart');
2794 var part2 = _p('/part2.dart'); 2664 var part2 = _p('/part2.dart');
2795 2665
2796 provider.newFile( 2666 provider.newFile(lib, r'''
2797 lib,
2798 r'''
2799 library test; 2667 library test;
2800 part 'part1.dart'; 2668 part 'part1.dart';
2801 part 'part2.dart'; 2669 part 'part2.dart';
2802 '''); 2670 ''');
2803 provider.newFile(part1, 'part of test; class A {}'); 2671 provider.newFile(part1, 'part of test; class A {}');
2804 provider.newFile(part2, 'part of test; class B {}'); 2672 provider.newFile(part2, 'part of test; class B {}');
2805 2673
2806 driver.addFile(lib); 2674 driver.addFile(lib);
2807 driver.addFile(part1); 2675 driver.addFile(part1);
2808 driver.addFile(part2); 2676 driver.addFile(part2);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2857 var path = _p('/test.dart'); 2725 var path = _p('/test.dart');
2858 expect(() { 2726 expect(() {
2859 driver.removeFile(path); 2727 driver.removeFile(path);
2860 }, throwsStateError); 2728 }, throwsStateError);
2861 } 2729 }
2862 2730
2863 String _p(String path) => provider.convertPath(path); 2731 String _p(String path) => provider.convertPath(path);
2864 } 2732 }
2865 2733
2866 class _SourceMock extends TypedMock implements Source {} 2734 class _SourceMock extends TypedMock implements Source {}
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/mock_sdk.dart ('k') | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698