| OLD | NEW |
| 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 analyzer.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 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/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); | 145 isInstanceOf isVerifyUnitTask = new isInstanceOf<VerifyUnitTask>(); |
| 146 | 146 |
| 147 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); | 147 final LintCode _testLintCode = new LintCode('test lint', 'test lint code'); |
| 148 | 148 |
| 149 @reflectiveTest | 149 @reflectiveTest |
| 150 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { | 150 class BuildCompilationUnitElementTaskTest extends _AbstractDartTaskTest { |
| 151 Source source; | 151 Source source; |
| 152 LibrarySpecificUnit target; | 152 LibrarySpecificUnit target; |
| 153 | 153 |
| 154 test_created_resolved_unit() { | 154 test_created_resolved_unit() { |
| 155 Source source = newSource( | 155 Source source = newSource('/test.dart', r''' |
| 156 '/test.dart', | |
| 157 r''' | |
| 158 library lib; | 156 library lib; |
| 159 class A {} | 157 class A {} |
| 160 '''); | 158 '''); |
| 161 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 159 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 162 computeResult(target, RESOLVED_UNIT1); | 160 computeResult(target, RESOLVED_UNIT1); |
| 163 expect(outputs[RESOLVED_UNIT1], isNotNull); | 161 expect(outputs[RESOLVED_UNIT1], isNotNull); |
| 164 expect(outputs[CREATED_RESOLVED_UNIT1], isTrue); | 162 expect(outputs[CREATED_RESOLVED_UNIT1], isTrue); |
| 165 } | 163 } |
| 166 | 164 |
| 167 test_perform_find_constants() { | 165 test_perform_find_constants() { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 expect(combinator.hiddenNames, ['C', 'D']); | 353 expect(combinator.hiddenNames, ['C', 'D']); |
| 356 } | 354 } |
| 357 } | 355 } |
| 358 | 356 |
| 359 test_perform_configurations_export() { | 357 test_perform_configurations_export() { |
| 360 context.declaredVariables.define('dart.library.io', 'true'); | 358 context.declaredVariables.define('dart.library.io', 'true'); |
| 361 context.declaredVariables.define('dart.library.html', 'true'); | 359 context.declaredVariables.define('dart.library.html', 'true'); |
| 362 newSource('/foo.dart', ''); | 360 newSource('/foo.dart', ''); |
| 363 var foo_io = newSource('/foo_io.dart', ''); | 361 var foo_io = newSource('/foo_io.dart', ''); |
| 364 newSource('/foo_html.dart', ''); | 362 newSource('/foo_html.dart', ''); |
| 365 var testSource = newSource( | 363 var testSource = newSource('/test.dart', r''' |
| 366 '/test.dart', | |
| 367 r''' | |
| 368 export 'foo.dart' | 364 export 'foo.dart' |
| 369 if (dart.library.io) 'foo_io.dart' | 365 if (dart.library.io) 'foo_io.dart' |
| 370 if (dart.library.html) 'foo_html.dart'; | 366 if (dart.library.html) 'foo_html.dart'; |
| 371 '''); | 367 '''); |
| 372 // Perform the task. | 368 // Perform the task. |
| 373 computeResult(testSource, LIBRARY_ELEMENT2, | 369 computeResult(testSource, LIBRARY_ELEMENT2, |
| 374 matcher: isBuildDirectiveElementsTask); | 370 matcher: isBuildDirectiveElementsTask); |
| 375 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; | 371 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
| 376 // Validate the export element. | 372 // Validate the export element. |
| 377 ExportElement export = testLibrary.exports[0]; | 373 ExportElement export = testLibrary.exports[0]; |
| 378 expect(export.exportedLibrary.source, foo_io); | 374 expect(export.exportedLibrary.source, foo_io); |
| 379 expect(export.uri, 'foo_io.dart'); | 375 expect(export.uri, 'foo_io.dart'); |
| 380 } | 376 } |
| 381 | 377 |
| 382 test_perform_configurations_import() { | 378 test_perform_configurations_import() { |
| 383 context.declaredVariables.define('dart.library.io', 'true'); | 379 context.declaredVariables.define('dart.library.io', 'true'); |
| 384 context.declaredVariables.define('dart.library.html', 'true'); | 380 context.declaredVariables.define('dart.library.html', 'true'); |
| 385 newSource('/foo.dart', ''); | 381 newSource('/foo.dart', ''); |
| 386 var foo_io = newSource('/foo_io.dart', ''); | 382 var foo_io = newSource('/foo_io.dart', ''); |
| 387 newSource('/foo_html.dart', ''); | 383 newSource('/foo_html.dart', ''); |
| 388 var testSource = newSource( | 384 var testSource = newSource('/test.dart', r''' |
| 389 '/test.dart', | |
| 390 r''' | |
| 391 import 'foo.dart' | 385 import 'foo.dart' |
| 392 if (dart.library.io) 'foo_io.dart' | 386 if (dart.library.io) 'foo_io.dart' |
| 393 if (dart.library.html) 'foo_html.dart'; | 387 if (dart.library.html) 'foo_html.dart'; |
| 394 '''); | 388 '''); |
| 395 // Perform the task. | 389 // Perform the task. |
| 396 computeResult(testSource, LIBRARY_ELEMENT2, | 390 computeResult(testSource, LIBRARY_ELEMENT2, |
| 397 matcher: isBuildDirectiveElementsTask); | 391 matcher: isBuildDirectiveElementsTask); |
| 398 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; | 392 LibraryElement testLibrary = outputs[LIBRARY_ELEMENT2]; |
| 399 // Validate the import element. | 393 // Validate the import element. |
| 400 ImportElement import = testLibrary.imports[0]; | 394 ImportElement import = testLibrary.imports[0]; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 592 |
| 599 _getImportLibraryInput(Source source) { | 593 _getImportLibraryInput(Source source) { |
| 600 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; | 594 var key = BuildDirectiveElementsTask.IMPORTS_LIBRARY_ELEMENT_INPUT_NAME; |
| 601 return task.inputs[key][source]; | 595 return task.inputs[key][source]; |
| 602 } | 596 } |
| 603 } | 597 } |
| 604 | 598 |
| 605 @reflectiveTest | 599 @reflectiveTest |
| 606 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { | 600 class BuildEnumMemberElementsTaskTest extends _AbstractDartTaskTest { |
| 607 test_created_resolved_unit() { | 601 test_created_resolved_unit() { |
| 608 Source source = newSource( | 602 Source source = newSource('/test.dart', r''' |
| 609 '/test.dart', | |
| 610 r''' | |
| 611 library lib; | 603 library lib; |
| 612 class A {} | 604 class A {} |
| 613 '''); | 605 '''); |
| 614 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 606 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 615 computeResult(target, RESOLVED_UNIT3); | 607 computeResult(target, RESOLVED_UNIT3); |
| 616 expect(outputs[RESOLVED_UNIT3], isNotNull); | 608 expect(outputs[RESOLVED_UNIT3], isNotNull); |
| 617 expect(outputs[CREATED_RESOLVED_UNIT3], isTrue); | 609 expect(outputs[CREATED_RESOLVED_UNIT3], isTrue); |
| 618 } | 610 } |
| 619 | 611 |
| 620 test_perform() { | 612 test_perform() { |
| 621 Source source = newSource( | 613 Source source = newSource('/test.dart', ''' |
| 622 '/test.dart', | |
| 623 ''' | |
| 624 enum MyEnum { | 614 enum MyEnum { |
| 625 A, B | 615 A, B |
| 626 } | 616 } |
| 627 '''); | 617 '''); |
| 628 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT3, | 618 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT3, |
| 629 matcher: isBuildEnumMemberElementsTask); | 619 matcher: isBuildEnumMemberElementsTask); |
| 630 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 620 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 631 // validate Element | 621 // validate Element |
| 632 ClassElement enumElement = | 622 ClassElement enumElement = |
| 633 resolutionMap.elementDeclaredByCompilationUnit(unit).getEnum('MyEnum'); | 623 resolutionMap.elementDeclaredByCompilationUnit(unit).getEnum('MyEnum'); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 PropertyAccessorElement getter = field.getter; | 666 PropertyAccessorElement getter = field.getter; |
| 677 expect(getter, isNotNull); | 667 expect(getter, isNotNull); |
| 678 expect(getter.variable, same(field)); | 668 expect(getter.variable, same(field)); |
| 679 expect(getter.type, isNotNull); | 669 expect(getter.type, isNotNull); |
| 680 } | 670 } |
| 681 } | 671 } |
| 682 | 672 |
| 683 @reflectiveTest | 673 @reflectiveTest |
| 684 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { | 674 class BuildExportNamespaceTaskTest extends _AbstractDartTaskTest { |
| 685 test_perform_entryPoint() { | 675 test_perform_entryPoint() { |
| 686 Source sourceA = newSource( | 676 Source sourceA = newSource('/a.dart', ''' |
| 687 '/a.dart', | |
| 688 ''' | |
| 689 library lib_a; | 677 library lib_a; |
| 690 export 'b.dart'; | 678 export 'b.dart'; |
| 691 '''); | 679 '''); |
| 692 Source sourceB = newSource( | 680 Source sourceB = newSource('/b.dart', ''' |
| 693 '/b.dart', | |
| 694 ''' | |
| 695 library lib_b; | 681 library lib_b; |
| 696 main() {} | 682 main() {} |
| 697 '''); | 683 '''); |
| 698 computeResult(sourceA, LIBRARY_ELEMENT4, | 684 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 699 matcher: isBuildExportNamespaceTask); | 685 matcher: isBuildExportNamespaceTask); |
| 700 // validate | 686 // validate |
| 701 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 687 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 702 FunctionElement entryPoint = library.entryPoint; | 688 FunctionElement entryPoint = library.entryPoint; |
| 703 expect(entryPoint, isNotNull); | 689 expect(entryPoint, isNotNull); |
| 704 expect(entryPoint.source, sourceB); | 690 expect(entryPoint.source, sourceB); |
| 705 } | 691 } |
| 706 | 692 |
| 707 test_perform_hideCombinator() { | 693 test_perform_hideCombinator() { |
| 708 Source sourceA = newSource( | 694 Source sourceA = newSource('/a.dart', ''' |
| 709 '/a.dart', | |
| 710 ''' | |
| 711 library lib_a; | 695 library lib_a; |
| 712 export 'b.dart' hide B1; | 696 export 'b.dart' hide B1; |
| 713 class A1 {} | 697 class A1 {} |
| 714 class A2 {} | 698 class A2 {} |
| 715 class _A3 {} | 699 class _A3 {} |
| 716 '''); | 700 '''); |
| 717 newSource( | 701 newSource('/b.dart', ''' |
| 718 '/b.dart', | |
| 719 ''' | |
| 720 library lib_b; | 702 library lib_b; |
| 721 class B1 {} | 703 class B1 {} |
| 722 class B2 {} | 704 class B2 {} |
| 723 class B3 {} | 705 class B3 {} |
| 724 class _B4 {} | 706 class _B4 {} |
| 725 '''); | 707 '''); |
| 726 newSource( | 708 newSource('/c.dart', ''' |
| 727 '/c.dart', | |
| 728 ''' | |
| 729 library lib_c; | 709 library lib_c; |
| 730 class C1 {} | 710 class C1 {} |
| 731 class C2 {} | 711 class C2 {} |
| 732 class C3 {} | 712 class C3 {} |
| 733 '''); | 713 '''); |
| 734 computeResult(sourceA, LIBRARY_ELEMENT4, | 714 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 735 matcher: isBuildExportNamespaceTask); | 715 matcher: isBuildExportNamespaceTask); |
| 736 // validate | 716 // validate |
| 737 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 717 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 738 Namespace namespace = library.exportNamespace; | 718 Namespace namespace = library.exportNamespace; |
| 739 Iterable<String> definedKeys = namespace.definedNames.keys; | 719 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 740 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); | 720 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B2', 'B3'])); |
| 741 } | 721 } |
| 742 | 722 |
| 743 test_perform_showCombinator() { | 723 test_perform_showCombinator() { |
| 744 Source sourceA = newSource( | 724 Source sourceA = newSource('/a.dart', ''' |
| 745 '/a.dart', | |
| 746 ''' | |
| 747 library lib_a; | 725 library lib_a; |
| 748 export 'b.dart' show B1; | 726 export 'b.dart' show B1; |
| 749 class A1 {} | 727 class A1 {} |
| 750 class A2 {} | 728 class A2 {} |
| 751 class _A3 {} | 729 class _A3 {} |
| 752 '''); | 730 '''); |
| 753 newSource( | 731 newSource('/b.dart', ''' |
| 754 '/b.dart', | |
| 755 ''' | |
| 756 library lib_b; | 732 library lib_b; |
| 757 class B1 {} | 733 class B1 {} |
| 758 class B2 {} | 734 class B2 {} |
| 759 class _B3 {} | 735 class _B3 {} |
| 760 '''); | 736 '''); |
| 761 computeResult(sourceA, LIBRARY_ELEMENT4, | 737 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 762 matcher: isBuildExportNamespaceTask); | 738 matcher: isBuildExportNamespaceTask); |
| 763 // validate | 739 // validate |
| 764 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 740 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 765 Namespace namespace = library.exportNamespace; | 741 Namespace namespace = library.exportNamespace; |
| 766 Iterable<String> definedKeys = namespace.definedNames.keys; | 742 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 767 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); | 743 expect(definedKeys, unorderedEquals(['A1', 'A2', 'B1'])); |
| 768 } | 744 } |
| 769 | 745 |
| 770 test_perform_showCombinator_setter() { | 746 test_perform_showCombinator_setter() { |
| 771 Source sourceA = newSource( | 747 Source sourceA = newSource('/a.dart', ''' |
| 772 '/a.dart', | |
| 773 ''' | |
| 774 library lib_a; | 748 library lib_a; |
| 775 export 'b.dart' show topLevelB; | 749 export 'b.dart' show topLevelB; |
| 776 class A {} | 750 class A {} |
| 777 '''); | 751 '''); |
| 778 newSource( | 752 newSource('/b.dart', ''' |
| 779 '/b.dart', | |
| 780 ''' | |
| 781 library lib_b; | 753 library lib_b; |
| 782 int topLevelB; | 754 int topLevelB; |
| 783 '''); | 755 '''); |
| 784 computeResult(sourceA, LIBRARY_ELEMENT4, | 756 computeResult(sourceA, LIBRARY_ELEMENT4, |
| 785 matcher: isBuildExportNamespaceTask); | 757 matcher: isBuildExportNamespaceTask); |
| 786 // validate | 758 // validate |
| 787 LibraryElement library = outputs[LIBRARY_ELEMENT4]; | 759 LibraryElement library = outputs[LIBRARY_ELEMENT4]; |
| 788 Namespace namespace = library.exportNamespace; | 760 Namespace namespace = library.exportNamespace; |
| 789 Iterable<String> definedKeys = namespace.definedNames.keys; | 761 Iterable<String> definedKeys = namespace.definedNames.keys; |
| 790 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); | 762 expect(definedKeys, unorderedEquals(['A', 'topLevelB', 'topLevelB='])); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 } | 1051 } |
| 1080 } | 1052 } |
| 1081 | 1053 |
| 1082 @reflectiveTest | 1054 @reflectiveTest |
| 1083 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { | 1055 class BuildSourceExportClosureTaskTest extends _AbstractDartTaskTest { |
| 1084 List<Source> getExportSourceClosure(Map<ResultDescriptor, dynamic> outputs) { | 1056 List<Source> getExportSourceClosure(Map<ResultDescriptor, dynamic> outputs) { |
| 1085 return outputs[EXPORT_SOURCE_CLOSURE] as List<Source>; | 1057 return outputs[EXPORT_SOURCE_CLOSURE] as List<Source>; |
| 1086 } | 1058 } |
| 1087 | 1059 |
| 1088 test_perform_exportClosure() { | 1060 test_perform_exportClosure() { |
| 1089 Source sourceA = newSource( | 1061 Source sourceA = newSource('/a.dart', ''' |
| 1090 '/a.dart', | |
| 1091 ''' | |
| 1092 library lib_a; | 1062 library lib_a; |
| 1093 export 'b.dart'; | 1063 export 'b.dart'; |
| 1094 '''); | 1064 '''); |
| 1095 Source sourceB = newSource( | 1065 Source sourceB = newSource('/b.dart', ''' |
| 1096 '/b.dart', | |
| 1097 ''' | |
| 1098 library lib_b; | 1066 library lib_b; |
| 1099 export 'c.dart'; | 1067 export 'c.dart'; |
| 1100 '''); | 1068 '''); |
| 1101 Source sourceC = newSource( | 1069 Source sourceC = newSource('/c.dart', ''' |
| 1102 '/c.dart', | |
| 1103 ''' | |
| 1104 library lib_c; | 1070 library lib_c; |
| 1105 export 'a.dart'; | 1071 export 'a.dart'; |
| 1106 '''); | 1072 '''); |
| 1107 Source sourceD = newSource( | 1073 Source sourceD = newSource('/d.dart', ''' |
| 1108 '/d.dart', | |
| 1109 ''' | |
| 1110 library lib_d; | 1074 library lib_d; |
| 1111 '''); | 1075 '''); |
| 1112 // a.dart | 1076 // a.dart |
| 1113 { | 1077 { |
| 1114 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, | 1078 computeResult(sourceA, EXPORT_SOURCE_CLOSURE, |
| 1115 matcher: isBuildSourceExportClosureTask); | 1079 matcher: isBuildSourceExportClosureTask); |
| 1116 List<Source> closure = getExportSourceClosure(outputs); | 1080 List<Source> closure = getExportSourceClosure(outputs); |
| 1117 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); | 1081 expect(closure, unorderedEquals([sourceA, sourceB, sourceC])); |
| 1118 } | 1082 } |
| 1119 // c.dart | 1083 // c.dart |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 if (member is ClassDeclaration && member.name.name == className) { | 1118 if (member is ClassDeclaration && member.name.name == className) { |
| 1155 expect(member.metadata, hasLength(1)); | 1119 expect(member.metadata, hasLength(1)); |
| 1156 return member.metadata[0]; | 1120 return member.metadata[0]; |
| 1157 } | 1121 } |
| 1158 } | 1122 } |
| 1159 fail('Annotation not found'); | 1123 fail('Annotation not found'); |
| 1160 return null; | 1124 return null; |
| 1161 } | 1125 } |
| 1162 | 1126 |
| 1163 test_annotation_with_args() { | 1127 test_annotation_with_args() { |
| 1164 Source source = newSource( | 1128 Source source = newSource('/test.dart', ''' |
| 1165 '/test.dart', | |
| 1166 ''' | |
| 1167 const x = 1; | 1129 const x = 1; |
| 1168 @D(x) class C {} | 1130 @D(x) class C {} |
| 1169 class D { const D(value); } | 1131 class D { const D(value); } |
| 1170 '''); | 1132 '''); |
| 1171 // First compute the resolved unit for the source. | 1133 // First compute the resolved unit for the source. |
| 1172 LibrarySpecificUnit librarySpecificUnit = | 1134 LibrarySpecificUnit librarySpecificUnit = |
| 1173 new LibrarySpecificUnit(source, source); | 1135 new LibrarySpecificUnit(source, source); |
| 1174 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1136 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1175 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1137 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1176 // Find the elements for x and D's constructor, and the annotation on C. | 1138 // Find the elements for x and D's constructor, and the annotation on C. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1189 // the set [x, constructorForD]. | 1151 // the set [x, constructorForD]. |
| 1190 // TODO(paulberry): test librarySource != source | 1152 // TODO(paulberry): test librarySource != source |
| 1191 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), | 1153 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), |
| 1192 CONSTANT_DEPENDENCIES, | 1154 CONSTANT_DEPENDENCIES, |
| 1193 matcher: isComputeConstantDependenciesTask); | 1155 matcher: isComputeConstantDependenciesTask); |
| 1194 expect( | 1156 expect( |
| 1195 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); | 1157 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); |
| 1196 } | 1158 } |
| 1197 | 1159 |
| 1198 test_annotation_with_nonConstArg() { | 1160 test_annotation_with_nonConstArg() { |
| 1199 Source source = newSource( | 1161 Source source = newSource('/test.dart', ''' |
| 1200 '/test.dart', | |
| 1201 ''' | |
| 1202 class A { | 1162 class A { |
| 1203 const A(x); | 1163 const A(x); |
| 1204 } | 1164 } |
| 1205 class C { | 1165 class C { |
| 1206 @A(const [(_) => null]) | 1166 @A(const [(_) => null]) |
| 1207 String s; | 1167 String s; |
| 1208 } | 1168 } |
| 1209 '''); | 1169 '''); |
| 1210 // First compute the resolved unit for the source. | 1170 // First compute the resolved unit for the source. |
| 1211 LibrarySpecificUnit librarySpecificUnit = | 1171 LibrarySpecificUnit librarySpecificUnit = |
| 1212 new LibrarySpecificUnit(source, source); | 1172 new LibrarySpecificUnit(source, source); |
| 1213 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1173 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1214 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1174 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1215 // Find the annotation on the field. | 1175 // Find the annotation on the field. |
| 1216 ClassDeclaration classC = unit.declarations[1]; | 1176 ClassDeclaration classC = unit.declarations[1]; |
| 1217 Annotation annotation = classC.members[0].metadata[0]; | 1177 Annotation annotation = classC.members[0].metadata[0]; |
| 1218 // Now compute the dependencies for the annotation, and check that it is | 1178 // Now compute the dependencies for the annotation, and check that it is |
| 1219 // the right size. | 1179 // the right size. |
| 1220 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), | 1180 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), |
| 1221 CONSTANT_DEPENDENCIES, | 1181 CONSTANT_DEPENDENCIES, |
| 1222 matcher: isComputeConstantDependenciesTask); | 1182 matcher: isComputeConstantDependenciesTask); |
| 1223 expect(outputs[CONSTANT_DEPENDENCIES], hasLength(1)); | 1183 expect(outputs[CONSTANT_DEPENDENCIES], hasLength(1)); |
| 1224 } | 1184 } |
| 1225 | 1185 |
| 1226 test_annotation_without_args() { | 1186 test_annotation_without_args() { |
| 1227 Source source = newSource( | 1187 Source source = newSource('/test.dart', ''' |
| 1228 '/test.dart', | |
| 1229 ''' | |
| 1230 const x = 1; | 1188 const x = 1; |
| 1231 @x class C {} | 1189 @x class C {} |
| 1232 '''); | 1190 '''); |
| 1233 // First compute the resolved unit for the source. | 1191 // First compute the resolved unit for the source. |
| 1234 LibrarySpecificUnit librarySpecificUnit = | 1192 LibrarySpecificUnit librarySpecificUnit = |
| 1235 new LibrarySpecificUnit(source, source); | 1193 new LibrarySpecificUnit(source, source); |
| 1236 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1194 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1237 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1195 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1238 // Find the element for x and the annotation on C. | 1196 // Find the element for x and the annotation on C. |
| 1239 List<PropertyAccessorElement> accessors = | 1197 List<PropertyAccessorElement> accessors = |
| 1240 resolutionMap.elementDeclaredByCompilationUnit(unit).accessors; | 1198 resolutionMap.elementDeclaredByCompilationUnit(unit).accessors; |
| 1241 Element x = accessors | 1199 Element x = accessors |
| 1242 .firstWhere((PropertyAccessorElement accessor) => | 1200 .firstWhere((PropertyAccessorElement accessor) => |
| 1243 accessor.isGetter && accessor.name == 'x') | 1201 accessor.isGetter && accessor.name == 'x') |
| 1244 .variable; | 1202 .variable; |
| 1245 Annotation annotation = findClassAnnotation(unit, 'C'); | 1203 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1246 // Now compute the dependencies for the annotation, and check that it is | 1204 // Now compute the dependencies for the annotation, and check that it is |
| 1247 // the list [x]. | 1205 // the list [x]. |
| 1248 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), | 1206 computeResult(resolutionMap.elementAnnotationForAnnotation(annotation), |
| 1249 CONSTANT_DEPENDENCIES, | 1207 CONSTANT_DEPENDENCIES, |
| 1250 matcher: isComputeConstantDependenciesTask); | 1208 matcher: isComputeConstantDependenciesTask); |
| 1251 expect(outputs[CONSTANT_DEPENDENCIES], [x]); | 1209 expect(outputs[CONSTANT_DEPENDENCIES], [x]); |
| 1252 } | 1210 } |
| 1253 | 1211 |
| 1254 test_enumConstant() { | 1212 test_enumConstant() { |
| 1255 Source source = newSource( | 1213 Source source = newSource('/test.dart', ''' |
| 1256 '/test.dart', | |
| 1257 ''' | |
| 1258 enum E {A, B, C} | 1214 enum E {A, B, C} |
| 1259 '''); | 1215 '''); |
| 1260 // First compute the resolved unit for the source. | 1216 // First compute the resolved unit for the source. |
| 1261 LibrarySpecificUnit librarySpecificUnit = | 1217 LibrarySpecificUnit librarySpecificUnit = |
| 1262 new LibrarySpecificUnit(source, source); | 1218 new LibrarySpecificUnit(source, source); |
| 1263 computeResult(librarySpecificUnit, RESOLVED_UNIT3); | 1219 computeResult(librarySpecificUnit, RESOLVED_UNIT3); |
| 1264 CompilationUnit unit = outputs[RESOLVED_UNIT3]; | 1220 CompilationUnit unit = outputs[RESOLVED_UNIT3]; |
| 1265 // Find the element for 'A' | 1221 // Find the element for 'A' |
| 1266 EnumDeclaration enumDeclaration = unit.declarations[0]; | 1222 EnumDeclaration enumDeclaration = unit.declarations[0]; |
| 1267 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; | 1223 EnumConstantDeclaration constantDeclaration = enumDeclaration.constants[0]; |
| 1268 FieldElement constantElement = constantDeclaration.element; | 1224 FieldElement constantElement = constantDeclaration.element; |
| 1269 // Now compute the dependencies for the constant and check that there are | 1225 // Now compute the dependencies for the constant and check that there are |
| 1270 // none. | 1226 // none. |
| 1271 computeResult(constantElement, CONSTANT_DEPENDENCIES, | 1227 computeResult(constantElement, CONSTANT_DEPENDENCIES, |
| 1272 matcher: isComputeConstantDependenciesTask); | 1228 matcher: isComputeConstantDependenciesTask); |
| 1273 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); | 1229 expect(outputs[CONSTANT_DEPENDENCIES], isEmpty); |
| 1274 } | 1230 } |
| 1275 | 1231 |
| 1276 test_perform() { | 1232 test_perform() { |
| 1277 Source source = newSource( | 1233 Source source = newSource('/test.dart', ''' |
| 1278 '/test.dart', | |
| 1279 ''' | |
| 1280 const x = y; | 1234 const x = y; |
| 1281 const y = 1; | 1235 const y = 1; |
| 1282 '''); | 1236 '''); |
| 1283 // First compute the resolved unit for the source. | 1237 // First compute the resolved unit for the source. |
| 1284 LibrarySpecificUnit librarySpecificUnit = | 1238 LibrarySpecificUnit librarySpecificUnit = |
| 1285 new LibrarySpecificUnit(source, source); | 1239 new LibrarySpecificUnit(source, source); |
| 1286 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1240 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1287 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1241 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1288 // Find the elements for the constants x and y. | 1242 // Find the elements for the constants x and y. |
| 1289 List<PropertyAccessorElement> accessors = | 1243 List<PropertyAccessorElement> accessors = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 return evaluationResult; | 1275 return evaluationResult; |
| 1322 } | 1276 } |
| 1323 } | 1277 } |
| 1324 fail('Annotation not found'); | 1278 fail('Annotation not found'); |
| 1325 return null; | 1279 return null; |
| 1326 } | 1280 } |
| 1327 | 1281 |
| 1328 test_annotation_non_const_constructor() { | 1282 test_annotation_non_const_constructor() { |
| 1329 // Calling a non-const constructor from an annotation that is illegal, but | 1283 // Calling a non-const constructor from an annotation that is illegal, but |
| 1330 // shouldn't crash analysis. | 1284 // shouldn't crash analysis. |
| 1331 Source source = newSource( | 1285 Source source = newSource('/test.dart', ''' |
| 1332 '/test.dart', | |
| 1333 ''' | |
| 1334 class A { | 1286 class A { |
| 1335 final int i; | 1287 final int i; |
| 1336 A(this.i); | 1288 A(this.i); |
| 1337 } | 1289 } |
| 1338 | 1290 |
| 1339 @A(5) | 1291 @A(5) |
| 1340 class C {} | 1292 class C {} |
| 1341 '''); | 1293 '''); |
| 1342 // First compute the resolved unit for the source. | 1294 // First compute the resolved unit for the source. |
| 1343 CompilationUnit unit = _resolveSource(source); | 1295 CompilationUnit unit = _resolveSource(source); |
| 1344 // Compute the constant value of the annotation on C. | 1296 // Compute the constant value of the annotation on C. |
| 1345 EvaluationResultImpl evaluationResult = | 1297 EvaluationResultImpl evaluationResult = |
| 1346 computeClassAnnotation(source, unit, 'C'); | 1298 computeClassAnnotation(source, unit, 'C'); |
| 1347 // And check that it has no value stored in it. | 1299 // And check that it has no value stored in it. |
| 1348 expect(evaluationResult, isNotNull); | 1300 expect(evaluationResult, isNotNull); |
| 1349 expect(evaluationResult.value, isNull); | 1301 expect(evaluationResult.value, isNull); |
| 1350 } | 1302 } |
| 1351 | 1303 |
| 1352 test_annotation_with_args() { | 1304 test_annotation_with_args() { |
| 1353 Source source = newSource( | 1305 Source source = newSource('/test.dart', ''' |
| 1354 '/test.dart', | |
| 1355 ''' | |
| 1356 const x = 1; | 1306 const x = 1; |
| 1357 @D(x) class C {} | 1307 @D(x) class C {} |
| 1358 class D { | 1308 class D { |
| 1359 const D(this.value); | 1309 const D(this.value); |
| 1360 final value; | 1310 final value; |
| 1361 } | 1311 } |
| 1362 '''); | 1312 '''); |
| 1363 // First compute the resolved unit for the source. | 1313 // First compute the resolved unit for the source. |
| 1364 CompilationUnit unit = _resolveSource(source); | 1314 CompilationUnit unit = _resolveSource(source); |
| 1365 // Compute the constant value of the annotation on C. | 1315 // Compute the constant value of the annotation on C. |
| 1366 EvaluationResultImpl evaluationResult = | 1316 EvaluationResultImpl evaluationResult = |
| 1367 computeClassAnnotation(source, unit, 'C'); | 1317 computeClassAnnotation(source, unit, 'C'); |
| 1368 // And check that it has the expected value. | 1318 // And check that it has the expected value. |
| 1369 expect(evaluationResult, isNotNull); | 1319 expect(evaluationResult, isNotNull); |
| 1370 expect(evaluationResult.value, isNotNull); | 1320 expect(evaluationResult.value, isNotNull); |
| 1371 expect(evaluationResult.value.type, isNotNull); | 1321 expect(evaluationResult.value.type, isNotNull); |
| 1372 expect(evaluationResult.value.type.name, 'D'); | 1322 expect(evaluationResult.value.type.name, 'D'); |
| 1373 expect(evaluationResult.value.fields, contains('value')); | 1323 expect(evaluationResult.value.fields, contains('value')); |
| 1374 expect(evaluationResult.value.fields['value'].toIntValue(), 1); | 1324 expect(evaluationResult.value.fields['value'].toIntValue(), 1); |
| 1375 } | 1325 } |
| 1376 | 1326 |
| 1377 test_annotation_without_args() { | 1327 test_annotation_without_args() { |
| 1378 Source source = newSource( | 1328 Source source = newSource('/test.dart', ''' |
| 1379 '/test.dart', | |
| 1380 ''' | |
| 1381 const x = 1; | 1329 const x = 1; |
| 1382 @x class C {} | 1330 @x class C {} |
| 1383 '''); | 1331 '''); |
| 1384 // First compute the resolved unit for the source. | 1332 // First compute the resolved unit for the source. |
| 1385 CompilationUnit unit = _resolveSource(source); | 1333 CompilationUnit unit = _resolveSource(source); |
| 1386 // Compute the constant value of the annotation on C. | 1334 // Compute the constant value of the annotation on C. |
| 1387 EvaluationResultImpl evaluationResult = | 1335 EvaluationResultImpl evaluationResult = |
| 1388 computeClassAnnotation(source, unit, 'C'); | 1336 computeClassAnnotation(source, unit, 'C'); |
| 1389 // And check that it has the expected value. | 1337 // And check that it has the expected value. |
| 1390 expect(evaluationResult, isNotNull); | 1338 expect(evaluationResult, isNotNull); |
| 1391 expect(evaluationResult.value, isNotNull); | 1339 expect(evaluationResult.value, isNotNull); |
| 1392 expect(evaluationResult.value.toIntValue(), 1); | 1340 expect(evaluationResult.value.toIntValue(), 1); |
| 1393 } | 1341 } |
| 1394 | 1342 |
| 1395 test_circular_reference() { | 1343 test_circular_reference() { |
| 1396 _checkCircularities( | 1344 _checkCircularities('x', ['y'], ''' |
| 1397 'x', | |
| 1398 ['y'], | |
| 1399 ''' | |
| 1400 const x = y + 1; | 1345 const x = y + 1; |
| 1401 const y = x + 1; | 1346 const y = x + 1; |
| 1402 '''); | 1347 '''); |
| 1403 } | 1348 } |
| 1404 | 1349 |
| 1405 test_circular_reference_one_element() { | 1350 test_circular_reference_one_element() { |
| 1406 // See dartbug.com/23490. | 1351 // See dartbug.com/23490. |
| 1407 _checkCircularities('x', [], 'const x = x;'); | 1352 _checkCircularities('x', [], 'const x = x;'); |
| 1408 } | 1353 } |
| 1409 | 1354 |
| 1410 test_circular_reference_strongly_connected_component() { | 1355 test_circular_reference_strongly_connected_component() { |
| 1411 // When there is a circularity, all elements in the strongly connected | 1356 // When there is a circularity, all elements in the strongly connected |
| 1412 // component should be marked as having an error. | 1357 // component should be marked as having an error. |
| 1413 _checkCircularities( | 1358 _checkCircularities('a', ['b', 'c', 'd'], ''' |
| 1414 'a', | |
| 1415 ['b', 'c', 'd'], | |
| 1416 ''' | |
| 1417 const a = b; | 1359 const a = b; |
| 1418 const b = c + d; | 1360 const b = c + d; |
| 1419 const c = a; | 1361 const c = a; |
| 1420 const d = a; | 1362 const d = a; |
| 1421 '''); | 1363 '''); |
| 1422 } | 1364 } |
| 1423 | 1365 |
| 1424 test_const_constructor_calls_implicit_super_constructor_implicitly() { | 1366 test_const_constructor_calls_implicit_super_constructor_implicitly() { |
| 1425 // Note: the situation below is a compile-time error (since the synthetic | 1367 // Note: the situation below is a compile-time error (since the synthetic |
| 1426 // constructor for Base is non-const), but we need to handle it without | 1368 // constructor for Base is non-const), but we need to handle it without |
| 1427 // throwing an exception. | 1369 // throwing an exception. |
| 1428 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1370 EvaluationResultImpl evaluationResult = |
| 1429 'x', | 1371 _computeTopLevelVariableConstValue('x', ''' |
| 1430 ''' | |
| 1431 class Base {} | 1372 class Base {} |
| 1432 class Derived extends Base { | 1373 class Derived extends Base { |
| 1433 const Derived(); | 1374 const Derived(); |
| 1434 } | 1375 } |
| 1435 const x = const Derived(); | 1376 const x = const Derived(); |
| 1436 '''); | 1377 '''); |
| 1437 expect(evaluationResult, isNotNull); | 1378 expect(evaluationResult, isNotNull); |
| 1438 } | 1379 } |
| 1439 | 1380 |
| 1440 test_dependency() { | 1381 test_dependency() { |
| 1441 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1382 EvaluationResultImpl evaluationResult = |
| 1442 'x', | 1383 _computeTopLevelVariableConstValue('x', ''' |
| 1443 ''' | |
| 1444 const x = y + 1; | 1384 const x = y + 1; |
| 1445 const y = 1; | 1385 const y = 1; |
| 1446 '''); | 1386 '''); |
| 1447 expect(evaluationResult, isNotNull); | 1387 expect(evaluationResult, isNotNull); |
| 1448 expect(evaluationResult.value, isNotNull); | 1388 expect(evaluationResult.value, isNotNull); |
| 1449 expect(evaluationResult.value.toIntValue(), 2); | 1389 expect(evaluationResult.value.toIntValue(), 2); |
| 1450 } | 1390 } |
| 1451 | 1391 |
| 1452 test_external_const_factory() { | 1392 test_external_const_factory() { |
| 1453 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1393 EvaluationResultImpl evaluationResult = |
| 1454 'x', | 1394 _computeTopLevelVariableConstValue('x', ''' |
| 1455 ''' | |
| 1456 const x = const C.foo(); | 1395 const x = const C.foo(); |
| 1457 | 1396 |
| 1458 class C extends B { | 1397 class C extends B { |
| 1459 external const factory C.foo(); | 1398 external const factory C.foo(); |
| 1460 } | 1399 } |
| 1461 | 1400 |
| 1462 class B {} | 1401 class B {} |
| 1463 '''); | 1402 '''); |
| 1464 expect(evaluationResult, isNotNull); | 1403 expect(evaluationResult, isNotNull); |
| 1465 } | 1404 } |
| 1466 | 1405 |
| 1467 test_simple_constant() { | 1406 test_simple_constant() { |
| 1468 EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue( | 1407 EvaluationResultImpl evaluationResult = |
| 1469 'x', | 1408 _computeTopLevelVariableConstValue('x', ''' |
| 1470 ''' | |
| 1471 const x = 1; | 1409 const x = 1; |
| 1472 '''); | 1410 '''); |
| 1473 expect(evaluationResult, isNotNull); | 1411 expect(evaluationResult, isNotNull); |
| 1474 expect(evaluationResult.value, isNotNull); | 1412 expect(evaluationResult.value, isNotNull); |
| 1475 expect(evaluationResult.value.toIntValue(), 1); | 1413 expect(evaluationResult.value.toIntValue(), 1); |
| 1476 } | 1414 } |
| 1477 | 1415 |
| 1478 void _checkCircularities( | 1416 void _checkCircularities( |
| 1479 String variableName, List<String> otherVariables, String content) { | 1417 String variableName, List<String> otherVariables, String content) { |
| 1480 // Evaluating the first constant should produce an error. | 1418 // Evaluating the first constant should produce an error. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1534 class ComputeInferableStaticVariableDependenciesTaskTest | 1472 class ComputeInferableStaticVariableDependenciesTaskTest |
| 1535 extends _AbstractDartTaskTest { | 1473 extends _AbstractDartTaskTest { |
| 1536 @override | 1474 @override |
| 1537 void setUp() { | 1475 void setUp() { |
| 1538 super.setUp(); | 1476 super.setUp(); |
| 1539 // Variable dependencies are only available in strong mode. | 1477 // Variable dependencies are only available in strong mode. |
| 1540 enableStrongMode(); | 1478 enableStrongMode(); |
| 1541 } | 1479 } |
| 1542 | 1480 |
| 1543 test_created_resolved_unit() { | 1481 test_created_resolved_unit() { |
| 1544 Source source = newSource( | 1482 Source source = newSource('/test.dart', r''' |
| 1545 '/test.dart', | |
| 1546 r''' | |
| 1547 library lib; | 1483 library lib; |
| 1548 class A {} | 1484 class A {} |
| 1549 '''); | 1485 '''); |
| 1550 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1486 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1551 computeResult(target, RESOLVED_UNIT7); | 1487 computeResult(target, RESOLVED_UNIT7); |
| 1552 expect(outputs[RESOLVED_UNIT7], isNotNull); | 1488 expect(outputs[RESOLVED_UNIT7], isNotNull); |
| 1553 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue); | 1489 expect(outputs[CREATED_RESOLVED_UNIT7], isTrue); |
| 1554 } | 1490 } |
| 1555 | 1491 |
| 1556 test_perform() { | 1492 test_perform() { |
| 1557 AnalysisTarget source = newSource( | 1493 AnalysisTarget source = newSource('/test.dart', ''' |
| 1558 '/test.dart', | |
| 1559 ''' | |
| 1560 const a = b; | 1494 const a = b; |
| 1561 const b = 0; | 1495 const b = 0; |
| 1562 '''); | 1496 '''); |
| 1563 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 1497 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 1564 computeResult(target, RESOLVED_UNIT7); | 1498 computeResult(target, RESOLVED_UNIT7); |
| 1565 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 1499 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 1566 TopLevelVariableElement elementA = resolutionMap | 1500 TopLevelVariableElement elementA = resolutionMap |
| 1567 .elementDeclaredByCompilationUnit(unit) | 1501 .elementDeclaredByCompilationUnit(unit) |
| 1568 .topLevelVariables[0]; | 1502 .topLevelVariables[0]; |
| 1569 TopLevelVariableElement elementB = resolutionMap | 1503 TopLevelVariableElement elementB = resolutionMap |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1597 } | 1531 } |
| 1598 | 1532 |
| 1599 @override | 1533 @override |
| 1600 void setUp() { | 1534 void setUp() { |
| 1601 super.setUp(); | 1535 super.setUp(); |
| 1602 enableStrongMode(); | 1536 enableStrongMode(); |
| 1603 } | 1537 } |
| 1604 | 1538 |
| 1605 void test_library_cycle_incremental() { | 1539 void test_library_cycle_incremental() { |
| 1606 enableStrongMode(); | 1540 enableStrongMode(); |
| 1607 Source a = newSource( | 1541 Source a = newSource('/a.dart', ''' |
| 1608 '/a.dart', | |
| 1609 ''' | |
| 1610 library a; | 1542 library a; |
| 1611 '''); | 1543 '''); |
| 1612 Source b = newSource( | 1544 Source b = newSource('/b.dart', ''' |
| 1613 '/b.dart', | |
| 1614 ''' | |
| 1615 library b; | 1545 library b; |
| 1616 import 'a.dart'; | 1546 import 'a.dart'; |
| 1617 '''); | 1547 '''); |
| 1618 Source c = newSource( | 1548 Source c = newSource('/c.dart', ''' |
| 1619 '/c.dart', | |
| 1620 ''' | |
| 1621 library c; | 1549 library c; |
| 1622 import 'b.dart'; | 1550 import 'b.dart'; |
| 1623 '''); | 1551 '''); |
| 1624 | 1552 |
| 1625 _assertLibraryCycle(a, [a]); | 1553 _assertLibraryCycle(a, [a]); |
| 1626 _assertLibraryCycle(b, [b]); | 1554 _assertLibraryCycle(b, [b]); |
| 1627 _assertLibraryCycle(c, [c]); | 1555 _assertLibraryCycle(c, [c]); |
| 1628 | 1556 |
| 1629 // Create a cycle. | 1557 // Create a cycle. |
| 1630 context.setContents( | 1558 context.setContents(a, ''' |
| 1631 a, | |
| 1632 ''' | |
| 1633 library a; | 1559 library a; |
| 1634 import 'c.dart'; | 1560 import 'c.dart'; |
| 1635 '''); | 1561 '''); |
| 1636 _expectInvalid(a); | 1562 _expectInvalid(a); |
| 1637 _expectInvalid(b); | 1563 _expectInvalid(b); |
| 1638 _expectInvalid(c); | 1564 _expectInvalid(c); |
| 1639 | 1565 |
| 1640 _assertLibraryCycle(a, [a, b, c]); | 1566 _assertLibraryCycle(a, [a, b, c]); |
| 1641 _assertLibraryCycle(b, [a, b, c]); | 1567 _assertLibraryCycle(b, [a, b, c]); |
| 1642 _assertLibraryCycle(c, [a, b, c]); | 1568 _assertLibraryCycle(c, [a, b, c]); |
| 1643 | 1569 |
| 1644 // Break the cycle again. | 1570 // Break the cycle again. |
| 1645 context.setContents( | 1571 context.setContents(a, ''' |
| 1646 a, | |
| 1647 ''' | |
| 1648 library a; | 1572 library a; |
| 1649 '''); | 1573 '''); |
| 1650 _expectInvalid(a); | 1574 _expectInvalid(a); |
| 1651 _expectInvalid(b); | 1575 _expectInvalid(b); |
| 1652 _expectInvalid(c); | 1576 _expectInvalid(c); |
| 1653 | 1577 |
| 1654 _assertLibraryCycle(a, [a]); | 1578 _assertLibraryCycle(a, [a]); |
| 1655 _assertLibraryCycle(b, [b]); | 1579 _assertLibraryCycle(b, [b]); |
| 1656 _assertLibraryCycle(c, [c]); | 1580 _assertLibraryCycle(c, [c]); |
| 1657 } | 1581 } |
| 1658 | 1582 |
| 1659 void test_library_cycle_incremental_partial() { | 1583 void test_library_cycle_incremental_partial() { |
| 1660 enableStrongMode(); | 1584 enableStrongMode(); |
| 1661 Source a = newSource( | 1585 Source a = newSource('/a.dart', r''' |
| 1662 '/a.dart', | |
| 1663 r''' | |
| 1664 library a; | 1586 library a; |
| 1665 '''); | 1587 '''); |
| 1666 Source b = newSource( | 1588 Source b = newSource('/b.dart', r''' |
| 1667 '/b.dart', | |
| 1668 r''' | |
| 1669 library b; | 1589 library b; |
| 1670 import 'a.dart'; | 1590 import 'a.dart'; |
| 1671 '''); | 1591 '''); |
| 1672 Source c = newSource( | 1592 Source c = newSource('/c.dart', r''' |
| 1673 '/c.dart', | |
| 1674 r''' | |
| 1675 library c; | 1593 library c; |
| 1676 import 'b.dart'; | 1594 import 'b.dart'; |
| 1677 '''); | 1595 '''); |
| 1678 | 1596 |
| 1679 _assertLibraryCycle(a, [a]); | 1597 _assertLibraryCycle(a, [a]); |
| 1680 _assertLibraryCycle(b, [b]); | 1598 _assertLibraryCycle(b, [b]); |
| 1681 // 'c' is not reachable, so we have not yet computed its library cycles. | 1599 // 'c' is not reachable, so we have not yet computed its library cycles. |
| 1682 | 1600 |
| 1683 // Complete the cycle, via 'c'. | 1601 // Complete the cycle, via 'c'. |
| 1684 context.setContents( | 1602 context.setContents(a, r''' |
| 1685 a, | |
| 1686 r''' | |
| 1687 library a; | 1603 library a; |
| 1688 import 'c.dart'; | 1604 import 'c.dart'; |
| 1689 '''); | 1605 '''); |
| 1690 _expectInvalid(a); | 1606 _expectInvalid(a); |
| 1691 _expectInvalid(b); | 1607 _expectInvalid(b); |
| 1692 _expectInvalid(c); | 1608 _expectInvalid(c); |
| 1693 | 1609 |
| 1694 // Ensure that everything reachable through 'c' was invalidated, | 1610 // Ensure that everything reachable through 'c' was invalidated, |
| 1695 // and recomputed to include all three sources. | 1611 // and recomputed to include all three sources. |
| 1696 _assertLibraryCycle(a, [a, b, c]); | 1612 _assertLibraryCycle(a, [a, b, c]); |
| 1697 _assertLibraryCycle(b, [a, b, c]); | 1613 _assertLibraryCycle(b, [a, b, c]); |
| 1698 _assertLibraryCycle(c, [a, b, c]); | 1614 _assertLibraryCycle(c, [a, b, c]); |
| 1699 } | 1615 } |
| 1700 | 1616 |
| 1701 void test_library_cycle_incremental_partial2() { | 1617 void test_library_cycle_incremental_partial2() { |
| 1702 enableStrongMode(); | 1618 enableStrongMode(); |
| 1703 Source a = newSource( | 1619 Source a = newSource('/a.dart', r''' |
| 1704 '/a.dart', | |
| 1705 r''' | |
| 1706 library a; | 1620 library a; |
| 1707 import 'b.dart'; | 1621 import 'b.dart'; |
| 1708 '''); | 1622 '''); |
| 1709 Source b = newSource( | 1623 Source b = newSource('/b.dart', r''' |
| 1710 '/b.dart', | |
| 1711 r''' | |
| 1712 library b; | 1624 library b; |
| 1713 import 'a.dart'; | 1625 import 'a.dart'; |
| 1714 '''); | 1626 '''); |
| 1715 Source c = newSource( | 1627 Source c = newSource('/c.dart', r''' |
| 1716 '/c.dart', | |
| 1717 r''' | |
| 1718 library c; | 1628 library c; |
| 1719 import 'b.dart'; | 1629 import 'b.dart'; |
| 1720 '''); | 1630 '''); |
| 1721 | 1631 |
| 1722 _assertLibraryCycle(a, [a, b]); | 1632 _assertLibraryCycle(a, [a, b]); |
| 1723 _assertLibraryCycle(b, [a, b]); | 1633 _assertLibraryCycle(b, [a, b]); |
| 1724 _assertLibraryCycle(c, [c]); | 1634 _assertLibraryCycle(c, [c]); |
| 1725 | 1635 |
| 1726 // Include 'c' into the cycle. | 1636 // Include 'c' into the cycle. |
| 1727 context.setContents( | 1637 context.setContents(a, r''' |
| 1728 a, | |
| 1729 r''' | |
| 1730 library a; | 1638 library a; |
| 1731 import 'b.dart'; | 1639 import 'b.dart'; |
| 1732 import 'c.dart'; | 1640 import 'c.dart'; |
| 1733 '''); | 1641 '''); |
| 1734 _expectInvalid(a); | 1642 _expectInvalid(a); |
| 1735 _expectInvalid(b); | 1643 _expectInvalid(b); |
| 1736 _expectInvalid(c); | 1644 _expectInvalid(c); |
| 1737 | 1645 |
| 1738 // Start processing with 'b', so that when we resolve 'b' directives, | 1646 // Start processing with 'b', so that when we resolve 'b' directives, |
| 1739 // and invalidate library cycles, the 'a' directives are not resolved yet, | 1647 // and invalidate library cycles, the 'a' directives are not resolved yet, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); | 1709 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1802 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); | 1710 List<LibrarySpecificUnit> dep1 = getLibraryCycleDependencies(results[1]); |
| 1803 List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]); | 1711 List<LibrarySpecificUnit> dep2 = getLibraryCycleDependencies(results[2]); |
| 1804 expect(dep0, hasLength(1)); // dart:core | 1712 expect(dep0, hasLength(1)); // dart:core |
| 1805 expect(dep1, hasLength(1)); // dart:core | 1713 expect(dep1, hasLength(1)); // dart:core |
| 1806 expect(dep2, hasLength(1)); // dart:core | 1714 expect(dep2, hasLength(1)); // dart:core |
| 1807 } | 1715 } |
| 1808 | 1716 |
| 1809 void test_library_cycle_override_inference_incremental() { | 1717 void test_library_cycle_override_inference_incremental() { |
| 1810 enableStrongMode(); | 1718 enableStrongMode(); |
| 1811 Source lib1Source = newSource( | 1719 Source lib1Source = newSource('/my_lib1.dart', ''' |
| 1812 '/my_lib1.dart', | |
| 1813 ''' | |
| 1814 library my_lib1; | 1720 library my_lib1; |
| 1815 import 'my_lib3.dart'; | 1721 import 'my_lib3.dart'; |
| 1816 '''); | 1722 '''); |
| 1817 Source lib2Source = newSource( | 1723 Source lib2Source = newSource('/my_lib2.dart', ''' |
| 1818 '/my_lib2.dart', | |
| 1819 ''' | |
| 1820 library my_lib2; | 1724 library my_lib2; |
| 1821 import 'my_lib1.dart'; | 1725 import 'my_lib1.dart'; |
| 1822 '''); | 1726 '''); |
| 1823 Source lib3Source = newSource( | 1727 Source lib3Source = newSource('/my_lib3.dart', ''' |
| 1824 '/my_lib3.dart', | |
| 1825 ''' | |
| 1826 library my_lib3; | 1728 library my_lib3; |
| 1827 import 'my_lib2.dart'; | 1729 import 'my_lib2.dart'; |
| 1828 | 1730 |
| 1829 class A { | 1731 class A { |
| 1830 int foo(int x) => null; | 1732 int foo(int x) => null; |
| 1831 } | 1733 } |
| 1832 class B extends A { | 1734 class B extends A { |
| 1833 foo(x) => null; | 1735 foo(x) => null; |
| 1834 } | 1736 } |
| 1835 '''); | 1737 '''); |
| 1836 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); | 1738 AnalysisTarget lib1Target = new LibrarySpecificUnit(lib1Source, lib1Source); |
| 1837 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); | 1739 AnalysisTarget lib2Target = new LibrarySpecificUnit(lib2Source, lib2Source); |
| 1838 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); | 1740 AnalysisTarget lib3Target = new LibrarySpecificUnit(lib3Source, lib3Source); |
| 1839 | 1741 |
| 1840 computeResult(lib1Target, RESOLVED_UNIT); | 1742 computeResult(lib1Target, RESOLVED_UNIT); |
| 1841 computeResult(lib2Target, RESOLVED_UNIT); | 1743 computeResult(lib2Target, RESOLVED_UNIT); |
| 1842 computeResult(lib3Target, RESOLVED_UNIT); | 1744 computeResult(lib3Target, RESOLVED_UNIT); |
| 1843 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 1745 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 1844 ClassElement b = unit.declarations[1].element; | 1746 ClassElement b = unit.declarations[1].element; |
| 1845 expect(b.getMethod('foo').returnType.toString(), 'int'); | 1747 expect(b.getMethod('foo').returnType.toString(), 'int'); |
| 1846 | 1748 |
| 1847 // add a dummy edit. | 1749 // add a dummy edit. |
| 1848 context.setContents( | 1750 context.setContents(lib1Source, ''' |
| 1849 lib1Source, | |
| 1850 ''' | |
| 1851 library my_lib1; | 1751 library my_lib1; |
| 1852 import 'my_lib3.dart'; | 1752 import 'my_lib3.dart'; |
| 1853 var foo = 123; | 1753 var foo = 123; |
| 1854 '''); | 1754 '''); |
| 1855 _expectInvalid(lib1Source); | 1755 _expectInvalid(lib1Source); |
| 1856 _expectInvalid(lib2Source); | 1756 _expectInvalid(lib2Source); |
| 1857 _expectInvalid(lib3Source); | 1757 _expectInvalid(lib3Source); |
| 1858 | 1758 |
| 1859 computeResult(lib1Target, RESOLVED_UNIT); | 1759 computeResult(lib1Target, RESOLVED_UNIT); |
| 1860 computeResult(lib2Target, RESOLVED_UNIT); | 1760 computeResult(lib2Target, RESOLVED_UNIT); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1877 expect(component0, hasLength(1)); | 1777 expect(component0, hasLength(1)); |
| 1878 | 1778 |
| 1879 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); | 1779 List<LibrarySpecificUnit> units0 = getLibraryCycleUnits(results[0]); |
| 1880 expect(units0, hasLength(1)); | 1780 expect(units0, hasLength(1)); |
| 1881 | 1781 |
| 1882 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); | 1782 List<LibrarySpecificUnit> dep0 = getLibraryCycleDependencies(results[0]); |
| 1883 expect(dep0, hasLength(1)); // dart:core | 1783 expect(dep0, hasLength(1)); // dart:core |
| 1884 } | 1784 } |
| 1885 | 1785 |
| 1886 void test_library_cycle_singleton() { | 1786 void test_library_cycle_singleton() { |
| 1887 Source source = newSource( | 1787 Source source = newSource('/test.dart', ''' |
| 1888 '/test.dart', | |
| 1889 ''' | |
| 1890 import 'dart:core'; | 1788 import 'dart:core'; |
| 1891 '''); | 1789 '''); |
| 1892 computeResult(source, LIBRARY_CYCLE); | 1790 computeResult(source, LIBRARY_CYCLE); |
| 1893 List<LibraryElement> component = getLibraryCycle(outputs); | 1791 List<LibraryElement> component = getLibraryCycle(outputs); |
| 1894 List<LibrarySpecificUnit> units = getLibraryCycleUnits(outputs); | 1792 List<LibrarySpecificUnit> units = getLibraryCycleUnits(outputs); |
| 1895 List<LibrarySpecificUnit> deps = getLibraryCycleDependencies(outputs); | 1793 List<LibrarySpecificUnit> deps = getLibraryCycleDependencies(outputs); |
| 1896 expect(component, hasLength(1)); | 1794 expect(component, hasLength(1)); |
| 1897 expect(units, hasLength(1)); | 1795 expect(units, hasLength(1)); |
| 1898 expect(deps, hasLength(1)); | 1796 expect(deps, hasLength(1)); |
| 1899 } | 1797 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2138 List<AnalysisError> errors = getDartErrors(outputs); | 2036 List<AnalysisError> errors = getDartErrors(outputs); |
| 2139 // This should contain only the errors in the part file, not the ones in the | 2037 // This should contain only the errors in the part file, not the ones in the |
| 2140 // library. | 2038 // library. |
| 2141 expect(errors, hasLength(1)); | 2039 expect(errors, hasLength(1)); |
| 2142 } | 2040 } |
| 2143 } | 2041 } |
| 2144 | 2042 |
| 2145 @reflectiveTest | 2043 @reflectiveTest |
| 2146 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { | 2044 class EvaluateUnitConstantsTaskTest extends _AbstractDartTaskTest { |
| 2147 test_created_resolved_unit() { | 2045 test_created_resolved_unit() { |
| 2148 Source source = newSource( | 2046 Source source = newSource('/test.dart', r''' |
| 2149 '/test.dart', | |
| 2150 r''' | |
| 2151 library lib; | 2047 library lib; |
| 2152 class A {} | 2048 class A {} |
| 2153 '''); | 2049 '''); |
| 2154 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2050 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2155 computeResult(target, RESOLVED_UNIT12); | 2051 computeResult(target, RESOLVED_UNIT12); |
| 2156 expect(outputs[RESOLVED_UNIT12], isNotNull); | 2052 expect(outputs[RESOLVED_UNIT12], isNotNull); |
| 2157 expect(outputs[CREATED_RESOLVED_UNIT12], isTrue); | 2053 expect(outputs[CREATED_RESOLVED_UNIT12], isTrue); |
| 2158 } | 2054 } |
| 2159 | 2055 |
| 2160 test_perform() { | 2056 test_perform() { |
| 2161 Source source = newSource( | 2057 Source source = newSource('/test.dart', ''' |
| 2162 '/test.dart', | |
| 2163 ''' | |
| 2164 class C { | 2058 class C { |
| 2165 const C(); | 2059 const C(); |
| 2166 } | 2060 } |
| 2167 | 2061 |
| 2168 @x | 2062 @x |
| 2169 f() {} | 2063 f() {} |
| 2170 | 2064 |
| 2171 const x = const C(); | 2065 const x = const C(); |
| 2172 '''); | 2066 '''); |
| 2173 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2067 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2189 isNotNull); | 2083 isNotNull); |
| 2190 } | 2084 } |
| 2191 } | 2085 } |
| 2192 | 2086 |
| 2193 @reflectiveTest | 2087 @reflectiveTest |
| 2194 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { | 2088 class GatherUsedImportedElementsTaskTest extends _AbstractDartTaskTest { |
| 2195 UsedImportedElements usedElements; | 2089 UsedImportedElements usedElements; |
| 2196 Set<String> usedElementNames; | 2090 Set<String> usedElementNames; |
| 2197 | 2091 |
| 2198 test_perform_inBody() { | 2092 test_perform_inBody() { |
| 2199 newSource( | 2093 newSource('/a.dart', r''' |
| 2200 '/a.dart', | |
| 2201 r''' | |
| 2202 library lib_a; | 2094 library lib_a; |
| 2203 class A {} | 2095 class A {} |
| 2204 '''); | 2096 '''); |
| 2205 newSource( | 2097 newSource('/b.dart', r''' |
| 2206 '/b.dart', | |
| 2207 r''' | |
| 2208 library lib_b; | 2098 library lib_b; |
| 2209 class B {} | 2099 class B {} |
| 2210 '''); | 2100 '''); |
| 2211 Source source = newSource( | 2101 Source source = newSource('/test.dart', r''' |
| 2212 '/test.dart', | |
| 2213 r''' | |
| 2214 import 'a.dart'; | 2102 import 'a.dart'; |
| 2215 import 'b.dart'; | 2103 import 'b.dart'; |
| 2216 main() { | 2104 main() { |
| 2217 new A(); | 2105 new A(); |
| 2218 }'''); | 2106 }'''); |
| 2219 _computeUsedElements(source); | 2107 _computeUsedElements(source); |
| 2220 // validate | 2108 // validate |
| 2221 expect(usedElementNames, unorderedEquals(['A'])); | 2109 expect(usedElementNames, unorderedEquals(['A'])); |
| 2222 } | 2110 } |
| 2223 | 2111 |
| 2224 test_perform_inComment_exportDirective() { | 2112 test_perform_inComment_exportDirective() { |
| 2225 Source source = newSource( | 2113 Source source = newSource('/test.dart', r''' |
| 2226 '/test.dart', | |
| 2227 r''' | |
| 2228 import 'dart:async'; | 2114 import 'dart:async'; |
| 2229 /// Use [Future]. | 2115 /// Use [Future]. |
| 2230 export 'dart:math'; | 2116 export 'dart:math'; |
| 2231 '''); | 2117 '''); |
| 2232 _computeUsedElements(source); | 2118 _computeUsedElements(source); |
| 2233 expect(usedElementNames, unorderedEquals(['Future'])); | 2119 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2234 } | 2120 } |
| 2235 | 2121 |
| 2236 test_perform_inComment_importDirective() { | 2122 test_perform_inComment_importDirective() { |
| 2237 Source source = newSource( | 2123 Source source = newSource('/test.dart', r''' |
| 2238 '/test.dart', | |
| 2239 r''' | |
| 2240 import 'dart:async'; | 2124 import 'dart:async'; |
| 2241 /// Use [Future]. | 2125 /// Use [Future]. |
| 2242 import 'dart:math'; | 2126 import 'dart:math'; |
| 2243 '''); | 2127 '''); |
| 2244 _computeUsedElements(source); | 2128 _computeUsedElements(source); |
| 2245 expect(usedElementNames, unorderedEquals(['Future'])); | 2129 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2246 } | 2130 } |
| 2247 | 2131 |
| 2248 test_perform_inComment_libraryDirective() { | 2132 test_perform_inComment_libraryDirective() { |
| 2249 Source source = newSource( | 2133 Source source = newSource('/test.dart', r''' |
| 2250 '/test.dart', | |
| 2251 r''' | |
| 2252 /// Use [Future]. | 2134 /// Use [Future]. |
| 2253 library test; | 2135 library test; |
| 2254 import 'dart:async'; | 2136 import 'dart:async'; |
| 2255 '''); | 2137 '''); |
| 2256 _computeUsedElements(source); | 2138 _computeUsedElements(source); |
| 2257 expect(usedElementNames, unorderedEquals(['Future'])); | 2139 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2258 } | 2140 } |
| 2259 | 2141 |
| 2260 test_perform_inComment_topLevelFunction() { | 2142 test_perform_inComment_topLevelFunction() { |
| 2261 Source source = newSource( | 2143 Source source = newSource('/test.dart', r''' |
| 2262 '/test.dart', | |
| 2263 r''' | |
| 2264 import 'dart:async'; | 2144 import 'dart:async'; |
| 2265 /// Use [Future]. | 2145 /// Use [Future]. |
| 2266 main() {} | 2146 main() {} |
| 2267 '''); | 2147 '''); |
| 2268 _computeUsedElements(source); | 2148 _computeUsedElements(source); |
| 2269 expect(usedElementNames, unorderedEquals(['Future'])); | 2149 expect(usedElementNames, unorderedEquals(['Future'])); |
| 2270 } | 2150 } |
| 2271 | 2151 |
| 2272 void _computeUsedElements(Source source) { | 2152 void _computeUsedElements(Source source) { |
| 2273 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2153 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2274 computeResult(target, USED_IMPORTED_ELEMENTS, | 2154 computeResult(target, USED_IMPORTED_ELEMENTS, |
| 2275 matcher: isGatherUsedImportedElementsTask); | 2155 matcher: isGatherUsedImportedElementsTask); |
| 2276 usedElements = outputs[USED_IMPORTED_ELEMENTS]; | 2156 usedElements = outputs[USED_IMPORTED_ELEMENTS]; |
| 2277 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 2157 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 2278 } | 2158 } |
| 2279 } | 2159 } |
| 2280 | 2160 |
| 2281 @reflectiveTest | 2161 @reflectiveTest |
| 2282 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { | 2162 class GatherUsedLocalElementsTaskTest extends _AbstractDartTaskTest { |
| 2283 UsedLocalElements usedElements; | 2163 UsedLocalElements usedElements; |
| 2284 Set<String> usedElementNames; | 2164 Set<String> usedElementNames; |
| 2285 | 2165 |
| 2286 test_perform_forPart_afterLibraryUpdate() { | 2166 test_perform_forPart_afterLibraryUpdate() { |
| 2287 Source libSource = newSource( | 2167 Source libSource = newSource('/my_lib.dart', ''' |
| 2288 '/my_lib.dart', | |
| 2289 ''' | |
| 2290 library my_lib; | 2168 library my_lib; |
| 2291 part 'my_part.dart'; | 2169 part 'my_part.dart'; |
| 2292 foo() => null; | 2170 foo() => null; |
| 2293 class _LocalClass {} | 2171 class _LocalClass {} |
| 2294 '''); | 2172 '''); |
| 2295 Source partSource = newSource( | 2173 Source partSource = newSource('/my_part.dart', ''' |
| 2296 '/my_part.dart', | |
| 2297 ''' | |
| 2298 part of my_lib; | 2174 part of my_lib; |
| 2299 bar() { | 2175 bar() { |
| 2300 print(_LocalClass); | 2176 print(_LocalClass); |
| 2301 } | 2177 } |
| 2302 '''); | 2178 '''); |
| 2303 AnalysisTarget libTarget = new LibrarySpecificUnit(libSource, libSource); | 2179 AnalysisTarget libTarget = new LibrarySpecificUnit(libSource, libSource); |
| 2304 AnalysisTarget partTarget = new LibrarySpecificUnit(libSource, partSource); | 2180 AnalysisTarget partTarget = new LibrarySpecificUnit(libSource, partSource); |
| 2305 computeResult(libTarget, USED_LOCAL_ELEMENTS); | 2181 computeResult(libTarget, USED_LOCAL_ELEMENTS); |
| 2306 computeResult(partTarget, USED_LOCAL_ELEMENTS); | 2182 computeResult(partTarget, USED_LOCAL_ELEMENTS); |
| 2307 // _LocalClass is used in my_part.dart | 2183 // _LocalClass is used in my_part.dart |
| 2308 { | 2184 { |
| 2309 UsedLocalElements usedElements = | 2185 UsedLocalElements usedElements = |
| 2310 analysisCache.getValue(partTarget, USED_LOCAL_ELEMENTS); | 2186 analysisCache.getValue(partTarget, USED_LOCAL_ELEMENTS); |
| 2311 expect(usedElements.elements, contains(predicate((Element e) { | 2187 expect(usedElements.elements, contains(predicate((Element e) { |
| 2312 return e.displayName == '_LocalClass'; | 2188 return e.displayName == '_LocalClass'; |
| 2313 }))); | 2189 }))); |
| 2314 } | 2190 } |
| 2315 // change my_lib.dart and recompute | 2191 // change my_lib.dart and recompute |
| 2316 context.setContents( | 2192 context.setContents(libSource, ''' |
| 2317 libSource, | |
| 2318 ''' | |
| 2319 library my_lib; | 2193 library my_lib; |
| 2320 part 'my_part.dart'; | 2194 part 'my_part.dart'; |
| 2321 String foo() => null; | 2195 String foo() => null; |
| 2322 class _LocalClass {} | 2196 class _LocalClass {} |
| 2323 '''); | 2197 '''); |
| 2324 computeResult(libTarget, USED_LOCAL_ELEMENTS); | 2198 computeResult(libTarget, USED_LOCAL_ELEMENTS); |
| 2325 computeResult(partTarget, USED_LOCAL_ELEMENTS); | 2199 computeResult(partTarget, USED_LOCAL_ELEMENTS); |
| 2326 // _LocalClass should still be used in my_part.dart | 2200 // _LocalClass should still be used in my_part.dart |
| 2327 { | 2201 { |
| 2328 UsedLocalElements usedElements = | 2202 UsedLocalElements usedElements = |
| 2329 analysisCache.getValue(partTarget, USED_LOCAL_ELEMENTS); | 2203 analysisCache.getValue(partTarget, USED_LOCAL_ELEMENTS); |
| 2330 expect(usedElements.elements, contains(predicate((Element e) { | 2204 expect(usedElements.elements, contains(predicate((Element e) { |
| 2331 return e.displayName == '_LocalClass'; | 2205 return e.displayName == '_LocalClass'; |
| 2332 }))); | 2206 }))); |
| 2333 } | 2207 } |
| 2334 } | 2208 } |
| 2335 | 2209 |
| 2336 test_perform_localVariable() { | 2210 test_perform_localVariable() { |
| 2337 Source source = newSource( | 2211 Source source = newSource('/test.dart', r''' |
| 2338 '/test.dart', | |
| 2339 r''' | |
| 2340 main() { | 2212 main() { |
| 2341 var v1 = 1; | 2213 var v1 = 1; |
| 2342 var v2 = 2; | 2214 var v2 = 2; |
| 2343 print(v2); | 2215 print(v2); |
| 2344 }'''); | 2216 }'''); |
| 2345 _computeUsedElements(source); | 2217 _computeUsedElements(source); |
| 2346 // validate | 2218 // validate |
| 2347 expect(usedElementNames, unorderedEquals(['v2'])); | 2219 expect(usedElementNames, unorderedEquals(['v2'])); |
| 2348 } | 2220 } |
| 2349 | 2221 |
| 2350 test_perform_method() { | 2222 test_perform_method() { |
| 2351 Source source = newSource( | 2223 Source source = newSource('/test.dart', r''' |
| 2352 '/test.dart', | |
| 2353 r''' | |
| 2354 class A { | 2224 class A { |
| 2355 _m1() {} | 2225 _m1() {} |
| 2356 _m2() {} | 2226 _m2() {} |
| 2357 } | 2227 } |
| 2358 | 2228 |
| 2359 main(A a, p) { | 2229 main(A a, p) { |
| 2360 a._m2(); | 2230 a._m2(); |
| 2361 p._m3(); | 2231 p._m3(); |
| 2362 } | 2232 } |
| 2363 '''); | 2233 '''); |
| 2364 _computeUsedElements(source); | 2234 _computeUsedElements(source); |
| 2365 // validate | 2235 // validate |
| 2366 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); | 2236 expect(usedElementNames, unorderedEquals(['A', 'a', 'p', '_m2'])); |
| 2367 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); | 2237 expect(usedElements.members, unorderedEquals(['_m2', '_m3'])); |
| 2368 } | 2238 } |
| 2369 | 2239 |
| 2370 void _computeUsedElements(Source source) { | 2240 void _computeUsedElements(Source source) { |
| 2371 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2241 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2372 computeResult(target, USED_LOCAL_ELEMENTS, | 2242 computeResult(target, USED_LOCAL_ELEMENTS, |
| 2373 matcher: isGatherUsedLocalElementsTask); | 2243 matcher: isGatherUsedLocalElementsTask); |
| 2374 usedElements = outputs[USED_LOCAL_ELEMENTS]; | 2244 usedElements = outputs[USED_LOCAL_ELEMENTS]; |
| 2375 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); | 2245 usedElementNames = usedElements.elements.map((e) => e.name).toSet(); |
| 2376 } | 2246 } |
| 2377 } | 2247 } |
| 2378 | 2248 |
| 2379 @reflectiveTest | 2249 @reflectiveTest |
| 2380 class GenerateHintsTaskTest extends _AbstractDartTaskTest { | 2250 class GenerateHintsTaskTest extends _AbstractDartTaskTest { |
| 2381 test_perform_bestPractices_missingReturn() { | 2251 test_perform_bestPractices_missingReturn() { |
| 2382 Source source = newSource( | 2252 Source source = newSource('/test.dart', ''' |
| 2383 '/test.dart', | |
| 2384 ''' | |
| 2385 int main() { | 2253 int main() { |
| 2386 } | 2254 } |
| 2387 '''); | 2255 '''); |
| 2388 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2256 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2389 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2257 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2390 // validate | 2258 // validate |
| 2391 _fillErrorListener(HINTS); | 2259 _fillErrorListener(HINTS); |
| 2392 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); | 2260 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.MISSING_RETURN]); |
| 2393 } | 2261 } |
| 2394 | 2262 |
| 2395 test_perform_dart2js() { | 2263 test_perform_dart2js() { |
| 2396 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 2264 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 2397 options.dart2jsHint = true; | 2265 options.dart2jsHint = true; |
| 2398 prepareAnalysisContext(options); | 2266 prepareAnalysisContext(options); |
| 2399 Source source = newSource( | 2267 Source source = newSource('/test.dart', ''' |
| 2400 '/test.dart', | |
| 2401 ''' | |
| 2402 main(p) { | 2268 main(p) { |
| 2403 if (p is double) { | 2269 if (p is double) { |
| 2404 print('double'); | 2270 print('double'); |
| 2405 } | 2271 } |
| 2406 } | 2272 } |
| 2407 '''); | 2273 '''); |
| 2408 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2274 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2409 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2275 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2410 // validate | 2276 // validate |
| 2411 _fillErrorListener(HINTS); | 2277 _fillErrorListener(HINTS); |
| 2412 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); | 2278 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.IS_DOUBLE]); |
| 2413 } | 2279 } |
| 2414 | 2280 |
| 2415 test_perform_deadCode() { | 2281 test_perform_deadCode() { |
| 2416 Source source = newSource( | 2282 Source source = newSource('/test.dart', ''' |
| 2417 '/test.dart', | |
| 2418 ''' | |
| 2419 main() { | 2283 main() { |
| 2420 if (false) { | 2284 if (false) { |
| 2421 print('how?'); | 2285 print('how?'); |
| 2422 } | 2286 } |
| 2423 } | 2287 } |
| 2424 '''); | 2288 '''); |
| 2425 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2289 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2426 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2290 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2427 // validate | 2291 // validate |
| 2428 _fillErrorListener(HINTS); | 2292 _fillErrorListener(HINTS); |
| 2429 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); | 2293 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DEAD_CODE]); |
| 2430 } | 2294 } |
| 2431 | 2295 |
| 2432 test_perform_disabled() { | 2296 test_perform_disabled() { |
| 2433 context.analysisOptions = | 2297 context.analysisOptions = |
| 2434 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false; | 2298 new AnalysisOptionsImpl.from(context.analysisOptions)..hint = false; |
| 2435 Source source = newSource( | 2299 Source source = newSource('/test.dart', ''' |
| 2436 '/test.dart', | |
| 2437 ''' | |
| 2438 int main() { | 2300 int main() { |
| 2439 } | 2301 } |
| 2440 '''); | 2302 '''); |
| 2441 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2303 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2442 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2304 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2443 // validate | 2305 // validate |
| 2444 _fillErrorListener(HINTS); | 2306 _fillErrorListener(HINTS); |
| 2445 errorListener.assertNoErrors(); | 2307 errorListener.assertNoErrors(); |
| 2446 } | 2308 } |
| 2447 | 2309 |
| 2448 test_perform_imports_duplicateImport() { | 2310 test_perform_imports_duplicateImport() { |
| 2449 newSource( | 2311 newSource('/a.dart', r''' |
| 2450 '/a.dart', | |
| 2451 r''' | |
| 2452 library lib_a; | 2312 library lib_a; |
| 2453 class A {} | 2313 class A {} |
| 2454 '''); | 2314 '''); |
| 2455 Source source = newSource( | 2315 Source source = newSource('/test.dart', r''' |
| 2456 '/test.dart', | |
| 2457 r''' | |
| 2458 import 'a.dart'; | 2316 import 'a.dart'; |
| 2459 import 'a.dart'; | 2317 import 'a.dart'; |
| 2460 main() { | 2318 main() { |
| 2461 new A(); | 2319 new A(); |
| 2462 } | 2320 } |
| 2463 '''); | 2321 '''); |
| 2464 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2322 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2465 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2323 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2466 // validate | 2324 // validate |
| 2467 _fillErrorListener(HINTS); | 2325 _fillErrorListener(HINTS); |
| 2468 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); | 2326 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.DUPLICATE_IMPORT]); |
| 2469 } | 2327 } |
| 2470 | 2328 |
| 2471 test_perform_imports_unusedImport_one() { | 2329 test_perform_imports_unusedImport_one() { |
| 2472 newSource( | 2330 newSource('/a.dart', r''' |
| 2473 '/a.dart', | |
| 2474 r''' | |
| 2475 library lib_a; | 2331 library lib_a; |
| 2476 class A {} | 2332 class A {} |
| 2477 '''); | 2333 '''); |
| 2478 newSource( | 2334 newSource('/b.dart', r''' |
| 2479 '/b.dart', | |
| 2480 r''' | |
| 2481 library lib_b; | 2335 library lib_b; |
| 2482 class B {} | 2336 class B {} |
| 2483 '''); | 2337 '''); |
| 2484 Source source = newSource( | 2338 Source source = newSource('/test.dart', r''' |
| 2485 '/test.dart', | |
| 2486 r''' | |
| 2487 import 'a.dart'; | 2339 import 'a.dart'; |
| 2488 import 'b.dart'; | 2340 import 'b.dart'; |
| 2489 main() { | 2341 main() { |
| 2490 new A(); | 2342 new A(); |
| 2491 }'''); | 2343 }'''); |
| 2492 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2344 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2493 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2345 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2494 // validate | 2346 // validate |
| 2495 _fillErrorListener(HINTS); | 2347 _fillErrorListener(HINTS); |
| 2496 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); | 2348 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_IMPORT]); |
| 2497 } | 2349 } |
| 2498 | 2350 |
| 2499 test_perform_imports_unusedImport_zero() { | 2351 test_perform_imports_unusedImport_zero() { |
| 2500 newSource( | 2352 newSource('/a.dart', r''' |
| 2501 '/a.dart', | |
| 2502 r''' | |
| 2503 library lib_a; | 2353 library lib_a; |
| 2504 class A {} | 2354 class A {} |
| 2505 '''); | 2355 '''); |
| 2506 Source source = newSource( | 2356 Source source = newSource('/test.dart', r''' |
| 2507 '/test.dart', | |
| 2508 r''' | |
| 2509 import 'a.dart'; | 2357 import 'a.dart'; |
| 2510 main() { | 2358 main() { |
| 2511 new A(); | 2359 new A(); |
| 2512 }'''); | 2360 }'''); |
| 2513 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2361 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2514 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2362 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2515 // validate | 2363 // validate |
| 2516 _fillErrorListener(HINTS); | 2364 _fillErrorListener(HINTS); |
| 2517 errorListener.assertNoErrors(); | 2365 errorListener.assertNoErrors(); |
| 2518 } | 2366 } |
| 2519 | 2367 |
| 2520 test_perform_overrideVerifier() { | 2368 test_perform_overrideVerifier() { |
| 2521 Source source = newSource( | 2369 Source source = newSource('/test.dart', ''' |
| 2522 '/test.dart', | |
| 2523 ''' | |
| 2524 class A {} | 2370 class A {} |
| 2525 class B { | 2371 class B { |
| 2526 @override | 2372 @override |
| 2527 m() {} | 2373 m() {} |
| 2528 } | 2374 } |
| 2529 '''); | 2375 '''); |
| 2530 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2376 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2531 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2377 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2532 // validate | 2378 // validate |
| 2533 _fillErrorListener(HINTS); | 2379 _fillErrorListener(HINTS); |
| 2534 errorListener.assertErrorsWithCodes( | 2380 errorListener.assertErrorsWithCodes( |
| 2535 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); | 2381 <ErrorCode>[HintCode.OVERRIDE_ON_NON_OVERRIDING_METHOD]); |
| 2536 } | 2382 } |
| 2537 | 2383 |
| 2538 test_perform_todo() { | 2384 test_perform_todo() { |
| 2539 Source source = newSource( | 2385 Source source = newSource('/test.dart', ''' |
| 2540 '/test.dart', | |
| 2541 ''' | |
| 2542 main() { | 2386 main() { |
| 2543 // TODO(developer) foo bar | 2387 // TODO(developer) foo bar |
| 2544 } | 2388 } |
| 2545 '''); | 2389 '''); |
| 2546 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2390 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2547 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2391 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2548 // validate | 2392 // validate |
| 2549 _fillErrorListener(HINTS); | 2393 _fillErrorListener(HINTS); |
| 2550 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); | 2394 errorListener.assertErrorsWithCodes(<ErrorCode>[TodoCode.TODO]); |
| 2551 } | 2395 } |
| 2552 | 2396 |
| 2553 test_perform_unusedLocalElements_class() { | 2397 test_perform_unusedLocalElements_class() { |
| 2554 Source source = newSource( | 2398 Source source = newSource('/test.dart', ''' |
| 2555 '/test.dart', | |
| 2556 ''' | |
| 2557 class _A {} | 2399 class _A {} |
| 2558 class _B {} | 2400 class _B {} |
| 2559 main() { | 2401 main() { |
| 2560 new _A(); | 2402 new _A(); |
| 2561 } | 2403 } |
| 2562 '''); | 2404 '''); |
| 2563 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2405 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2564 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2406 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2565 // validate | 2407 // validate |
| 2566 _fillErrorListener(HINTS); | 2408 _fillErrorListener(HINTS); |
| 2567 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); | 2409 errorListener.assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_ELEMENT]); |
| 2568 } | 2410 } |
| 2569 | 2411 |
| 2570 test_perform_unusedLocalElements_localVariable() { | 2412 test_perform_unusedLocalElements_localVariable() { |
| 2571 Source source = newSource( | 2413 Source source = newSource('/test.dart', ''' |
| 2572 '/test.dart', | |
| 2573 ''' | |
| 2574 main() { | 2414 main() { |
| 2575 var v = 42; | 2415 var v = 42; |
| 2576 } | 2416 } |
| 2577 '''); | 2417 '''); |
| 2578 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2418 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2579 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2419 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2580 // validate | 2420 // validate |
| 2581 _fillErrorListener(HINTS); | 2421 _fillErrorListener(HINTS); |
| 2582 errorListener | 2422 errorListener |
| 2583 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); | 2423 .assertErrorsWithCodes(<ErrorCode>[HintCode.UNUSED_LOCAL_VARIABLE]); |
| 2584 } | 2424 } |
| 2585 | 2425 |
| 2586 test_perform_unusedLocalElements_method() { | 2426 test_perform_unusedLocalElements_method() { |
| 2587 Source source = newSource( | 2427 Source source = newSource('/my_lib.dart', ''' |
| 2588 '/my_lib.dart', | |
| 2589 ''' | |
| 2590 library my_lib; | 2428 library my_lib; |
| 2591 part 'my_part.dart'; | 2429 part 'my_part.dart'; |
| 2592 class A { | 2430 class A { |
| 2593 _ma() {} | 2431 _ma() {} |
| 2594 _mb() {} | 2432 _mb() {} |
| 2595 _mc() {} | 2433 _mc() {} |
| 2596 } | 2434 } |
| 2597 '''); | 2435 '''); |
| 2598 newSource( | 2436 newSource('/my_part.dart', ''' |
| 2599 '/my_part.dart', | |
| 2600 ''' | |
| 2601 part of my_lib; | 2437 part of my_lib; |
| 2602 | 2438 |
| 2603 f(A a) { | 2439 f(A a) { |
| 2604 a._mb(); | 2440 a._mb(); |
| 2605 } | 2441 } |
| 2606 '''); | 2442 '''); |
| 2607 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2443 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2608 computeResult(target, HINTS, matcher: isGenerateHintsTask); | 2444 computeResult(target, HINTS, matcher: isGenerateHintsTask); |
| 2609 // validate | 2445 // validate |
| 2610 _fillErrorListener(HINTS); | 2446 _fillErrorListener(HINTS); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2628 setLints(context, [new GenerateLintsTaskTest_TestLinter()]); | 2464 setLints(context, [new GenerateLintsTaskTest_TestLinter()]); |
| 2629 } | 2465 } |
| 2630 | 2466 |
| 2631 @override | 2467 @override |
| 2632 void tearDown() { | 2468 void tearDown() { |
| 2633 setLints(context, []); | 2469 setLints(context, []); |
| 2634 super.tearDown(); | 2470 super.tearDown(); |
| 2635 } | 2471 } |
| 2636 | 2472 |
| 2637 test_camel_case_types() { | 2473 test_camel_case_types() { |
| 2638 Source source = newSource( | 2474 Source source = newSource('/test.dart', ''' |
| 2639 '/test.dart', | |
| 2640 ''' | |
| 2641 class a { } | 2475 class a { } |
| 2642 '''); | 2476 '''); |
| 2643 | 2477 |
| 2644 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2478 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2645 computeResult(target, LINTS, matcher: isGenerateLintsTask); | 2479 computeResult(target, LINTS, matcher: isGenerateLintsTask); |
| 2646 // validate | 2480 // validate |
| 2647 _fillErrorListener(LINTS); | 2481 _fillErrorListener(LINTS); |
| 2648 errorListener.assertErrorsWithCodes(<ErrorCode>[_testLintCode]); | 2482 errorListener.assertErrorsWithCodes(<ErrorCode>[_testLintCode]); |
| 2649 } | 2483 } |
| 2650 } | 2484 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2666 @override | 2500 @override |
| 2667 String get name => 'GenerateLintsTaskTest_TestLinter'; | 2501 String get name => 'GenerateLintsTaskTest_TestLinter'; |
| 2668 | 2502 |
| 2669 @override | 2503 @override |
| 2670 AstVisitor getVisitor() => new GenerateLintsTaskTest_AstVisitor(this); | 2504 AstVisitor getVisitor() => new GenerateLintsTaskTest_AstVisitor(this); |
| 2671 } | 2505 } |
| 2672 | 2506 |
| 2673 @reflectiveTest | 2507 @reflectiveTest |
| 2674 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { | 2508 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { |
| 2675 test_created_resolved_unit() { | 2509 test_created_resolved_unit() { |
| 2676 Source source = newSource( | 2510 Source source = newSource('/test.dart', r''' |
| 2677 '/test.dart', | |
| 2678 r''' | |
| 2679 library lib; | 2511 library lib; |
| 2680 class A {} | 2512 class A {} |
| 2681 '''); | 2513 '''); |
| 2682 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2514 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2683 computeResult(target, RESOLVED_UNIT10); | 2515 computeResult(target, RESOLVED_UNIT10); |
| 2684 expect(outputs[RESOLVED_UNIT10], isNotNull); | 2516 expect(outputs[RESOLVED_UNIT10], isNotNull); |
| 2685 expect(outputs[CREATED_RESOLVED_UNIT10], isTrue); | 2517 expect(outputs[CREATED_RESOLVED_UNIT10], isTrue); |
| 2686 } | 2518 } |
| 2687 | 2519 |
| 2688 void test_perform() { | 2520 void test_perform() { |
| 2689 enableStrongMode(); | 2521 enableStrongMode(); |
| 2690 AnalysisTarget source = newSource( | 2522 AnalysisTarget source = newSource('/test.dart', ''' |
| 2691 '/test.dart', | |
| 2692 ''' | |
| 2693 class A { | 2523 class A { |
| 2694 X f; | 2524 X f; |
| 2695 Y m(Z x) {} | 2525 Y m(Z x) {} |
| 2696 } | 2526 } |
| 2697 class B extends A { | 2527 class B extends A { |
| 2698 var f; | 2528 var f; |
| 2699 m(x) {} | 2529 m(x) {} |
| 2700 } | 2530 } |
| 2701 class X {} | 2531 class X {} |
| 2702 class Y {} | 2532 class Y {} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2724 expect( | 2554 expect( |
| 2725 resolutionMap | 2555 resolutionMap |
| 2726 .elementDeclaredByMethodDeclaration(method) | 2556 .elementDeclaredByMethodDeclaration(method) |
| 2727 .parameters[0] | 2557 .parameters[0] |
| 2728 .type, | 2558 .type, |
| 2729 typeZ); | 2559 typeZ); |
| 2730 } | 2560 } |
| 2731 | 2561 |
| 2732 void test_perform_cross_library_const() { | 2562 void test_perform_cross_library_const() { |
| 2733 enableStrongMode(); | 2563 enableStrongMode(); |
| 2734 AnalysisTarget firstSource = newSource( | 2564 AnalysisTarget firstSource = newSource('/first.dart', ''' |
| 2735 '/first.dart', | |
| 2736 ''' | |
| 2737 library first; | 2565 library first; |
| 2738 | 2566 |
| 2739 const a = 'hello'; | 2567 const a = 'hello'; |
| 2740 '''); | 2568 '''); |
| 2741 AnalysisTarget secondSource = newSource( | 2569 AnalysisTarget secondSource = newSource('/second.dart', ''' |
| 2742 '/second.dart', | |
| 2743 ''' | |
| 2744 import 'first.dart'; | 2570 import 'first.dart'; |
| 2745 | 2571 |
| 2746 const b = a; | 2572 const b = a; |
| 2747 class M { | 2573 class M { |
| 2748 String c = a; | 2574 String c = a; |
| 2749 } | 2575 } |
| 2750 '''); | 2576 '''); |
| 2751 computeResult( | 2577 computeResult( |
| 2752 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10, | 2578 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT10, |
| 2753 matcher: isInferInstanceMembersInUnitTask); | 2579 matcher: isInferInstanceMembersInUnitTask); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2769 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableB).type, | 2595 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableB).type, |
| 2770 stringType); | 2596 stringType); |
| 2771 expect(variableB.initializer.staticType, stringType); | 2597 expect(variableB.initializer.staticType, stringType); |
| 2772 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableC).type, | 2598 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableC).type, |
| 2773 stringType); | 2599 stringType); |
| 2774 expect(variableC.initializer.staticType, stringType); | 2600 expect(variableC.initializer.staticType, stringType); |
| 2775 } | 2601 } |
| 2776 | 2602 |
| 2777 void test_perform_reresolution() { | 2603 void test_perform_reresolution() { |
| 2778 enableStrongMode(); | 2604 enableStrongMode(); |
| 2779 AnalysisTarget source = newSource( | 2605 AnalysisTarget source = newSource('/test.dart', ''' |
| 2780 '/test.dart', | |
| 2781 ''' | |
| 2782 const topLevel = ''; | 2606 const topLevel = ''; |
| 2783 class C { | 2607 class C { |
| 2784 String field = topLevel; | 2608 String field = topLevel; |
| 2785 } | 2609 } |
| 2786 '''); | 2610 '''); |
| 2787 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); | 2611 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT10); |
| 2788 CompilationUnit unit = outputs[RESOLVED_UNIT10]; | 2612 CompilationUnit unit = outputs[RESOLVED_UNIT10]; |
| 2789 VariableDeclaration topLevelDecl = | 2613 VariableDeclaration topLevelDecl = |
| 2790 AstFinder.getTopLevelVariable(unit, 'topLevel'); | 2614 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2791 VariableDeclaration fieldDecl = | 2615 VariableDeclaration fieldDecl = |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2802 | 2626 |
| 2803 @reflectiveTest | 2627 @reflectiveTest |
| 2804 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { | 2628 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { |
| 2805 @override | 2629 @override |
| 2806 void setUp() { | 2630 void setUp() { |
| 2807 super.setUp(); | 2631 super.setUp(); |
| 2808 enableStrongMode(); | 2632 enableStrongMode(); |
| 2809 } | 2633 } |
| 2810 | 2634 |
| 2811 test_created_resolved_unit() { | 2635 test_created_resolved_unit() { |
| 2812 Source source = newSource( | 2636 Source source = newSource('/test.dart', r''' |
| 2813 '/test.dart', | |
| 2814 r''' | |
| 2815 library lib; | 2637 library lib; |
| 2816 class A {} | 2638 class A {} |
| 2817 '''); | 2639 '''); |
| 2818 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2640 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2819 computeResult(target, RESOLVED_UNIT8); | 2641 computeResult(target, RESOLVED_UNIT8); |
| 2820 expect(outputs[RESOLVED_UNIT8], isNotNull); | 2642 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2821 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); | 2643 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2822 } | 2644 } |
| 2823 | 2645 |
| 2824 void test_perform_const_field() { | 2646 void test_perform_const_field() { |
| 2825 enableStrongMode(); | 2647 enableStrongMode(); |
| 2826 AnalysisTarget source = newSource( | 2648 AnalysisTarget source = newSource('/test.dart', ''' |
| 2827 '/test.dart', | |
| 2828 ''' | |
| 2829 class M { | 2649 class M { |
| 2830 static const X = ""; | 2650 static const X = ""; |
| 2831 } | 2651 } |
| 2832 '''); | 2652 '''); |
| 2833 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, | 2653 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2834 matcher: isInferStaticVariableTypesInUnitTask); | 2654 matcher: isInferStaticVariableTypesInUnitTask); |
| 2835 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2655 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2836 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); | 2656 VariableDeclaration declaration = AstFinder.getFieldInClass(unit, 'M', 'X'); |
| 2837 InterfaceType stringType = context.typeProvider.stringType; | 2657 InterfaceType stringType = context.typeProvider.stringType; |
| 2838 expect(resolutionMap.elementDeclaredByVariableDeclaration(declaration).type, | 2658 expect(resolutionMap.elementDeclaredByVariableDeclaration(declaration).type, |
| 2839 stringType); | 2659 stringType); |
| 2840 } | 2660 } |
| 2841 | 2661 |
| 2842 test_perform_hasParseError() { | 2662 test_perform_hasParseError() { |
| 2843 Source source = newSource( | 2663 Source source = newSource('/test.dart', r''' |
| 2844 '/test.dart', | |
| 2845 r''' | |
| 2846 @(i $= | 2664 @(i $= |
| 2847 '''); | 2665 '''); |
| 2848 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2666 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2849 computeResult(target, RESOLVED_UNIT8); | 2667 computeResult(target, RESOLVED_UNIT8); |
| 2850 expect(outputs[RESOLVED_UNIT8], isNotNull); | 2668 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2851 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); | 2669 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2852 } | 2670 } |
| 2853 | 2671 |
| 2854 void test_perform_nestedDeclarations() { | 2672 void test_perform_nestedDeclarations() { |
| 2855 enableStrongMode(); | 2673 enableStrongMode(); |
| 2856 AnalysisTarget source = newSource( | 2674 AnalysisTarget source = newSource('/test.dart', ''' |
| 2857 '/test.dart', | |
| 2858 ''' | |
| 2859 var f = (int x) { | 2675 var f = (int x) { |
| 2860 int squared(int value) => value * value; | 2676 int squared(int value) => value * value; |
| 2861 var xSquared = squared(x); | 2677 var xSquared = squared(x); |
| 2862 return xSquared; | 2678 return xSquared; |
| 2863 }; | 2679 }; |
| 2864 '''); | 2680 '''); |
| 2865 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, | 2681 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2866 matcher: isInferStaticVariableTypesInUnitTask); | 2682 matcher: isInferStaticVariableTypesInUnitTask); |
| 2867 } | 2683 } |
| 2868 | 2684 |
| 2869 void test_perform_recursive() { | 2685 void test_perform_recursive() { |
| 2870 enableStrongMode(); | 2686 enableStrongMode(); |
| 2871 AnalysisTarget firstSource = newSource( | 2687 AnalysisTarget firstSource = newSource('/first.dart', ''' |
| 2872 '/first.dart', | |
| 2873 ''' | |
| 2874 import 'second.dart'; | 2688 import 'second.dart'; |
| 2875 | 2689 |
| 2876 var a = new M(); | 2690 var a = new M(); |
| 2877 var c = b; | 2691 var c = b; |
| 2878 '''); | 2692 '''); |
| 2879 AnalysisTarget secondSource = newSource( | 2693 AnalysisTarget secondSource = newSource('/second.dart', ''' |
| 2880 '/second.dart', | |
| 2881 ''' | |
| 2882 import 'first.dart'; | 2694 import 'first.dart'; |
| 2883 | 2695 |
| 2884 var b = a; | 2696 var b = a; |
| 2885 class M {} | 2697 class M {} |
| 2886 '''); | 2698 '''); |
| 2887 computeResult( | 2699 computeResult( |
| 2888 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, | 2700 new LibrarySpecificUnit(firstSource, firstSource), RESOLVED_UNIT8, |
| 2889 matcher: isInferStaticVariableTypesInUnitTask); | 2701 matcher: isInferStaticVariableTypesInUnitTask); |
| 2890 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; | 2702 CompilationUnit firstUnit = outputs[RESOLVED_UNIT8]; |
| 2891 computeResult( | 2703 computeResult( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2907 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableB).type, | 2719 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableB).type, |
| 2908 typeM); | 2720 typeM); |
| 2909 expect(variableB.initializer.staticType, typeM); | 2721 expect(variableB.initializer.staticType, typeM); |
| 2910 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableC).type, | 2722 expect(resolutionMap.elementDeclaredByVariableDeclaration(variableC).type, |
| 2911 typeM); | 2723 typeM); |
| 2912 expect(variableC.initializer.staticType, typeM); | 2724 expect(variableC.initializer.staticType, typeM); |
| 2913 } | 2725 } |
| 2914 | 2726 |
| 2915 void test_perform_simple() { | 2727 void test_perform_simple() { |
| 2916 enableStrongMode(); | 2728 enableStrongMode(); |
| 2917 AnalysisTarget source = newSource( | 2729 AnalysisTarget source = newSource('/test.dart', ''' |
| 2918 '/test.dart', | |
| 2919 ''' | |
| 2920 var X = 1; | 2730 var X = 1; |
| 2921 var Y = () => 1 + X; | 2731 var Y = () => 1 + X; |
| 2922 '''); | 2732 '''); |
| 2923 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, | 2733 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT8, |
| 2924 matcher: isInferStaticVariableTypesInUnitTask); | 2734 matcher: isInferStaticVariableTypesInUnitTask); |
| 2925 CompilationUnit unit = outputs[RESOLVED_UNIT8]; | 2735 CompilationUnit unit = outputs[RESOLVED_UNIT8]; |
| 2926 TopLevelVariableDeclaration declaration = unit.declarations[1]; | 2736 TopLevelVariableDeclaration declaration = unit.declarations[1]; |
| 2927 FunctionExpression function = | 2737 FunctionExpression function = |
| 2928 declaration.variables.variables[0].initializer; | 2738 declaration.variables.variables[0].initializer; |
| 2929 ExpressionFunctionBody body = function.body; | 2739 ExpressionFunctionBody body = function.body; |
| 2930 Expression expression = body.expression; | 2740 Expression expression = body.expression; |
| 2931 InterfaceType intType = context.typeProvider.intType; | 2741 InterfaceType intType = context.typeProvider.intType; |
| 2932 expect(expression.staticType, intType); | 2742 expect(expression.staticType, intType); |
| 2933 } | 2743 } |
| 2934 | 2744 |
| 2935 test_staticModeHints_forStaticVariableInference() { | 2745 test_staticModeHints_forStaticVariableInference() { |
| 2936 context.analysisOptions = | 2746 context.analysisOptions = |
| 2937 new AnalysisOptionsImpl.from(context.analysisOptions) | 2747 new AnalysisOptionsImpl.from(context.analysisOptions) |
| 2938 ..strongModeHints = true; | 2748 ..strongModeHints = true; |
| 2939 Source source = newSource( | 2749 Source source = newSource('/test.dart', r''' |
| 2940 '/test.dart', | |
| 2941 r''' | |
| 2942 var V = [42]; | 2750 var V = [42]; |
| 2943 '''); | 2751 '''); |
| 2944 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2752 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2945 computeResult(target, RESOLVED_UNIT8); | 2753 computeResult(target, RESOLVED_UNIT8); |
| 2946 expect(outputs[RESOLVED_UNIT8], isNotNull); | 2754 expect(outputs[RESOLVED_UNIT8], isNotNull); |
| 2947 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); | 2755 expect(outputs[CREATED_RESOLVED_UNIT8], isTrue); |
| 2948 // An INFERRED_TYPE_LITERAL error should be generated. | 2756 // An INFERRED_TYPE_LITERAL error should be generated. |
| 2949 List<AnalysisError> errors = | 2757 List<AnalysisError> errors = |
| 2950 outputs[STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] | 2758 outputs[STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] |
| 2951 as List<AnalysisError>; | 2759 as List<AnalysisError>; |
| 2952 expect(errors, hasLength(1)); | 2760 expect(errors, hasLength(1)); |
| 2953 expect(errors[0].errorCode, StrongModeCode.INFERRED_TYPE_LITERAL); | 2761 expect(errors[0].errorCode, StrongModeCode.INFERRED_TYPE_LITERAL); |
| 2954 } | 2762 } |
| 2955 } | 2763 } |
| 2956 | 2764 |
| 2957 @reflectiveTest | 2765 @reflectiveTest |
| 2958 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { | 2766 class InferStaticVariableTypeTaskTest extends _AbstractDartTaskTest { |
| 2959 void test_getDeclaration_staticField() { | 2767 void test_getDeclaration_staticField() { |
| 2960 AnalysisTarget source = newSource( | 2768 AnalysisTarget source = newSource('/test.dart', ''' |
| 2961 '/test.dart', | |
| 2962 ''' | |
| 2963 class C { | 2769 class C { |
| 2964 var field = ''; | 2770 var field = ''; |
| 2965 } | 2771 } |
| 2966 '''); | 2772 '''); |
| 2967 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2773 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2968 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2774 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2969 VariableDeclaration declaration = | 2775 VariableDeclaration declaration = |
| 2970 AstFinder.getFieldInClass(unit, 'C', 'field'); | 2776 AstFinder.getFieldInClass(unit, 'C', 'field'); |
| 2971 VariableElement variable = declaration.name.staticElement; | 2777 VariableElement variable = declaration.name.staticElement; |
| 2972 InferStaticVariableTypeTask inferTask = | 2778 InferStaticVariableTypeTask inferTask = |
| 2973 new InferStaticVariableTypeTask(task.context, variable); | 2779 new InferStaticVariableTypeTask(task.context, variable); |
| 2974 expect(inferTask.getDeclaration(unit), declaration); | 2780 expect(inferTask.getDeclaration(unit), declaration); |
| 2975 } | 2781 } |
| 2976 | 2782 |
| 2977 void test_getDeclaration_topLevel() { | 2783 void test_getDeclaration_topLevel() { |
| 2978 AnalysisTarget source = newSource( | 2784 AnalysisTarget source = newSource('/test.dart', ''' |
| 2979 '/test.dart', | |
| 2980 ''' | |
| 2981 var topLevel = ''; | 2785 var topLevel = ''; |
| 2982 '''); | 2786 '''); |
| 2983 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2787 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 2984 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2788 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 2985 VariableDeclaration declaration = | 2789 VariableDeclaration declaration = |
| 2986 AstFinder.getTopLevelVariable(unit, 'topLevel'); | 2790 AstFinder.getTopLevelVariable(unit, 'topLevel'); |
| 2987 VariableElement variable = declaration.name.staticElement; | 2791 VariableElement variable = declaration.name.staticElement; |
| 2988 InferStaticVariableTypeTask inferTask = | 2792 InferStaticVariableTypeTask inferTask = |
| 2989 new InferStaticVariableTypeTask(task.context, variable); | 2793 new InferStaticVariableTypeTask(task.context, variable); |
| 2990 expect(inferTask.getDeclaration(unit), declaration); | 2794 expect(inferTask.getDeclaration(unit), declaration); |
| 2991 } | 2795 } |
| 2992 | 2796 |
| 2993 void test_perform() { | 2797 void test_perform() { |
| 2994 enableStrongMode(); | 2798 enableStrongMode(); |
| 2995 AnalysisTarget source = newSource( | 2799 AnalysisTarget source = newSource('/test3.dart', ''' |
| 2996 '/test3.dart', | |
| 2997 ''' | |
| 2998 var topLevel3 = ''; | 2800 var topLevel3 = ''; |
| 2999 class C { | 2801 class C { |
| 3000 var field3 = topLevel3; | 2802 var field3 = topLevel3; |
| 3001 } | 2803 } |
| 3002 '''); | 2804 '''); |
| 3003 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2805 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 3004 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2806 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3005 VariableDeclaration topLevelDecl = | 2807 VariableDeclaration topLevelDecl = |
| 3006 AstFinder.getTopLevelVariable(unit, 'topLevel3'); | 2808 AstFinder.getTopLevelVariable(unit, 'topLevel3'); |
| 3007 VariableDeclaration fieldDecl = | 2809 VariableDeclaration fieldDecl = |
| 3008 AstFinder.getFieldInClass(unit, 'C', 'field3'); | 2810 AstFinder.getFieldInClass(unit, 'C', 'field3'); |
| 3009 VariableElement topLevel = topLevelDecl.name.staticElement; | 2811 VariableElement topLevel = topLevelDecl.name.staticElement; |
| 3010 VariableElement field = fieldDecl.name.staticElement; | 2812 VariableElement field = fieldDecl.name.staticElement; |
| 3011 | 2813 |
| 3012 computeResult(field, INFERRED_STATIC_VARIABLE, | 2814 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 3013 matcher: isInferStaticVariableTypeTask); | 2815 matcher: isInferStaticVariableTypeTask); |
| 3014 InterfaceType stringType = context.typeProvider.stringType; | 2816 InterfaceType stringType = context.typeProvider.stringType; |
| 3015 expect(topLevel.type, stringType); | 2817 expect(topLevel.type, stringType); |
| 3016 expect(field.type, stringType); | 2818 expect(field.type, stringType); |
| 3017 expect(fieldDecl.initializer.staticType, stringType); | 2819 expect(fieldDecl.initializer.staticType, stringType); |
| 3018 } | 2820 } |
| 3019 | 2821 |
| 3020 void test_perform_const() { | 2822 void test_perform_const() { |
| 3021 enableStrongMode(); | 2823 enableStrongMode(); |
| 3022 AnalysisTarget source = newSource( | 2824 AnalysisTarget source = newSource('/test.dart', ''' |
| 3023 '/test.dart', | |
| 3024 ''' | |
| 3025 const topLevel = "hello"; | 2825 const topLevel = "hello"; |
| 3026 class C { | 2826 class C { |
| 3027 var field = topLevel; | 2827 var field = topLevel; |
| 3028 } | 2828 } |
| 3029 '''); | 2829 '''); |
| 3030 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2830 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 3031 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2831 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3032 VariableElement topLevel = | 2832 VariableElement topLevel = |
| 3033 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement; | 2833 AstFinder.getTopLevelVariable(unit, 'topLevel').name.staticElement; |
| 3034 VariableElement field = | 2834 VariableElement field = |
| 3035 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement; | 2835 AstFinder.getFieldInClass(unit, 'C', 'field').name.staticElement; |
| 3036 | 2836 |
| 3037 computeResult(field, INFERRED_STATIC_VARIABLE, | 2837 computeResult(field, INFERRED_STATIC_VARIABLE, |
| 3038 matcher: isInferStaticVariableTypeTask); | 2838 matcher: isInferStaticVariableTypeTask); |
| 3039 InterfaceType stringType = context.typeProvider.stringType; | 2839 InterfaceType stringType = context.typeProvider.stringType; |
| 3040 expect(topLevel.type, stringType); | 2840 expect(topLevel.type, stringType); |
| 3041 expect(field.type, stringType); | 2841 expect(field.type, stringType); |
| 3042 } | 2842 } |
| 3043 | 2843 |
| 3044 void test_perform_cycle() { | 2844 void test_perform_cycle() { |
| 3045 enableStrongMode(); | 2845 enableStrongMode(); |
| 3046 AnalysisTarget source = newSource( | 2846 AnalysisTarget source = newSource('/test.dart', ''' |
| 3047 '/test.dart', | |
| 3048 ''' | |
| 3049 var piFirst = true; | 2847 var piFirst = true; |
| 3050 var pi = piFirst ? 3.14 : tau / 2; | 2848 var pi = piFirst ? 3.14 : tau / 2; |
| 3051 var tau = piFirst ? pi * 2 : 6.28; | 2849 var tau = piFirst ? pi * 2 : 6.28; |
| 3052 '''); | 2850 '''); |
| 3053 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2851 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 3054 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2852 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3055 VariableElement piFirst = | 2853 VariableElement piFirst = |
| 3056 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; | 2854 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 3057 VariableElement pi = | 2855 VariableElement pi = |
| 3058 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; | 2856 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 3059 VariableElement tau = | 2857 VariableElement tau = |
| 3060 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; | 2858 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 3061 | 2859 |
| 3062 computeResult(piFirst, INFERRED_STATIC_VARIABLE, | 2860 computeResult(piFirst, INFERRED_STATIC_VARIABLE, |
| 3063 matcher: isInferStaticVariableTypeTask); | 2861 matcher: isInferStaticVariableTypeTask); |
| 3064 expect(piFirst.type, context.typeProvider.boolType); | 2862 expect(piFirst.type, context.typeProvider.boolType); |
| 3065 expect(pi.type.isDynamic, isTrue); | 2863 expect(pi.type.isDynamic, isTrue); |
| 3066 expect(tau.type.isDynamic, isTrue); | 2864 expect(tau.type.isDynamic, isTrue); |
| 3067 } | 2865 } |
| 3068 | 2866 |
| 3069 void test_perform_error() { | 2867 void test_perform_error() { |
| 3070 enableStrongMode(); | 2868 enableStrongMode(); |
| 3071 AnalysisTarget source = newSource( | 2869 AnalysisTarget source = newSource('/test.dart', ''' |
| 3072 '/test.dart', | |
| 3073 ''' | |
| 3074 var a = '' / null; | 2870 var a = '' / null; |
| 3075 '''); | 2871 '''); |
| 3076 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2872 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 3077 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2873 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3078 VariableElement a = | 2874 VariableElement a = |
| 3079 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; | 2875 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 3080 | 2876 |
| 3081 computeResult(a, INFERRED_STATIC_VARIABLE, | 2877 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 3082 matcher: isInferStaticVariableTypeTask); | 2878 matcher: isInferStaticVariableTypeTask); |
| 3083 expect(a.type.isDynamic, isTrue); | 2879 expect(a.type.isDynamic, isTrue); |
| 3084 } | 2880 } |
| 3085 | 2881 |
| 3086 void test_perform_null() { | 2882 void test_perform_null() { |
| 3087 enableStrongMode(); | 2883 enableStrongMode(); |
| 3088 AnalysisTarget source = newSource( | 2884 AnalysisTarget source = newSource('/test.dart', ''' |
| 3089 '/test.dart', | |
| 3090 ''' | |
| 3091 var a = null; | 2885 var a = null; |
| 3092 '''); | 2886 '''); |
| 3093 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); | 2887 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT7); |
| 3094 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 2888 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3095 VariableElement a = | 2889 VariableElement a = |
| 3096 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; | 2890 AstFinder.getTopLevelVariable(unit, 'a').name.staticElement; |
| 3097 | 2891 |
| 3098 computeResult(a, INFERRED_STATIC_VARIABLE, | 2892 computeResult(a, INFERRED_STATIC_VARIABLE, |
| 3099 matcher: isInferStaticVariableTypeTask); | 2893 matcher: isInferStaticVariableTypeTask); |
| 3100 expect(a.type.isDynamic, isTrue); | 2894 expect(a.type.isDynamic, isTrue); |
| 3101 } | 2895 } |
| 3102 } | 2896 } |
| 3103 | 2897 |
| 3104 @reflectiveTest | 2898 @reflectiveTest |
| 3105 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { | 2899 class LibraryErrorsReadyTaskTest extends _AbstractDartTaskTest { |
| 3106 test_perform() { | 2900 test_perform() { |
| 3107 Source library = newSource( | 2901 Source library = newSource('/lib.dart', r''' |
| 3108 '/lib.dart', | |
| 3109 r''' | |
| 3110 library lib; | 2902 library lib; |
| 3111 part 'part1.dart'; | 2903 part 'part1.dart'; |
| 3112 part 'part2.dart'; | 2904 part 'part2.dart'; |
| 3113 X v1; | 2905 X v1; |
| 3114 '''); | 2906 '''); |
| 3115 Source part1 = newSource( | 2907 Source part1 = newSource('/part1.dart', r''' |
| 3116 '/part1.dart', | |
| 3117 r''' | |
| 3118 part of lib; | 2908 part of lib; |
| 3119 X v2; | 2909 X v2; |
| 3120 '''); | 2910 '''); |
| 3121 Source part2 = newSource( | 2911 Source part2 = newSource('/part2.dart', r''' |
| 3122 '/part2.dart', | |
| 3123 r''' | |
| 3124 part of lib; | 2912 part of lib; |
| 3125 X v3; | 2913 X v3; |
| 3126 '''); | 2914 '''); |
| 3127 computeResult(library, LIBRARY_ERRORS_READY, | 2915 computeResult(library, LIBRARY_ERRORS_READY, |
| 3128 matcher: isLibraryErrorsReadyTask); | 2916 matcher: isLibraryErrorsReadyTask); |
| 3129 expect(outputs, hasLength(1)); | 2917 expect(outputs, hasLength(1)); |
| 3130 bool ready = outputs[LIBRARY_ERRORS_READY]; | 2918 bool ready = outputs[LIBRARY_ERRORS_READY]; |
| 3131 expect(ready, isTrue); | 2919 expect(ready, isTrue); |
| 3132 expect(context.getErrors(library).errors, hasLength(1)); | 2920 expect(context.getErrors(library).errors, hasLength(1)); |
| 3133 expect(context.getErrors(part1).errors, hasLength(1)); | 2921 expect(context.getErrors(part1).errors, hasLength(1)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3181 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | 2969 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 3182 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2970 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3183 expect(outputs[PARSED_UNIT], isNotNull); | 2971 expect(outputs[PARSED_UNIT], isNotNull); |
| 3184 expect(outputs[REFERENCED_SOURCES], hasLength(2)); | 2972 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 3185 expect(outputs[SOURCE_KIND], SourceKind.PART); | 2973 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 3186 expect(outputs[UNITS], hasLength(1)); | 2974 expect(outputs[UNITS], hasLength(1)); |
| 3187 } | 2975 } |
| 3188 | 2976 |
| 3189 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { | 2977 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { |
| 3190 // Parse "lib.dart" to let the context know that "test.dart" is included. | 2978 // Parse "lib.dart" to let the context know that "test.dart" is included. |
| 3191 computeResult( | 2979 computeResult(newSource('/lib.dart', r''' |
| 3192 newSource( | |
| 3193 '/lib.dart', | |
| 3194 r''' | |
| 3195 library lib; | 2980 library lib; |
| 3196 part 'test.dart'; | 2981 part 'test.dart'; |
| 3197 '''), | 2982 '''), PARSED_UNIT); |
| 3198 PARSED_UNIT); | |
| 3199 // If there are no the "part of" directive, then it is not a part. | 2983 // If there are no the "part of" directive, then it is not a part. |
| 3200 _performParseTask(''); | 2984 _performParseTask(''); |
| 3201 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 2985 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3202 } | 2986 } |
| 3203 | 2987 |
| 3204 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { | 2988 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { |
| 3205 _performParseTask(''); | 2989 _performParseTask(''); |
| 3206 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 2990 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3207 } | 2991 } |
| 3208 | 2992 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3441 expect(sources, hasLength(lenght)); | 3225 expect(sources, hasLength(lenght)); |
| 3442 expect(sources, contains(predicate((Source s) { | 3226 expect(sources, contains(predicate((Source s) { |
| 3443 return s.fullName.endsWith('core.dart'); | 3227 return s.fullName.endsWith('core.dart'); |
| 3444 }))); | 3228 }))); |
| 3445 } | 3229 } |
| 3446 } | 3230 } |
| 3447 | 3231 |
| 3448 @reflectiveTest | 3232 @reflectiveTest |
| 3449 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { | 3233 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { |
| 3450 test_perform_strong_importExport() { | 3234 test_perform_strong_importExport() { |
| 3451 newSource( | 3235 newSource('/a.dart', ''' |
| 3452 '/a.dart', | |
| 3453 ''' | |
| 3454 library a; | 3236 library a; |
| 3455 class A<T> { | 3237 class A<T> { |
| 3456 T m() {} | 3238 T m() {} |
| 3457 } | 3239 } |
| 3458 '''); | 3240 '''); |
| 3459 newSource( | 3241 newSource('/b.dart', ''' |
| 3460 '/b.dart', | |
| 3461 ''' | |
| 3462 library b; | 3242 library b; |
| 3463 export 'a.dart'; | 3243 export 'a.dart'; |
| 3464 '''); | 3244 '''); |
| 3465 Source sourceC = newSource( | 3245 Source sourceC = newSource('/c.dart', ''' |
| 3466 '/c.dart', | |
| 3467 ''' | |
| 3468 library c; | 3246 library c; |
| 3469 import 'b.dart'; | 3247 import 'b.dart'; |
| 3470 main() { | 3248 main() { |
| 3471 new A<int>().m(); | 3249 new A<int>().m(); |
| 3472 } | 3250 } |
| 3473 '''); | 3251 '''); |
| 3474 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT7, | 3252 computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT7, |
| 3475 matcher: isPartiallyResolveUnitReferencesTask); | 3253 matcher: isPartiallyResolveUnitReferencesTask); |
| 3476 // validate | 3254 // validate |
| 3477 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); | 3255 expect(outputs[INFERABLE_STATIC_VARIABLES_IN_UNIT], hasLength(0)); |
| 3478 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 3256 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3479 expect(unit, isNotNull); | 3257 expect(unit, isNotNull); |
| 3480 | 3258 |
| 3481 FunctionDeclaration mainFunction = unit.declarations[0]; | 3259 FunctionDeclaration mainFunction = unit.declarations[0]; |
| 3482 expect(mainFunction.element, isNotNull); | 3260 expect(mainFunction.element, isNotNull); |
| 3483 BlockFunctionBody body = mainFunction.functionExpression.body; | 3261 BlockFunctionBody body = mainFunction.functionExpression.body; |
| 3484 List<Statement> statements = body.block.statements; | 3262 List<Statement> statements = body.block.statements; |
| 3485 ExpressionStatement statement = statements[0]; | 3263 ExpressionStatement statement = statements[0]; |
| 3486 MethodInvocation invocation = statement.expression; | 3264 MethodInvocation invocation = statement.expression; |
| 3487 MethodElement methodElement = invocation.methodName.staticElement; | 3265 MethodElement methodElement = invocation.methodName.staticElement; |
| 3488 expect(methodElement, isNull); | 3266 expect(methodElement, isNull); |
| 3489 } | 3267 } |
| 3490 | 3268 |
| 3491 test_perform_strong_inferable() { | 3269 test_perform_strong_inferable() { |
| 3492 enableStrongMode(); | 3270 enableStrongMode(); |
| 3493 Source source = newSource( | 3271 Source source = newSource('/test.dart', ''' |
| 3494 '/test.dart', | |
| 3495 ''' | |
| 3496 int a = b; | 3272 int a = b; |
| 3497 int b = c; | 3273 int b = c; |
| 3498 var d = 0; | 3274 var d = 0; |
| 3499 class A {} | 3275 class A {} |
| 3500 class C { | 3276 class C { |
| 3501 static final f = ''; | 3277 static final f = ''; |
| 3502 var g = 0; | 3278 var g = 0; |
| 3503 } | 3279 } |
| 3504 '''); | 3280 '''); |
| 3505 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3281 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3516 } | 3292 } |
| 3517 // Test the state of the AST | 3293 // Test the state of the AST |
| 3518 TopLevelVariableDeclaration a = unit.declarations[0]; | 3294 TopLevelVariableDeclaration a = unit.declarations[0]; |
| 3519 VariableDeclaration variableA = a.variables.variables[0]; | 3295 VariableDeclaration variableA = a.variables.variables[0]; |
| 3520 SimpleIdentifier initializer = variableA.initializer; | 3296 SimpleIdentifier initializer = variableA.initializer; |
| 3521 expect(initializer.staticElement, isNotNull); | 3297 expect(initializer.staticElement, isNotNull); |
| 3522 } | 3298 } |
| 3523 | 3299 |
| 3524 test_perform_strong_notResolved() { | 3300 test_perform_strong_notResolved() { |
| 3525 enableStrongMode(); | 3301 enableStrongMode(); |
| 3526 Source source = newSource( | 3302 Source source = newSource('/test.dart', ''' |
| 3527 '/test.dart', | |
| 3528 ''' | |
| 3529 int A; | 3303 int A; |
| 3530 f1() { | 3304 f1() { |
| 3531 A; | 3305 A; |
| 3532 } | 3306 } |
| 3533 var f2 = () { | 3307 var f2 = () { |
| 3534 A; | 3308 A; |
| 3535 void f3() { | 3309 void f3() { |
| 3536 A; | 3310 A; |
| 3537 } | 3311 } |
| 3538 } | 3312 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3641 | 3415 |
| 3642 @reflectiveTest | 3416 @reflectiveTest |
| 3643 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { | 3417 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { |
| 3644 @override | 3418 @override |
| 3645 void setUp() { | 3419 void setUp() { |
| 3646 super.setUp(); | 3420 super.setUp(); |
| 3647 enableStrongMode(); | 3421 enableStrongMode(); |
| 3648 } | 3422 } |
| 3649 | 3423 |
| 3650 test_created_resolved_unit() { | 3424 test_created_resolved_unit() { |
| 3651 Source source = newSource( | 3425 Source source = newSource('/test.dart', r''' |
| 3652 '/test.dart', | |
| 3653 r''' | |
| 3654 library lib; | 3426 library lib; |
| 3655 class A {} | 3427 class A {} |
| 3656 '''); | 3428 '''); |
| 3657 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3429 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3658 computeResult(target, RESOLVED_UNIT9); | 3430 computeResult(target, RESOLVED_UNIT9); |
| 3659 expect(outputs[RESOLVED_UNIT9], isNotNull); | 3431 expect(outputs[RESOLVED_UNIT9], isNotNull); |
| 3660 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); | 3432 expect(outputs[CREATED_RESOLVED_UNIT9], isTrue); |
| 3661 } | 3433 } |
| 3662 | 3434 |
| 3663 /** | 3435 /** |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3880 | 3652 |
| 3881 // B.b2 should now be fully resolved and inferred. | 3653 // B.b2 should now be fully resolved and inferred. |
| 3882 assertVariableDeclarationTypes( | 3654 assertVariableDeclarationTypes( |
| 3883 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); | 3655 AstFinder.getFieldInClass(unit0, "B", "b2"), intType, intType); |
| 3884 } | 3656 } |
| 3885 } | 3657 } |
| 3886 | 3658 |
| 3887 @reflectiveTest | 3659 @reflectiveTest |
| 3888 class ResolveLibraryTaskTest extends _AbstractDartTaskTest { | 3660 class ResolveLibraryTaskTest extends _AbstractDartTaskTest { |
| 3889 test_perform() { | 3661 test_perform() { |
| 3890 Source sourceLib = newSource( | 3662 Source sourceLib = newSource('/my_lib.dart', ''' |
| 3891 '/my_lib.dart', | |
| 3892 ''' | |
| 3893 library my_lib; | 3663 library my_lib; |
| 3894 const a = new A(); | 3664 const a = new A(); |
| 3895 class A { | 3665 class A { |
| 3896 const A(); | 3666 const A(); |
| 3897 } | 3667 } |
| 3898 @a | 3668 @a |
| 3899 class C {} | 3669 class C {} |
| 3900 '''); | 3670 '''); |
| 3901 computeResult(sourceLib, LIBRARY_ELEMENT, matcher: isResolveLibraryTask); | 3671 computeResult(sourceLib, LIBRARY_ELEMENT, matcher: isResolveLibraryTask); |
| 3902 // validate | 3672 // validate |
| 3903 LibraryElement library = outputs[LIBRARY_ELEMENT]; | 3673 LibraryElement library = outputs[LIBRARY_ELEMENT]; |
| 3904 ClassElement classC = library.getType('C'); | 3674 ClassElement classC = library.getType('C'); |
| 3905 List<ElementAnnotation> metadata = classC.metadata; | 3675 List<ElementAnnotation> metadata = classC.metadata; |
| 3906 expect(metadata, hasLength(1)); | 3676 expect(metadata, hasLength(1)); |
| 3907 ElementAnnotation annotation = metadata[0]; | 3677 ElementAnnotation annotation = metadata[0]; |
| 3908 expect(annotation, isNotNull); | 3678 expect(annotation, isNotNull); |
| 3909 expect((annotation as ElementAnnotationImpl).evaluationResult, isNotNull); | 3679 expect((annotation as ElementAnnotationImpl).evaluationResult, isNotNull); |
| 3910 } | 3680 } |
| 3911 } | 3681 } |
| 3912 | 3682 |
| 3913 @reflectiveTest | 3683 @reflectiveTest |
| 3914 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { | 3684 class ResolveLibraryTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 3915 test_perform() { | 3685 test_perform() { |
| 3916 Source sourceLib = newSource( | 3686 Source sourceLib = newSource('/my_lib.dart', ''' |
| 3917 '/my_lib.dart', | |
| 3918 ''' | |
| 3919 library my_lib; | 3687 library my_lib; |
| 3920 part 'my_part.dart'; | 3688 part 'my_part.dart'; |
| 3921 class A {} | 3689 class A {} |
| 3922 class B extends A {} | 3690 class B extends A {} |
| 3923 '''); | 3691 '''); |
| 3924 newSource( | 3692 newSource('/my_part.dart', ''' |
| 3925 '/my_part.dart', | |
| 3926 ''' | |
| 3927 part of my_lib; | 3693 part of my_lib; |
| 3928 class C extends A {} | 3694 class C extends A {} |
| 3929 '''); | 3695 '''); |
| 3930 computeResult(sourceLib, LIBRARY_ELEMENT6, | 3696 computeResult(sourceLib, LIBRARY_ELEMENT6, |
| 3931 matcher: isResolveLibraryTypeNamesTask); | 3697 matcher: isResolveLibraryTypeNamesTask); |
| 3932 // validate | 3698 // validate |
| 3933 LibraryElement library = outputs[LIBRARY_ELEMENT6]; | 3699 LibraryElement library = outputs[LIBRARY_ELEMENT6]; |
| 3934 { | 3700 { |
| 3935 ClassElement classB = library.getType('B'); | 3701 ClassElement classB = library.getType('B'); |
| 3936 expect(classB.supertype.displayName, 'A'); | 3702 expect(classB.supertype.displayName, 'A'); |
| 3937 } | 3703 } |
| 3938 { | 3704 { |
| 3939 ClassElement classC = library.getType('C'); | 3705 ClassElement classC = library.getType('C'); |
| 3940 expect(classC.supertype.displayName, 'A'); | 3706 expect(classC.supertype.displayName, 'A'); |
| 3941 } | 3707 } |
| 3942 expect(library.loadLibraryFunction, isNotNull); | 3708 expect(library.loadLibraryFunction, isNotNull); |
| 3943 } | 3709 } |
| 3944 | 3710 |
| 3945 test_perform_external() { | 3711 test_perform_external() { |
| 3946 Source sourceA = newSource( | 3712 Source sourceA = newSource('/a.dart', ''' |
| 3947 '/a.dart', | |
| 3948 ''' | |
| 3949 library a; | 3713 library a; |
| 3950 import 'b.dart'; | 3714 import 'b.dart'; |
| 3951 class A extends B {} | 3715 class A extends B {} |
| 3952 '''); | 3716 '''); |
| 3953 newSource( | 3717 newSource('/b.dart', ''' |
| 3954 '/b.dart', | |
| 3955 ''' | |
| 3956 library b; | 3718 library b; |
| 3957 class B {} | 3719 class B {} |
| 3958 '''); | 3720 '''); |
| 3959 // The reference A to B should be resolved, but there's no requirement that | 3721 // The reference A to B should be resolved, but there's no requirement that |
| 3960 // the full class hierarchy be resolved. | 3722 // the full class hierarchy be resolved. |
| 3961 computeResult(sourceA, LIBRARY_ELEMENT6, | 3723 computeResult(sourceA, LIBRARY_ELEMENT6, |
| 3962 matcher: isResolveLibraryTypeNamesTask); | 3724 matcher: isResolveLibraryTypeNamesTask); |
| 3963 // validate | 3725 // validate |
| 3964 LibraryElement library = outputs[LIBRARY_ELEMENT6]; | 3726 LibraryElement library = outputs[LIBRARY_ELEMENT6]; |
| 3965 { | 3727 { |
| 3966 ClassElement clazz = library.getType('A'); | 3728 ClassElement clazz = library.getType('A'); |
| 3967 expect(clazz.displayName, 'A'); | 3729 expect(clazz.displayName, 'A'); |
| 3968 clazz = clazz.supertype.element; | 3730 clazz = clazz.supertype.element; |
| 3969 expect(clazz.displayName, 'B'); | 3731 expect(clazz.displayName, 'B'); |
| 3970 } | 3732 } |
| 3971 } | 3733 } |
| 3972 } | 3734 } |
| 3973 | 3735 |
| 3974 @reflectiveTest | 3736 @reflectiveTest |
| 3975 class ResolveTopLevelUnitTypeBoundsTaskTest extends _AbstractDartTaskTest { | 3737 class ResolveTopLevelUnitTypeBoundsTaskTest extends _AbstractDartTaskTest { |
| 3976 test_perform_boundIsGenericType() { | 3738 test_perform_boundIsGenericType() { |
| 3977 Source source = newSource( | 3739 Source source = newSource('/test.dart', ''' |
| 3978 '/test.dart', | |
| 3979 ''' | |
| 3980 class C<T extends Map<String, List<int>>> {} | 3740 class C<T extends Map<String, List<int>>> {} |
| 3981 '''); | 3741 '''); |
| 3982 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3742 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3983 computeResult(target, RESOLVED_UNIT4, | 3743 computeResult(target, RESOLVED_UNIT4, |
| 3984 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3744 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 3985 // validate | 3745 // validate |
| 3986 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 3746 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 3987 ClassDeclaration nodeC = unit.declarations[0]; | 3747 ClassDeclaration nodeC = unit.declarations[0]; |
| 3988 _assertTypeParameterBound(nodeC.typeParameters.typeParameters[0], | 3748 _assertTypeParameterBound(nodeC.typeParameters.typeParameters[0], |
| 3989 'Map<String, List<int>>', 'Map'); | 3749 'Map<String, List<int>>', 'Map'); |
| 3990 } | 3750 } |
| 3991 | 3751 |
| 3992 test_perform_errors() { | 3752 test_perform_errors() { |
| 3993 Source source = newSource( | 3753 Source source = newSource('/test.dart', ''' |
| 3994 '/test.dart', | |
| 3995 ''' | |
| 3996 class C<T extends NoSuchClass> {} | 3754 class C<T extends NoSuchClass> {} |
| 3997 '''); | 3755 '''); |
| 3998 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3756 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 3999 computeResult(target, RESOLVE_TYPE_BOUNDS_ERRORS, | 3757 computeResult(target, RESOLVE_TYPE_BOUNDS_ERRORS, |
| 4000 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3758 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4001 // validate | 3759 // validate |
| 4002 _fillErrorListener(RESOLVE_TYPE_BOUNDS_ERRORS); | 3760 _fillErrorListener(RESOLVE_TYPE_BOUNDS_ERRORS); |
| 4003 errorListener | 3761 errorListener |
| 4004 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 3762 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 4005 } | 3763 } |
| 4006 | 3764 |
| 4007 test_perform_ignoreBoundsOfBounds() { | 3765 test_perform_ignoreBoundsOfBounds() { |
| 4008 Source source = newSource( | 3766 Source source = newSource('/test.dart', ''' |
| 4009 '/test.dart', | |
| 4010 ''' | |
| 4011 class A<T1 extends num> {} | 3767 class A<T1 extends num> {} |
| 4012 class B<T2 extends A> {} | 3768 class B<T2 extends A> {} |
| 4013 '''); | 3769 '''); |
| 4014 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3770 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4015 computeResult(target, RESOLVED_UNIT4, | 3771 computeResult(target, RESOLVED_UNIT4, |
| 4016 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3772 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4017 // validate | 3773 // validate |
| 4018 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 3774 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4019 ClassDeclaration nodeB = unit.declarations[1]; | 3775 ClassDeclaration nodeB = unit.declarations[1]; |
| 4020 _assertTypeParameterBound( | 3776 _assertTypeParameterBound( |
| 4021 nodeB.typeParameters.typeParameters[0], 'A<dynamic>', 'A'); | 3777 nodeB.typeParameters.typeParameters[0], 'A<dynamic>', 'A'); |
| 4022 } | 3778 } |
| 4023 | 3779 |
| 4024 test_perform_outputs() { | 3780 test_perform_outputs() { |
| 4025 Source source = newSource( | 3781 Source source = newSource('/test.dart', r''' |
| 4026 '/test.dart', | |
| 4027 r''' | |
| 4028 class C<T extends int> {} | 3782 class C<T extends int> {} |
| 4029 '''); | 3783 '''); |
| 4030 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3784 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4031 computeResult(target, RESOLVED_UNIT4); | 3785 computeResult(target, RESOLVED_UNIT4); |
| 4032 expect(outputs[RESOLVED_UNIT4], isNotNull); | 3786 expect(outputs[RESOLVED_UNIT4], isNotNull); |
| 4033 expect(outputs[CREATED_RESOLVED_UNIT4], isTrue); | 3787 expect(outputs[CREATED_RESOLVED_UNIT4], isTrue); |
| 4034 expect(outputs[RESOLVE_TYPE_BOUNDS_ERRORS], isNotNull); | 3788 expect(outputs[RESOLVE_TYPE_BOUNDS_ERRORS], isNotNull); |
| 4035 } | 3789 } |
| 4036 | 3790 |
| 4037 test_perform_unitMember_ClassDeclaration() { | 3791 test_perform_unitMember_ClassDeclaration() { |
| 4038 Source source = newSource( | 3792 Source source = newSource('/test.dart', ''' |
| 4039 '/test.dart', | |
| 4040 ''' | |
| 4041 class C<T extends int> extends Object {} | 3793 class C<T extends int> extends Object {} |
| 4042 '''); | 3794 '''); |
| 4043 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3795 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4044 computeResult(target, RESOLVED_UNIT4, | 3796 computeResult(target, RESOLVED_UNIT4, |
| 4045 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3797 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4046 // validate | 3798 // validate |
| 4047 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 3799 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4048 ClassDeclaration nodeC = unit.declarations[0]; | 3800 ClassDeclaration nodeC = unit.declarations[0]; |
| 4049 // 'extends Object' is not resolved | 3801 // 'extends Object' is not resolved |
| 4050 expect(nodeC.extendsClause.superclass.name.staticElement, isNull); | 3802 expect(nodeC.extendsClause.superclass.name.staticElement, isNull); |
| 4051 // but 'T extends int' is resolved | 3803 // but 'T extends int' is resolved |
| 4052 _assertTypeParameterBound( | 3804 _assertTypeParameterBound( |
| 4053 nodeC.typeParameters.typeParameters[0], 'int', 'int'); | 3805 nodeC.typeParameters.typeParameters[0], 'int', 'int'); |
| 4054 } | 3806 } |
| 4055 | 3807 |
| 4056 test_perform_unitMember_ClassTypeAlias() { | 3808 test_perform_unitMember_ClassTypeAlias() { |
| 4057 Source source = newSource( | 3809 Source source = newSource('/test.dart', ''' |
| 4058 '/test.dart', | |
| 4059 ''' | |
| 4060 class C<T extends double> = Object; | 3810 class C<T extends double> = Object; |
| 4061 '''); | 3811 '''); |
| 4062 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3812 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4063 computeResult(target, RESOLVED_UNIT4, | 3813 computeResult(target, RESOLVED_UNIT4, |
| 4064 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3814 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4065 // validate | 3815 // validate |
| 4066 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 3816 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4067 ClassTypeAlias nodeC = unit.declarations[0]; | 3817 ClassTypeAlias nodeC = unit.declarations[0]; |
| 4068 // '= Object' is not resolved | 3818 // '= Object' is not resolved |
| 4069 expect(nodeC.superclass.name.staticElement, isNull); | 3819 expect(nodeC.superclass.name.staticElement, isNull); |
| 4070 // but 'T extends int' is resolved | 3820 // but 'T extends int' is resolved |
| 4071 _assertTypeParameterBound( | 3821 _assertTypeParameterBound( |
| 4072 nodeC.typeParameters.typeParameters[0], 'double', 'double'); | 3822 nodeC.typeParameters.typeParameters[0], 'double', 'double'); |
| 4073 } | 3823 } |
| 4074 | 3824 |
| 4075 test_perform_unitMember_FunctionTypeAlias() { | 3825 test_perform_unitMember_FunctionTypeAlias() { |
| 4076 Source source = newSource( | 3826 Source source = newSource('/test.dart', ''' |
| 4077 '/test.dart', | |
| 4078 ''' | |
| 4079 typedef F<T extends String>(); | 3827 typedef F<T extends String>(); |
| 4080 '''); | 3828 '''); |
| 4081 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3829 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4082 computeResult(target, RESOLVED_UNIT4, | 3830 computeResult(target, RESOLVED_UNIT4, |
| 4083 matcher: isResolveTopLevelUnitTypeBoundsTask); | 3831 matcher: isResolveTopLevelUnitTypeBoundsTask); |
| 4084 // validate | 3832 // validate |
| 4085 CompilationUnit unit = outputs[RESOLVED_UNIT4]; | 3833 CompilationUnit unit = outputs[RESOLVED_UNIT4]; |
| 4086 FunctionTypeAlias nodeF = unit.declarations[0]; | 3834 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 4087 // but 'T extends String' is resolved | 3835 // but 'T extends String' is resolved |
| 4088 _assertTypeParameterBound( | 3836 _assertTypeParameterBound( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4099 expect(boundNode.type.toString(), expectedBoundTypeString); | 3847 expect(boundNode.type.toString(), expectedBoundTypeString); |
| 4100 expect(boundName.staticType.toString(), expectedBoundTypeString); | 3848 expect(boundName.staticType.toString(), expectedBoundTypeString); |
| 4101 expect(resolutionMap.staticElementForIdentifier(boundName).displayName, | 3849 expect(resolutionMap.staticElementForIdentifier(boundName).displayName, |
| 4102 expectedBoundElementName); | 3850 expectedBoundElementName); |
| 4103 } | 3851 } |
| 4104 } | 3852 } |
| 4105 | 3853 |
| 4106 @reflectiveTest | 3854 @reflectiveTest |
| 4107 class ResolveUnitTaskTest extends _AbstractDartTaskTest { | 3855 class ResolveUnitTaskTest extends _AbstractDartTaskTest { |
| 4108 test_created_resolved_unit() { | 3856 test_created_resolved_unit() { |
| 4109 Source source = newSource( | 3857 Source source = newSource('/test.dart', r''' |
| 4110 '/test.dart', | |
| 4111 r''' | |
| 4112 library lib; | 3858 library lib; |
| 4113 class A {} | 3859 class A {} |
| 4114 '''); | 3860 '''); |
| 4115 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3861 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4116 computeResult(target, RESOLVED_UNIT11); | 3862 computeResult(target, RESOLVED_UNIT11); |
| 4117 expect(outputs[RESOLVED_UNIT11], isNotNull); | 3863 expect(outputs[RESOLVED_UNIT11], isNotNull); |
| 4118 expect(outputs[CREATED_RESOLVED_UNIT11], isTrue); | 3864 expect(outputs[CREATED_RESOLVED_UNIT11], isTrue); |
| 4119 } | 3865 } |
| 4120 | 3866 |
| 4121 void test_perform() { | 3867 void test_perform() { |
| 4122 AnalysisTarget source = newSource( | 3868 AnalysisTarget source = newSource('/test.dart', ''' |
| 4123 '/test.dart', | |
| 4124 ''' | |
| 4125 void f() { | 3869 void f() { |
| 4126 var c = new C(); | 3870 var c = new C(); |
| 4127 c.m(); | 3871 c.m(); |
| 4128 } | 3872 } |
| 4129 class C { | 3873 class C { |
| 4130 void m() { | 3874 void m() { |
| 4131 f(); | 3875 f(); |
| 4132 } | 3876 } |
| 4133 } | 3877 } |
| 4134 '''); | 3878 '''); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4148 void _assertResolved(FunctionBody body) { | 3892 void _assertResolved(FunctionBody body) { |
| 4149 ResolutionVerifier verifier = new ResolutionVerifier(); | 3893 ResolutionVerifier verifier = new ResolutionVerifier(); |
| 4150 body.accept(verifier); | 3894 body.accept(verifier); |
| 4151 verifier.assertResolved(); | 3895 verifier.assertResolved(); |
| 4152 } | 3896 } |
| 4153 } | 3897 } |
| 4154 | 3898 |
| 4155 @reflectiveTest | 3899 @reflectiveTest |
| 4156 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 3900 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 4157 test_created_resolved_unit() { | 3901 test_created_resolved_unit() { |
| 4158 Source source = newSource( | 3902 Source source = newSource('/test.dart', r''' |
| 4159 '/test.dart', | |
| 4160 r''' | |
| 4161 library lib; | 3903 library lib; |
| 4162 class A {} | 3904 class A {} |
| 4163 '''); | 3905 '''); |
| 4164 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3906 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4165 computeResult(target, RESOLVED_UNIT5); | 3907 computeResult(target, RESOLVED_UNIT5); |
| 4166 expect(outputs[RESOLVED_UNIT5], isNotNull); | 3908 expect(outputs[RESOLVED_UNIT5], isNotNull); |
| 4167 expect(outputs[CREATED_RESOLVED_UNIT5], isTrue); | 3909 expect(outputs[CREATED_RESOLVED_UNIT5], isTrue); |
| 4168 } | 3910 } |
| 4169 | 3911 |
| 4170 test_perform() { | 3912 test_perform() { |
| 4171 Source source = newSource( | 3913 Source source = newSource('/test.dart', ''' |
| 4172 '/test.dart', | |
| 4173 ''' | |
| 4174 class A {} | 3914 class A {} |
| 4175 class B extends A {} | 3915 class B extends A {} |
| 4176 int f(String p) => p.length; | 3916 int f(String p) => p.length; |
| 4177 '''); | 3917 '''); |
| 4178 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3918 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4179 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); | 3919 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); |
| 4180 // validate | 3920 // validate |
| 4181 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3921 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 4182 { | 3922 { |
| 4183 ClassDeclaration nodeA = unit.declarations[0]; | 3923 ClassDeclaration nodeA = unit.declarations[0]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4195 expect( | 3935 expect( |
| 4196 resolutionMap | 3936 resolutionMap |
| 4197 .elementDeclaredByFormalParameter(parameters[0]) | 3937 .elementDeclaredByFormalParameter(parameters[0]) |
| 4198 .type | 3938 .type |
| 4199 .displayName, | 3939 .displayName, |
| 4200 'String'); | 3940 'String'); |
| 4201 } | 3941 } |
| 4202 } | 3942 } |
| 4203 | 3943 |
| 4204 test_perform_errors() { | 3944 test_perform_errors() { |
| 4205 Source source = newSource( | 3945 Source source = newSource('/test.dart', ''' |
| 4206 '/test.dart', | |
| 4207 ''' | |
| 4208 NoSuchClass f() => null; | 3946 NoSuchClass f() => null; |
| 4209 '''); | 3947 '''); |
| 4210 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3948 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4211 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, | 3949 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, |
| 4212 matcher: isResolveUnitTypeNamesTask); | 3950 matcher: isResolveUnitTypeNamesTask); |
| 4213 // validate | 3951 // validate |
| 4214 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 3952 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 4215 errorListener | 3953 errorListener |
| 4216 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 3954 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 4217 } | 3955 } |
| 4218 | 3956 |
| 4219 test_perform_typedef() { | 3957 test_perform_typedef() { |
| 4220 Source source = newSource( | 3958 Source source = newSource('/test.dart', ''' |
| 4221 '/test.dart', | |
| 4222 ''' | |
| 4223 typedef int F(G g); | 3959 typedef int F(G g); |
| 4224 typedef String G(int p); | 3960 typedef String G(int p); |
| 4225 '''); | 3961 '''); |
| 4226 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3962 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4227 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); | 3963 computeResult(target, RESOLVED_UNIT5, matcher: isResolveUnitTypeNamesTask); |
| 4228 // validate | 3964 // validate |
| 4229 CompilationUnit unit = outputs[RESOLVED_UNIT5]; | 3965 CompilationUnit unit = outputs[RESOLVED_UNIT5]; |
| 4230 FunctionTypeAlias nodeF = unit.declarations[0]; | 3966 FunctionTypeAlias nodeF = unit.declarations[0]; |
| 4231 FunctionTypeAlias nodeG = unit.declarations[1]; | 3967 FunctionTypeAlias nodeG = unit.declarations[1]; |
| 4232 { | 3968 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4243 DartType parameterType = | 3979 DartType parameterType = |
| 4244 resolutionMap.elementDeclaredByFormalParameter(parameter).type; | 3980 resolutionMap.elementDeclaredByFormalParameter(parameter).type; |
| 4245 expect( | 3981 expect( |
| 4246 resolutionMap.typeForTypeName(nodeG.returnType).element.displayName, | 3982 resolutionMap.typeForTypeName(nodeG.returnType).element.displayName, |
| 4247 'String'); | 3983 'String'); |
| 4248 expect(parameterType.element.displayName, 'int'); | 3984 expect(parameterType.element.displayName, 'int'); |
| 4249 } | 3985 } |
| 4250 } | 3986 } |
| 4251 | 3987 |
| 4252 test_perform_typedef_errors() { | 3988 test_perform_typedef_errors() { |
| 4253 Source source = newSource( | 3989 Source source = newSource('/test.dart', ''' |
| 4254 '/test.dart', | |
| 4255 ''' | |
| 4256 typedef int F(NoSuchType p); | 3990 typedef int F(NoSuchType p); |
| 4257 '''); | 3991 '''); |
| 4258 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 3992 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4259 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, | 3993 computeResult(target, RESOLVE_TYPE_NAMES_ERRORS, |
| 4260 matcher: isResolveUnitTypeNamesTask); | 3994 matcher: isResolveUnitTypeNamesTask); |
| 4261 // validate | 3995 // validate |
| 4262 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); | 3996 _fillErrorListener(RESOLVE_TYPE_NAMES_ERRORS); |
| 4263 errorListener | 3997 errorListener |
| 4264 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); | 3998 .assertErrorsWithCodes(<ErrorCode>[StaticWarningCode.UNDEFINED_CLASS]); |
| 4265 } | 3999 } |
| 4266 } | 4000 } |
| 4267 | 4001 |
| 4268 @reflectiveTest | 4002 @reflectiveTest |
| 4269 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { | 4003 class ResolveVariableReferencesTaskTest extends _AbstractDartTaskTest { |
| 4270 /** | 4004 /** |
| 4271 * Verify that the mutated states of the given [variable] correspond to the | 4005 * Verify that the mutated states of the given [variable] correspond to the |
| 4272 * [mutatedInClosure] and [mutatedInScope] matchers. | 4006 * [mutatedInClosure] and [mutatedInScope] matchers. |
| 4273 */ | 4007 */ |
| 4274 void expectMutated(FunctionBody body, VariableElement variable, | 4008 void expectMutated(FunctionBody body, VariableElement variable, |
| 4275 bool mutatedInClosure, bool mutatedInScope) { | 4009 bool mutatedInClosure, bool mutatedInScope) { |
| 4276 expect(body.isPotentiallyMutatedInClosure(variable), mutatedInClosure); | 4010 expect(body.isPotentiallyMutatedInClosure(variable), mutatedInClosure); |
| 4277 expect(body.isPotentiallyMutatedInScope(variable), mutatedInScope); | 4011 expect(body.isPotentiallyMutatedInScope(variable), mutatedInScope); |
| 4278 } | 4012 } |
| 4279 | 4013 |
| 4280 test_created_resolved_unit() { | 4014 test_created_resolved_unit() { |
| 4281 Source source = newSource( | 4015 Source source = newSource('/test.dart', r''' |
| 4282 '/test.dart', | |
| 4283 r''' | |
| 4284 library lib; | 4016 library lib; |
| 4285 class A {} | 4017 class A {} |
| 4286 '''); | 4018 '''); |
| 4287 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4019 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4288 computeResult(target, RESOLVED_UNIT6); | 4020 computeResult(target, RESOLVED_UNIT6); |
| 4289 expect(outputs[RESOLVED_UNIT6], isNotNull); | 4021 expect(outputs[RESOLVED_UNIT6], isNotNull); |
| 4290 expect(outputs[CREATED_RESOLVED_UNIT6], isTrue); | 4022 expect(outputs[CREATED_RESOLVED_UNIT6], isTrue); |
| 4291 } | 4023 } |
| 4292 | 4024 |
| 4293 test_perform_buildClosureLibraryElements() { | 4025 test_perform_buildClosureLibraryElements() { |
| 4294 Source source = newSource( | 4026 Source source = newSource('/test.dart', ''' |
| 4295 '/test.dart', | |
| 4296 ''' | |
| 4297 main() { | 4027 main() { |
| 4298 } | 4028 } |
| 4299 '''); | 4029 '''); |
| 4300 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4030 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4301 computeResult(target, RESOLVED_UNIT6, | 4031 computeResult(target, RESOLVED_UNIT6, |
| 4302 matcher: isResolveVariableReferencesTask); | 4032 matcher: isResolveVariableReferencesTask); |
| 4303 } | 4033 } |
| 4304 | 4034 |
| 4305 test_perform_local() { | 4035 test_perform_local() { |
| 4306 Source source = newSource( | 4036 Source source = newSource('/test.dart', ''' |
| 4307 '/test.dart', | |
| 4308 ''' | |
| 4309 main() { | 4037 main() { |
| 4310 var v1 = 1; | 4038 var v1 = 1; |
| 4311 var v2 = 1; | 4039 var v2 = 1; |
| 4312 var v3 = 1; | 4040 var v3 = 1; |
| 4313 var v4 = 1; | 4041 var v4 = 1; |
| 4314 v2 = 2; | 4042 v2 = 2; |
| 4315 v4 = 2; | 4043 v4 = 2; |
| 4316 localFunction() { | 4044 localFunction() { |
| 4317 v3 = 3; | 4045 v3 = 3; |
| 4318 v4 = 3; | 4046 v4 = 3; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4330 LocalVariableElement v2 = findLocalVariable(unit, 'v2'); | 4058 LocalVariableElement v2 = findLocalVariable(unit, 'v2'); |
| 4331 LocalVariableElement v3 = findLocalVariable(unit, 'v3'); | 4059 LocalVariableElement v3 = findLocalVariable(unit, 'v3'); |
| 4332 LocalVariableElement v4 = findLocalVariable(unit, 'v4'); | 4060 LocalVariableElement v4 = findLocalVariable(unit, 'v4'); |
| 4333 expectMutated(body, v1, false, false); | 4061 expectMutated(body, v1, false, false); |
| 4334 expectMutated(body, v2, false, true); | 4062 expectMutated(body, v2, false, true); |
| 4335 expectMutated(body, v3, true, true); | 4063 expectMutated(body, v3, true, true); |
| 4336 expectMutated(body, v4, true, true); | 4064 expectMutated(body, v4, true, true); |
| 4337 } | 4065 } |
| 4338 | 4066 |
| 4339 test_perform_parameter() { | 4067 test_perform_parameter() { |
| 4340 Source source = newSource( | 4068 Source source = newSource('/test.dart', ''' |
| 4341 '/test.dart', | |
| 4342 ''' | |
| 4343 main(p1, p2, p3, p4) { | 4069 main(p1, p2, p3, p4) { |
| 4344 p2 = 2; | 4070 p2 = 2; |
| 4345 p4 = 2; | 4071 p4 = 2; |
| 4346 localFunction() { | 4072 localFunction() { |
| 4347 p3 = 3; | 4073 p3 = 3; |
| 4348 p4 = 3; | 4074 p4 = 3; |
| 4349 } | 4075 } |
| 4350 } | 4076 } |
| 4351 '''); | 4077 '''); |
| 4352 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4078 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4465 class StrongModeInferenceTest extends _AbstractDartTaskTest { | 4191 class StrongModeInferenceTest extends _AbstractDartTaskTest { |
| 4466 @override | 4192 @override |
| 4467 void setUp() { | 4193 void setUp() { |
| 4468 super.setUp(); | 4194 super.setUp(); |
| 4469 enableStrongMode(); | 4195 enableStrongMode(); |
| 4470 } | 4196 } |
| 4471 | 4197 |
| 4472 // Check that even within a static variable cycle, inferred | 4198 // Check that even within a static variable cycle, inferred |
| 4473 // types get propagated to the members of the cycle. | 4199 // types get propagated to the members of the cycle. |
| 4474 void test_perform_cycle() { | 4200 void test_perform_cycle() { |
| 4475 AnalysisTarget source = newSource( | 4201 AnalysisTarget source = newSource('/test.dart', ''' |
| 4476 '/test.dart', | |
| 4477 ''' | |
| 4478 var piFirst = true; | 4202 var piFirst = true; |
| 4479 var pi = piFirst ? 3.14 : tau / 2; | 4203 var pi = piFirst ? 3.14 : tau / 2; |
| 4480 var tau = piFirst ? pi * 2 : 6.28; | 4204 var tau = piFirst ? pi * 2 : 6.28; |
| 4481 '''); | 4205 '''); |
| 4482 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); | 4206 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 4483 CompilationUnit unit = outputs[RESOLVED_UNIT11]; | 4207 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 4484 VariableElement piFirst = | 4208 VariableElement piFirst = |
| 4485 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; | 4209 AstFinder.getTopLevelVariable(unit, 'piFirst').name.staticElement; |
| 4486 VariableElement pi = | 4210 VariableElement pi = |
| 4487 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; | 4211 AstFinder.getTopLevelVariable(unit, 'pi').name.staticElement; |
| 4488 VariableElement tau = | 4212 VariableElement tau = |
| 4489 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; | 4213 AstFinder.getTopLevelVariable(unit, 'tau').name.staticElement; |
| 4490 Expression piFirstUse = (AstFinder | 4214 Expression piFirstUse = (AstFinder |
| 4491 .getTopLevelVariable(unit, 'tau') | 4215 .getTopLevelVariable(unit, 'tau') |
| 4492 .initializer as ConditionalExpression) | 4216 .initializer as ConditionalExpression) |
| 4493 .condition; | 4217 .condition; |
| 4494 | 4218 |
| 4495 expect(piFirstUse.staticType, context.typeProvider.boolType); | 4219 expect(piFirstUse.staticType, context.typeProvider.boolType); |
| 4496 expect(piFirst.type, context.typeProvider.boolType); | 4220 expect(piFirst.type, context.typeProvider.boolType); |
| 4497 expect(pi.type.isDynamic, isTrue); | 4221 expect(pi.type.isDynamic, isTrue); |
| 4498 expect(tau.type.isDynamic, isTrue); | 4222 expect(tau.type.isDynamic, isTrue); |
| 4499 } | 4223 } |
| 4500 | 4224 |
| 4501 void test_perform_inference_cross_unit_cyclic() { | 4225 void test_perform_inference_cross_unit_cyclic() { |
| 4502 AnalysisTarget firstSource = newSource( | 4226 AnalysisTarget firstSource = newSource('/a.dart', ''' |
| 4503 '/a.dart', | |
| 4504 ''' | |
| 4505 import 'test.dart'; | 4227 import 'test.dart'; |
| 4506 var x = 2; | 4228 var x = 2; |
| 4507 class A { static var x = 2; } | 4229 class A { static var x = 2; } |
| 4508 '''); | 4230 '''); |
| 4509 AnalysisTarget secondSource = newSource( | 4231 AnalysisTarget secondSource = newSource('/test.dart', ''' |
| 4510 '/test.dart', | |
| 4511 ''' | |
| 4512 import 'a.dart'; | 4232 import 'a.dart'; |
| 4513 var y = x; | 4233 var y = x; |
| 4514 class B { static var y = A.x; } | 4234 class B { static var y = A.x; } |
| 4515 | 4235 |
| 4516 test1() { | 4236 test1() { |
| 4517 int t = 3; | 4237 int t = 3; |
| 4518 t = x; | 4238 t = x; |
| 4519 t = y; | 4239 t = y; |
| 4520 t = A.x; | 4240 t = A.x; |
| 4521 t = B.y; | 4241 t = B.y; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4634 intType); | 4354 intType); |
| 4635 assertVariableDeclarationStatementTypes( | 4355 assertVariableDeclarationStatementTypes( |
| 4636 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], | 4356 AstFinder.getStatementsInTopLevelFunction(unit2, "foo")[0], |
| 4637 stringType, | 4357 stringType, |
| 4638 intType); | 4358 intType); |
| 4639 } | 4359 } |
| 4640 | 4360 |
| 4641 // Test inference interactions between local variables and top level | 4361 // Test inference interactions between local variables and top level |
| 4642 // variables | 4362 // variables |
| 4643 void test_perform_inference_cross_unit_non_cyclic() { | 4363 void test_perform_inference_cross_unit_non_cyclic() { |
| 4644 AnalysisTarget firstSource = newSource( | 4364 AnalysisTarget firstSource = newSource('/a.dart', ''' |
| 4645 '/a.dart', | |
| 4646 ''' | |
| 4647 var x = 2; | 4365 var x = 2; |
| 4648 class A { static var x = 2; } | 4366 class A { static var x = 2; } |
| 4649 '''); | 4367 '''); |
| 4650 AnalysisTarget secondSource = newSource( | 4368 AnalysisTarget secondSource = newSource('/test.dart', ''' |
| 4651 '/test.dart', | |
| 4652 ''' | |
| 4653 import 'a.dart'; | 4369 import 'a.dart'; |
| 4654 var y = x; | 4370 var y = x; |
| 4655 class B { static var y = A.x; } | 4371 class B { static var y = A.x; } |
| 4656 | 4372 |
| 4657 test1() { | 4373 test1() { |
| 4658 x = /*severe:StaticTypeError*/"hi"; | 4374 x = /*severe:StaticTypeError*/"hi"; |
| 4659 y = /*severe:StaticTypeError*/"hi"; | 4375 y = /*severe:StaticTypeError*/"hi"; |
| 4660 A.x = /*severe:StaticTypeError*/"hi"; | 4376 A.x = /*severe:StaticTypeError*/"hi"; |
| 4661 B.y = /*severe:StaticTypeError*/"hi"; | 4377 B.y = /*severe:StaticTypeError*/"hi"; |
| 4662 } | 4378 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4736 | 4452 |
| 4737 List<Statement> statements = | 4453 List<Statement> statements = |
| 4738 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); | 4454 AstFinder.getStatementsInTopLevelFunction(unit2, "test1"); |
| 4739 | 4455 |
| 4740 assertAssignmentStatementTypes(statements[1], intType, intType); | 4456 assertAssignmentStatementTypes(statements[1], intType, intType); |
| 4741 assertAssignmentStatementTypes(statements[2], intType, dynamicType); | 4457 assertAssignmentStatementTypes(statements[2], intType, dynamicType); |
| 4742 } | 4458 } |
| 4743 | 4459 |
| 4744 // Test inference across units (non-cyclic) | 4460 // Test inference across units (non-cyclic) |
| 4745 void test_perform_inference_local_variables() { | 4461 void test_perform_inference_local_variables() { |
| 4746 AnalysisTarget source = newSource( | 4462 AnalysisTarget source = newSource('/test.dart', ''' |
| 4747 '/test.dart', | |
| 4748 ''' | |
| 4749 test() { | 4463 test() { |
| 4750 int x = 3; | 4464 int x = 3; |
| 4751 x = "hi"; | 4465 x = "hi"; |
| 4752 var y = 3; | 4466 var y = 3; |
| 4753 y = "hi"; | 4467 y = "hi"; |
| 4754 } | 4468 } |
| 4755 '''); | 4469 '''); |
| 4756 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); | 4470 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 4757 CompilationUnit unit = outputs[RESOLVED_UNIT11]; | 4471 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 4758 | 4472 |
| 4759 InterfaceType intType = context.typeProvider.intType; | 4473 InterfaceType intType = context.typeProvider.intType; |
| 4760 InterfaceType stringType = context.typeProvider.stringType; | 4474 InterfaceType stringType = context.typeProvider.stringType; |
| 4761 | 4475 |
| 4762 List<Statement> statements = | 4476 List<Statement> statements = |
| 4763 AstFinder.getStatementsInTopLevelFunction(unit, "test"); | 4477 AstFinder.getStatementsInTopLevelFunction(unit, "test"); |
| 4764 | 4478 |
| 4765 assertVariableDeclarationStatementTypes(statements[0], intType, intType); | 4479 assertVariableDeclarationStatementTypes(statements[0], intType, intType); |
| 4766 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4480 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4767 assertVariableDeclarationStatementTypes(statements[2], intType, intType); | 4481 assertVariableDeclarationStatementTypes(statements[2], intType, intType); |
| 4768 assertAssignmentStatementTypes(statements[3], intType, stringType); | 4482 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 4769 } | 4483 } |
| 4770 | 4484 |
| 4771 // Test inference across units (cyclic) | 4485 // Test inference across units (cyclic) |
| 4772 void test_perform_inference_local_variables_fields() { | 4486 void test_perform_inference_local_variables_fields() { |
| 4773 AnalysisTarget source = newSource( | 4487 AnalysisTarget source = newSource('/test.dart', ''' |
| 4774 '/test.dart', | |
| 4775 ''' | |
| 4776 class A { | 4488 class A { |
| 4777 int x = 0; | 4489 int x = 0; |
| 4778 | 4490 |
| 4779 test1() { | 4491 test1() { |
| 4780 var a = x; | 4492 var a = x; |
| 4781 a = "hi"; | 4493 a = "hi"; |
| 4782 a = 3; | 4494 a = 3; |
| 4783 var b = y; | 4495 var b = y; |
| 4784 b = "hi"; | 4496 b = "hi"; |
| 4785 b = 4; | 4497 b = 4; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4814 assertAssignmentStatementTypes(statements[8], intType, intType); | 4526 assertAssignmentStatementTypes(statements[8], intType, intType); |
| 4815 | 4527 |
| 4816 assertVariableDeclarationTypes( | 4528 assertVariableDeclarationTypes( |
| 4817 AstFinder.getFieldInClass(unit, "A", "x"), intType, intType); | 4529 AstFinder.getFieldInClass(unit, "A", "x"), intType, intType); |
| 4818 assertVariableDeclarationTypes( | 4530 assertVariableDeclarationTypes( |
| 4819 AstFinder.getFieldInClass(unit, "A", "z"), intType, intType); | 4531 AstFinder.getFieldInClass(unit, "A", "z"), intType, intType); |
| 4820 } | 4532 } |
| 4821 | 4533 |
| 4822 // Test inference of instance fields across units | 4534 // Test inference of instance fields across units |
| 4823 void test_perform_inference_local_variables_topLevel() { | 4535 void test_perform_inference_local_variables_topLevel() { |
| 4824 AnalysisTarget source = newSource( | 4536 AnalysisTarget source = newSource('/test.dart', ''' |
| 4825 '/test.dart', | |
| 4826 ''' | |
| 4827 int x = 0; | 4537 int x = 0; |
| 4828 | 4538 |
| 4829 test1() { | 4539 test1() { |
| 4830 var a = x; | 4540 var a = x; |
| 4831 a = /*severe:StaticTypeError*/"hi"; | 4541 a = /*severe:StaticTypeError*/"hi"; |
| 4832 a = 3; | 4542 a = 3; |
| 4833 var b = y; | 4543 var b = y; |
| 4834 b = /*severe:StaticTypeError*/"hi"; | 4544 b = /*severe:StaticTypeError*/"hi"; |
| 4835 b = 4; | 4545 b = 4; |
| 4836 var c = z; | 4546 var c = z; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4865 assertVariableDeclarationTypes( | 4575 assertVariableDeclarationTypes( |
| 4866 AstFinder.getTopLevelVariable(unit, "x"), intType, intType); | 4576 AstFinder.getTopLevelVariable(unit, "x"), intType, intType); |
| 4867 assertVariableDeclarationTypes( | 4577 assertVariableDeclarationTypes( |
| 4868 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); | 4578 AstFinder.getTopLevelVariable(unit, "y"), intType, intType); |
| 4869 assertVariableDeclarationTypes( | 4579 assertVariableDeclarationTypes( |
| 4870 AstFinder.getTopLevelVariable(unit, "z"), intType, intType); | 4580 AstFinder.getTopLevelVariable(unit, "z"), intType, intType); |
| 4871 } | 4581 } |
| 4872 | 4582 |
| 4873 // Test inference between static and instance fields | 4583 // Test inference between static and instance fields |
| 4874 void test_perform_inference_null() { | 4584 void test_perform_inference_null() { |
| 4875 AnalysisTarget source = newSource( | 4585 AnalysisTarget source = newSource('/test.dart', ''' |
| 4876 '/test.dart', | |
| 4877 ''' | |
| 4878 var x = null; | 4586 var x = null; |
| 4879 var y = 3; | 4587 var y = 3; |
| 4880 class A { | 4588 class A { |
| 4881 static var x = null; | 4589 static var x = null; |
| 4882 static var y = 3; | 4590 static var y = 3; |
| 4883 | 4591 |
| 4884 var x2 = null; | 4592 var x2 = null; |
| 4885 var y2 = 3; | 4593 var y2 = 3; |
| 4886 } | 4594 } |
| 4887 | 4595 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4921 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); | 4629 assertAssignmentStatementTypes(statements[0], dynamicType, stringType); |
| 4922 assertAssignmentStatementTypes(statements[1], intType, stringType); | 4630 assertAssignmentStatementTypes(statements[1], intType, stringType); |
| 4923 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); | 4631 assertAssignmentStatementTypes(statements[2], dynamicType, stringType); |
| 4924 assertAssignmentStatementTypes(statements[3], intType, stringType); | 4632 assertAssignmentStatementTypes(statements[3], intType, stringType); |
| 4925 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); | 4633 assertAssignmentStatementTypes(statements[4], dynamicType, stringType); |
| 4926 assertAssignmentStatementTypes(statements[5], intType, stringType); | 4634 assertAssignmentStatementTypes(statements[5], intType, stringType); |
| 4927 } | 4635 } |
| 4928 | 4636 |
| 4929 // Test inference between fields and method bodies | 4637 // Test inference between fields and method bodies |
| 4930 void test_perform_local_explicit_disabled() { | 4638 void test_perform_local_explicit_disabled() { |
| 4931 AnalysisTarget source = newSource( | 4639 AnalysisTarget source = newSource('/test.dart', ''' |
| 4932 '/test.dart', | |
| 4933 ''' | |
| 4934 test() { | 4640 test() { |
| 4935 int x = 3; | 4641 int x = 3; |
| 4936 x = "hi"; | 4642 x = "hi"; |
| 4937 } | 4643 } |
| 4938 '''); | 4644 '''); |
| 4939 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); | 4645 computeResult(new LibrarySpecificUnit(source, source), RESOLVED_UNIT11); |
| 4940 CompilationUnit unit = outputs[RESOLVED_UNIT11]; | 4646 CompilationUnit unit = outputs[RESOLVED_UNIT11]; |
| 4941 | 4647 |
| 4942 InterfaceType intType = context.typeProvider.intType; | 4648 InterfaceType intType = context.typeProvider.intType; |
| 4943 InterfaceType stringType = context.typeProvider.stringType; | 4649 InterfaceType stringType = context.typeProvider.stringType; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4959 | 4665 |
| 4960 @reflectiveTest | 4666 @reflectiveTest |
| 4961 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { | 4667 class StrongModeVerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 4962 @override | 4668 @override |
| 4963 void setUp() { | 4669 void setUp() { |
| 4964 super.setUp(); | 4670 super.setUp(); |
| 4965 enableStrongMode(); | 4671 enableStrongMode(); |
| 4966 } | 4672 } |
| 4967 | 4673 |
| 4968 test_created_resolved_unit() { | 4674 test_created_resolved_unit() { |
| 4969 Source source = newSource( | 4675 Source source = newSource('/test.dart', r''' |
| 4970 '/test.dart', | |
| 4971 r''' | |
| 4972 library lib; | 4676 library lib; |
| 4973 class A {} | 4677 class A {} |
| 4974 '''); | 4678 '''); |
| 4975 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4679 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 4976 computeResult(target, RESOLVED_UNIT); | 4680 computeResult(target, RESOLVED_UNIT); |
| 4977 expect(outputs[RESOLVED_UNIT], isNotNull); | 4681 expect(outputs[RESOLVED_UNIT], isNotNull); |
| 4978 expect(outputs[CREATED_RESOLVED_UNIT], isTrue); | 4682 expect(outputs[CREATED_RESOLVED_UNIT], isTrue); |
| 4979 } | 4683 } |
| 4980 | 4684 |
| 4981 void test_perform_recordDynamicInvoke() { | 4685 void test_perform_recordDynamicInvoke() { |
| 4982 enableStrongMode(); | 4686 enableStrongMode(); |
| 4983 AnalysisTarget source = newSource( | 4687 AnalysisTarget source = newSource('/test.dart', ''' |
| 4984 '/test.dart', | |
| 4985 ''' | |
| 4986 void main() { | 4688 void main() { |
| 4987 dynamic a = []; | 4689 dynamic a = []; |
| 4988 a[0]; | 4690 a[0]; |
| 4989 } | 4691 } |
| 4990 '''); | 4692 '''); |
| 4991 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); | 4693 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 4992 CompilationUnit unit = outputs[RESOLVED_UNIT]; | 4694 CompilationUnit unit = outputs[RESOLVED_UNIT]; |
| 4993 | 4695 |
| 4994 // validate | 4696 // validate |
| 4995 _fillErrorListener(STRONG_MODE_ERRORS); | 4697 _fillErrorListener(STRONG_MODE_ERRORS); |
| 4996 expect(errorListener.errors, isEmpty); | 4698 expect(errorListener.errors, isEmpty); |
| 4997 | 4699 |
| 4998 List<Statement> statements = | 4700 List<Statement> statements = |
| 4999 AstFinder.getStatementsInTopLevelFunction(unit, "main"); | 4701 AstFinder.getStatementsInTopLevelFunction(unit, "main"); |
| 5000 ExpressionStatement statement = statements[1]; | 4702 ExpressionStatement statement = statements[1]; |
| 5001 IndexExpression idx = statement.expression; | 4703 IndexExpression idx = statement.expression; |
| 5002 expect(strong_ast.isDynamicInvoke(idx.target), isTrue); | 4704 expect(strong_ast.isDynamicInvoke(idx.target), isTrue); |
| 5003 } | 4705 } |
| 5004 | 4706 |
| 5005 void test_perform_verifyError() { | 4707 void test_perform_verifyError() { |
| 5006 enableStrongMode(); | 4708 enableStrongMode(); |
| 5007 AnalysisTarget source = newSource( | 4709 AnalysisTarget source = newSource('/test.dart', ''' |
| 5008 '/test.dart', | |
| 5009 ''' | |
| 5010 class A {} | 4710 class A {} |
| 5011 class B extends A {} | 4711 class B extends A {} |
| 5012 B b = new A(); | 4712 B b = new A(); |
| 5013 '''); | 4713 '''); |
| 5014 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); | 4714 computeResult(new LibrarySpecificUnit(source, source), STRONG_MODE_ERRORS); |
| 5015 // validate | 4715 // validate |
| 5016 _fillErrorListener(STRONG_MODE_ERRORS); | 4716 _fillErrorListener(STRONG_MODE_ERRORS); |
| 5017 | 4717 |
| 5018 var errors = errorListener.errors; | 4718 var errors = errorListener.errors; |
| 5019 expect(errors.length, 1); | 4719 expect(errors.length, 1); |
| 5020 expect(errors[0].errorCode.name, "STRONG_MODE_INVALID_CAST_NEW_EXPR"); | 4720 expect(errors[0].errorCode.name, "STRONG_MODE_INVALID_CAST_NEW_EXPR"); |
| 5021 } | 4721 } |
| 5022 } | 4722 } |
| 5023 | 4723 |
| 5024 @reflectiveTest | 4724 @reflectiveTest |
| 5025 class VerifyUnitTaskTest extends _AbstractDartTaskTest { | 4725 class VerifyUnitTaskTest extends _AbstractDartTaskTest { |
| 5026 test_perform_constantError() { | 4726 test_perform_constantError() { |
| 5027 Source source = newSource( | 4727 Source source = newSource('/test.dart', ''' |
| 5028 '/test.dart', | |
| 5029 ''' | |
| 5030 main(int p) { | 4728 main(int p) { |
| 5031 const v = p; | 4729 const v = p; |
| 5032 } | 4730 } |
| 5033 '''); | 4731 '''); |
| 5034 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4732 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5035 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4733 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5036 // validate | 4734 // validate |
| 5037 _fillErrorListener(VERIFY_ERRORS); | 4735 _fillErrorListener(VERIFY_ERRORS); |
| 5038 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 4736 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 5039 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 4737 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 5040 ]); | 4738 ]); |
| 5041 } | 4739 } |
| 5042 | 4740 |
| 5043 test_perform_ConstantValidator_declaredIdentifier() { | 4741 test_perform_ConstantValidator_declaredIdentifier() { |
| 5044 Source source = newSource( | 4742 Source source = newSource('/test.dart', ''' |
| 5045 '/test.dart', | |
| 5046 ''' | |
| 5047 void main() { | 4743 void main() { |
| 5048 for (const foo in []) { | 4744 for (const foo in []) { |
| 5049 print(foo); | 4745 print(foo); |
| 5050 } | 4746 } |
| 5051 } | 4747 } |
| 5052 '''); | 4748 '''); |
| 5053 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4749 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5054 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4750 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5055 // validate | 4751 // validate |
| 5056 _fillErrorListener(VERIFY_ERRORS); | 4752 _fillErrorListener(VERIFY_ERRORS); |
| 5057 errorListener.assertNoErrors(); | 4753 errorListener.assertNoErrors(); |
| 5058 } | 4754 } |
| 5059 | 4755 |
| 5060 test_perform_ConstantValidator_dependencyCycle() { | 4756 test_perform_ConstantValidator_dependencyCycle() { |
| 5061 Source source = newSource( | 4757 Source source = newSource('/test.dart', ''' |
| 5062 '/test.dart', | |
| 5063 ''' | |
| 5064 const int a = b; | 4758 const int a = b; |
| 5065 const int b = c; | 4759 const int b = c; |
| 5066 const int c = a; | 4760 const int c = a; |
| 5067 '''); | 4761 '''); |
| 5068 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4762 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5069 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4763 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5070 // validate | 4764 // validate |
| 5071 _fillErrorListener(VERIFY_ERRORS); | 4765 _fillErrorListener(VERIFY_ERRORS); |
| 5072 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 4766 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 5073 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, | 4767 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 5074 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, | 4768 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT, |
| 5075 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT | 4769 CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT |
| 5076 ]); | 4770 ]); |
| 5077 } | 4771 } |
| 5078 | 4772 |
| 5079 test_perform_ConstantValidator_duplicateFields() { | 4773 test_perform_ConstantValidator_duplicateFields() { |
| 5080 Source source = newSource( | 4774 Source source = newSource('/test.dart', ''' |
| 5081 '/test.dart', | |
| 5082 ''' | |
| 5083 class Test { | 4775 class Test { |
| 5084 final int x = 1; | 4776 final int x = 1; |
| 5085 final int x = 2; | 4777 final int x = 2; |
| 5086 const Test(); | 4778 const Test(); |
| 5087 } | 4779 } |
| 5088 | 4780 |
| 5089 main() { | 4781 main() { |
| 5090 const Test(); | 4782 const Test(); |
| 5091 } | 4783 } |
| 5092 '''); | 4784 '''); |
| 5093 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4785 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5094 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4786 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5095 // validate | 4787 // validate |
| 5096 _fillErrorListener(VERIFY_ERRORS); | 4788 _fillErrorListener(VERIFY_ERRORS); |
| 5097 errorListener | 4789 errorListener |
| 5098 .assertErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]); | 4790 .assertErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]); |
| 5099 } | 4791 } |
| 5100 | 4792 |
| 5101 test_perform_ConstantValidator_noInitializer() { | 4793 test_perform_ConstantValidator_noInitializer() { |
| 5102 Source source = newSource( | 4794 Source source = newSource('/test.dart', ''' |
| 5103 '/test.dart', | |
| 5104 ''' | |
| 5105 const x; | 4795 const x; |
| 5106 '''); | 4796 '''); |
| 5107 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4797 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5108 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4798 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5109 // validate | 4799 // validate |
| 5110 _fillErrorListener(VERIFY_ERRORS); | 4800 _fillErrorListener(VERIFY_ERRORS); |
| 5111 errorListener.assertErrorsWithCodes( | 4801 errorListener.assertErrorsWithCodes( |
| 5112 <ErrorCode>[CompileTimeErrorCode.CONST_NOT_INITIALIZED]); | 4802 <ErrorCode>[CompileTimeErrorCode.CONST_NOT_INITIALIZED]); |
| 5113 } | 4803 } |
| 5114 | 4804 |
| 5115 test_perform_ConstantValidator_unknownValue() { | 4805 test_perform_ConstantValidator_unknownValue() { |
| 5116 Source source = newSource( | 4806 Source source = newSource('/test.dart', ''' |
| 5117 '/test.dart', | |
| 5118 ''' | |
| 5119 import 'no-such-file.dart' as p; | 4807 import 'no-such-file.dart' as p; |
| 5120 | 4808 |
| 5121 const int x = p.y; | 4809 const int x = p.y; |
| 5122 '''); | 4810 '''); |
| 5123 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4811 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5124 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4812 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5125 // validate | 4813 // validate |
| 5126 _fillErrorListener(VERIFY_ERRORS); | 4814 _fillErrorListener(VERIFY_ERRORS); |
| 5127 errorListener.assertErrorsWithCodes(<ErrorCode>[ | 4815 errorListener.assertErrorsWithCodes(<ErrorCode>[ |
| 5128 CompileTimeErrorCode.URI_DOES_NOT_EXIST, | 4816 CompileTimeErrorCode.URI_DOES_NOT_EXIST, |
| 5129 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE | 4817 CompileTimeErrorCode.CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE |
| 5130 ]); | 4818 ]); |
| 5131 } | 4819 } |
| 5132 | 4820 |
| 5133 test_perform_directiveError_generated() { | 4821 test_perform_directiveError_generated() { |
| 5134 Source source = newSource( | 4822 Source source = newSource('/test.dart', ''' |
| 5135 '/test.dart', | |
| 5136 ''' | |
| 5137 import 'generated-file.g.dart'; | 4823 import 'generated-file.g.dart'; |
| 5138 '''); | 4824 '''); |
| 5139 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4825 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5140 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4826 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5141 // validate | 4827 // validate |
| 5142 _fillErrorListener(VERIFY_ERRORS); | 4828 _fillErrorListener(VERIFY_ERRORS); |
| 5143 errorListener.assertErrorsWithCodes( | 4829 errorListener.assertErrorsWithCodes( |
| 5144 <ErrorCode>[CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED]); | 4830 <ErrorCode>[CompileTimeErrorCode.URI_HAS_NOT_BEEN_GENERATED]); |
| 5145 } | 4831 } |
| 5146 | 4832 |
| 5147 test_perform_directiveError_nonGenerated() { | 4833 test_perform_directiveError_nonGenerated() { |
| 5148 Source source = newSource( | 4834 Source source = newSource('/test.dart', ''' |
| 5149 '/test.dart', | |
| 5150 ''' | |
| 5151 import 'no-such-file.dart'; | 4835 import 'no-such-file.dart'; |
| 5152 '''); | 4836 '''); |
| 5153 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4837 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5154 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4838 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5155 // validate | 4839 // validate |
| 5156 _fillErrorListener(VERIFY_ERRORS); | 4840 _fillErrorListener(VERIFY_ERRORS); |
| 5157 errorListener.assertErrorsWithCodes( | 4841 errorListener.assertErrorsWithCodes( |
| 5158 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); | 4842 <ErrorCode>[CompileTimeErrorCode.URI_DOES_NOT_EXIST]); |
| 5159 } | 4843 } |
| 5160 | 4844 |
| 5161 void test_perform_reresolution() { | 4845 void test_perform_reresolution() { |
| 5162 enableStrongMode(); | 4846 enableStrongMode(); |
| 5163 AnalysisTarget source = newSource( | 4847 AnalysisTarget source = newSource('/test.dart', ''' |
| 5164 '/test.dart', | |
| 5165 ''' | |
| 5166 const topLevel = 3; | 4848 const topLevel = 3; |
| 5167 class C { | 4849 class C { |
| 5168 String field = topLevel; | 4850 String field = topLevel; |
| 5169 } | 4851 } |
| 5170 '''); | 4852 '''); |
| 5171 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); | 4853 computeResult(new LibrarySpecificUnit(source, source), VERIFY_ERRORS); |
| 5172 // validate | 4854 // validate |
| 5173 _fillErrorListener(VERIFY_ERRORS); | 4855 _fillErrorListener(VERIFY_ERRORS); |
| 5174 | 4856 |
| 5175 var errors = errorListener.errors; | 4857 var errors = errorListener.errors; |
| 5176 expect(errors.length, 1); | 4858 expect(errors.length, 1); |
| 5177 expect(errors[0].errorCode, StaticTypeWarningCode.INVALID_ASSIGNMENT); | 4859 expect(errors[0].errorCode, StaticTypeWarningCode.INVALID_ASSIGNMENT); |
| 5178 } | 4860 } |
| 5179 | 4861 |
| 5180 test_perform_verifyError() { | 4862 test_perform_verifyError() { |
| 5181 Source source = newSource( | 4863 Source source = newSource('/test.dart', ''' |
| 5182 '/test.dart', | |
| 5183 ''' | |
| 5184 main() { | 4864 main() { |
| 5185 if (42) { | 4865 if (42) { |
| 5186 print('Not bool!'); | 4866 print('Not bool!'); |
| 5187 } | 4867 } |
| 5188 } | 4868 } |
| 5189 '''); | 4869 '''); |
| 5190 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 4870 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 5191 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); | 4871 computeResult(target, VERIFY_ERRORS, matcher: isVerifyUnitTask); |
| 5192 // validate | 4872 // validate |
| 5193 _fillErrorListener(VERIFY_ERRORS); | 4873 _fillErrorListener(VERIFY_ERRORS); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5310 /** | 4990 /** |
| 5311 * Fill [errorListener] with [result] errors in the current [task]. | 4991 * Fill [errorListener] with [result] errors in the current [task]. |
| 5312 */ | 4992 */ |
| 5313 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4993 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 5314 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 4994 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
| 5315 expect(errors, isNotNull, reason: result.name); | 4995 expect(errors, isNotNull, reason: result.name); |
| 5316 errorListener = new GatheringErrorListener(); | 4996 errorListener = new GatheringErrorListener(); |
| 5317 errorListener.addAll(errors); | 4997 errorListener.addAll(errors); |
| 5318 } | 4998 } |
| 5319 } | 4999 } |
| OLD | NEW |