| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/token.dart'; | 6 import 'package:analyzer/dart/ast/token.dart'; |
| 7 import 'package:analyzer/file_system/file_system.dart'; | 7 import 'package:analyzer/file_system/file_system.dart'; |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | 8 import 'package:analyzer/file_system/memory_file_system.dart'; |
| 9 import 'package:analyzer/src/dart/sdk/patch.dart'; | 9 import 'package:analyzer/src/dart/sdk/patch.dart'; |
| 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 10 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 r''' | 155 r''' |
| 156 @patch | 156 @patch |
| 157 class C { | 157 class C { |
| 158 @patch | 158 @patch |
| 159 factory C.named() {} | 159 factory C.named() {} |
| 160 } | 160 } |
| 161 '''); | 161 '''); |
| 162 }, throwsArgumentError); | 162 }, throwsArgumentError); |
| 163 } | 163 } |
| 164 | 164 |
| 165 test_class_constructor_patch_fail_fieldFormalParam_inBase() { |
| 166 expect(() { |
| 167 _doTopLevelPatching( |
| 168 r''' |
| 169 class C { |
| 170 int f; |
| 171 external C.named(this.f); |
| 172 } |
| 173 ''', |
| 174 r''' |
| 175 @patch |
| 176 class C { |
| 177 @patch |
| 178 C.named() : f = 2 {} |
| 179 } |
| 180 '''); |
| 181 }, throwsArgumentError); |
| 182 } |
| 183 |
| 184 test_class_constructor_patch_fail_fieldFormalParam_inPatch() { |
| 185 expect(() { |
| 186 _doTopLevelPatching( |
| 187 r''' |
| 188 class C { |
| 189 int f; |
| 190 external C.named(int f); |
| 191 } |
| 192 ''', |
| 193 r''' |
| 194 @patch |
| 195 class C { |
| 196 @patch |
| 197 C.named(this.f) {} |
| 198 } |
| 199 '''); |
| 200 }, throwsArgumentError); |
| 201 } |
| 202 |
| 203 test_class_constructor_patch_fail_fieldFormalParam_inPatchAndBase() { |
| 204 expect(() { |
| 205 _doTopLevelPatching( |
| 206 r''' |
| 207 class C { |
| 208 int f; |
| 209 external C.named(this.f); |
| 210 } |
| 211 ''', |
| 212 r''' |
| 213 @patch |
| 214 class C { |
| 215 @patch |
| 216 C.named(this.f) {} |
| 217 } |
| 218 '''); |
| 219 }, throwsArgumentError); |
| 220 } |
| 221 |
| 165 test_class_constructor_patch_fail_hasInitializers() { | 222 test_class_constructor_patch_fail_hasInitializers() { |
| 166 expect(() { | 223 expect(() { |
| 167 _doTopLevelPatching( | 224 _doTopLevelPatching( |
| 168 r''' | 225 r''' |
| 169 class C { | 226 class C { |
| 170 int f; | 227 int f; |
| 171 external C.named() : f = 1; | 228 external C.named() : f = 1; |
| 172 } | 229 } |
| 173 ''', | 230 ''', |
| 174 r''' | 231 r''' |
| (...skipping 17 matching lines...) Expand all Loading... |
| 192 r''' | 249 r''' |
| 193 @patch | 250 @patch |
| 194 class C { | 251 class C { |
| 195 @patch | 252 @patch |
| 196 C.named() {} | 253 C.named() {} |
| 197 } | 254 } |
| 198 '''); | 255 '''); |
| 199 }, throwsArgumentError); | 256 }, throwsArgumentError); |
| 200 } | 257 } |
| 201 | 258 |
| 259 test_class_constructor_patch_fail_signatureChange() { |
| 260 expect(() { |
| 261 _doTopLevelPatching( |
| 262 r''' |
| 263 class C { |
| 264 external C.named(int x); |
| 265 } |
| 266 ''', |
| 267 r''' |
| 268 @patch |
| 269 class C { |
| 270 @patch |
| 271 C.named(double x) {} |
| 272 } |
| 273 '''); |
| 274 }, throwsArgumentError); |
| 275 } |
| 276 |
| 277 test_class_constructor_patch_fail_signatureChange_nameOnly() { |
| 278 expect(() { |
| 279 _doTopLevelPatching( |
| 280 r''' |
| 281 class C { |
| 282 external C.named(int x); |
| 283 } |
| 284 ''', |
| 285 r''' |
| 286 @patch |
| 287 class C { |
| 288 @patch |
| 289 C.named(int y) {} |
| 290 } |
| 291 '''); |
| 292 }, throwsArgumentError); |
| 293 } |
| 294 |
| 202 test_class_constructor_patch_initializers() { | 295 test_class_constructor_patch_initializers() { |
| 203 CompilationUnit unit = _doTopLevelPatching( | 296 CompilationUnit unit = _doTopLevelPatching( |
| 204 r''' | 297 r''' |
| 205 class C { | 298 class C { |
| 206 int f; | 299 int f; |
| 207 external C.named(); | 300 external C.named(); |
| 208 } | 301 } |
| 209 ''', | 302 ''', |
| 210 r''' | 303 r''' |
| 211 @patch | 304 @patch |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 r''' | 496 r''' |
| 404 @patch | 497 @patch |
| 405 class C { | 498 class C { |
| 406 @patch | 499 @patch |
| 407 int m() => 42; | 500 int m() => 42; |
| 408 } | 501 } |
| 409 '''); | 502 '''); |
| 410 }, throwsArgumentError); | 503 }, throwsArgumentError); |
| 411 } | 504 } |
| 412 | 505 |
| 506 test_class_method_patch_fail_signatureChange() { |
| 507 expect(() { |
| 508 _doTopLevelPatching( |
| 509 r''' |
| 510 class C { |
| 511 external void f(int x); |
| 512 } |
| 513 ''', |
| 514 r''' |
| 515 @patch |
| 516 class C { |
| 517 @patch |
| 518 void f(double x) {} |
| 519 } |
| 520 '''); |
| 521 }, throwsArgumentError); |
| 522 } |
| 523 |
| 524 test_class_method_patch_fail_signatureChange_extraArgument() { |
| 525 expect(() { |
| 526 _doTopLevelPatching( |
| 527 r''' |
| 528 class C { |
| 529 external void f(); |
| 530 } |
| 531 ''', |
| 532 r''' |
| 533 @patch |
| 534 class C { |
| 535 @patch |
| 536 void f(int x) {} |
| 537 } |
| 538 '''); |
| 539 }, throwsArgumentError); |
| 540 } |
| 541 |
| 542 test_class_method_patch_fail_signatureChange_extraTypeTokens() { |
| 543 expect(() { |
| 544 _doTopLevelPatching( |
| 545 r''' |
| 546 class C { |
| 547 external List f(); |
| 548 } |
| 549 ''', |
| 550 r''' |
| 551 @patch |
| 552 class C { |
| 553 @patch |
| 554 List<int> f() => null; |
| 555 } |
| 556 '''); |
| 557 }, throwsArgumentError); |
| 558 } |
| 559 |
| 560 test_class_method_patch_fail_signatureChange_functionTypedParam_paramType() { |
| 561 expect(() { |
| 562 _doTopLevelPatching( |
| 563 r''' |
| 564 class C { |
| 565 external void f(void x(int y)); |
| 566 } |
| 567 ''', |
| 568 r''' |
| 569 @patch |
| 570 class C { |
| 571 @patch |
| 572 void f(void x(double y)) {} |
| 573 } |
| 574 '''); |
| 575 }, throwsArgumentError); |
| 576 } |
| 577 |
| 578 test_class_method_patch_fail_signatureChange_functionTypedParam_returnType() { |
| 579 expect(() { |
| 580 _doTopLevelPatching( |
| 581 r''' |
| 582 class C { |
| 583 external void f(int x()); |
| 584 } |
| 585 ''', |
| 586 r''' |
| 587 @patch |
| 588 class C { |
| 589 @patch |
| 590 void f(double x()) {} |
| 591 } |
| 592 '''); |
| 593 }, throwsArgumentError); |
| 594 } |
| 595 |
| 596 test_class_method_patch_fail_signatureChange_makeReturnTypeExplicit() { |
| 597 expect(() { |
| 598 _doTopLevelPatching( |
| 599 r''' |
| 600 class C { |
| 601 external f(); |
| 602 } |
| 603 ''', |
| 604 r''' |
| 605 @patch |
| 606 class C { |
| 607 @patch |
| 608 int f() => 0; |
| 609 } |
| 610 '''); |
| 611 }, throwsArgumentError); |
| 612 } |
| 613 |
| 614 test_class_method_patch_fail_signatureChange_missingArgument() { |
| 615 expect(() { |
| 616 _doTopLevelPatching( |
| 617 r''' |
| 618 class C { |
| 619 external void f(int x); |
| 620 } |
| 621 ''', |
| 622 r''' |
| 623 @patch |
| 624 class C { |
| 625 @patch |
| 626 void f() {} |
| 627 } |
| 628 '''); |
| 629 }, throwsArgumentError); |
| 630 } |
| 631 |
| 632 test_class_method_patch_fail_signatureChange_missingTypeTokens() { |
| 633 expect(() { |
| 634 _doTopLevelPatching( |
| 635 r''' |
| 636 class C { |
| 637 external List<int> f(); |
| 638 } |
| 639 ''', |
| 640 r''' |
| 641 @patch |
| 642 class C { |
| 643 @patch |
| 644 List f() => null; |
| 645 } |
| 646 '''); |
| 647 }, throwsArgumentError); |
| 648 } |
| 649 |
| 650 test_class_method_patch_fail_signatureChange_nameOnly() { |
| 651 expect(() { |
| 652 _doTopLevelPatching( |
| 653 r''' |
| 654 class C { |
| 655 external void f(int x); |
| 656 } |
| 657 ''', |
| 658 r''' |
| 659 @patch |
| 660 class C { |
| 661 @patch |
| 662 void f(int y) {} |
| 663 } |
| 664 '''); |
| 665 }, throwsArgumentError); |
| 666 } |
| 667 |
| 668 test_class_method_patch_fail_signatureChange_returnTypeOnly() { |
| 669 expect(() { |
| 670 _doTopLevelPatching( |
| 671 r''' |
| 672 class C { |
| 673 external void f(int x); |
| 674 } |
| 675 ''', |
| 676 r''' |
| 677 @patch |
| 678 class C { |
| 679 @patch |
| 680 int f(int x) {} |
| 681 } |
| 682 '''); |
| 683 }, throwsArgumentError); |
| 684 } |
| 685 |
| 686 test_class_method_patch_success_defaultFormalParameter() { |
| 687 CompilationUnit unit = _doTopLevelPatching( |
| 688 r''' |
| 689 class C { |
| 690 external void f(int x = 0); |
| 691 } |
| 692 ''', |
| 693 r''' |
| 694 @patch |
| 695 class C { |
| 696 @patch |
| 697 void f(int x) {} |
| 698 } |
| 699 '''); |
| 700 ClassDeclaration cls = unit.declarations[0]; |
| 701 MethodDeclaration method = cls.members[0]; |
| 702 FormalParameter parameter = method.parameters.parameters[0]; |
| 703 expect(parameter, new isInstanceOf<DefaultFormalParameter>()); |
| 704 } |
| 705 |
| 706 test_class_method_patch_success_implicitReturnType() { |
| 707 _doTopLevelPatching( |
| 708 r''' |
| 709 class C { |
| 710 external f(); |
| 711 } |
| 712 ''', |
| 713 r''' |
| 714 @patch |
| 715 class C { |
| 716 @patch |
| 717 f() => null; |
| 718 } |
| 719 '''); |
| 720 } |
| 721 |
| 722 test_class_method_patch_success_multiTokenReturnType() { |
| 723 _doTopLevelPatching( |
| 724 r''' |
| 725 class C { |
| 726 external List<int> f(); |
| 727 } |
| 728 ''', |
| 729 r''' |
| 730 @patch |
| 731 class C { |
| 732 @patch |
| 733 List<int> f() => null; |
| 734 } |
| 735 '''); |
| 736 } |
| 737 |
| 738 test_class_method_patch_success_signatureChange_functionTypedParam_matching()
{ |
| 739 _doTopLevelPatching( |
| 740 r''' |
| 741 class C { |
| 742 external void f(void x(int y)); |
| 743 } |
| 744 ''', |
| 745 r''' |
| 746 @patch |
| 747 class C { |
| 748 @patch |
| 749 void f(void x(int y)) {} |
| 750 } |
| 751 '''); |
| 752 } |
| 753 |
| 413 test_class_setter_append() { | 754 test_class_setter_append() { |
| 414 CompilationUnit unit = _doTopLevelPatching( | 755 CompilationUnit unit = _doTopLevelPatching( |
| 415 r''' | 756 r''' |
| 416 class C { | 757 class C { |
| 417 void a() {} | 758 void a() {} |
| 418 } | 759 } |
| 419 ''', | 760 ''', |
| 420 r''' | 761 r''' |
| 421 @patch | 762 @patch |
| 422 class C { | 763 class C { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 r''' | 1087 r''' |
| 747 external int foo(); | 1088 external int foo(); |
| 748 ''', | 1089 ''', |
| 749 r''' | 1090 r''' |
| 750 @patch | 1091 @patch |
| 751 int foo() {int v = 1; return v + 2;} | 1092 int foo() {int v = 1; return v + 2;} |
| 752 '''); | 1093 '''); |
| 753 _assertUnitCode(unit, 'int foo() {int v = 1; return v + 2;}'); | 1094 _assertUnitCode(unit, 'int foo() {int v = 1; return v + 2;}'); |
| 754 } | 1095 } |
| 755 | 1096 |
| 1097 test_topLevel_patch_function_fail_signatureChange() { |
| 1098 expect(() { |
| 1099 _doTopLevelPatching( |
| 1100 r''' |
| 1101 external void f(int x); |
| 1102 ''', |
| 1103 r''' |
| 1104 @patch |
| 1105 void f(double x) {} |
| 1106 '''); |
| 1107 }, throwsArgumentError); |
| 1108 } |
| 1109 |
| 1110 test_topLevel_patch_function_fail_signatureChange_nameOnly() { |
| 1111 expect(() { |
| 1112 _doTopLevelPatching( |
| 1113 r''' |
| 1114 external void f(int x); |
| 1115 ''', |
| 1116 r''' |
| 1117 @patch |
| 1118 void f(int y) {} |
| 1119 '''); |
| 1120 }, throwsArgumentError); |
| 1121 } |
| 1122 |
| 1123 test_topLevel_patch_function_fail_signatureChange_returnTypeOnly() { |
| 1124 expect(() { |
| 1125 _doTopLevelPatching( |
| 1126 r''' |
| 1127 external void f(int x); |
| 1128 ''', |
| 1129 r''' |
| 1130 @patch |
| 1131 int f(int x) {} |
| 1132 '''); |
| 1133 }, throwsArgumentError); |
| 1134 } |
| 1135 |
| 756 test_topLevel_patch_getter() { | 1136 test_topLevel_patch_getter() { |
| 757 CompilationUnit unit = _doTopLevelPatching( | 1137 CompilationUnit unit = _doTopLevelPatching( |
| 758 r''' | 1138 r''' |
| 759 external int get foo; | 1139 external int get foo; |
| 760 int bar() => 2; | 1140 int bar() => 2; |
| 761 ''', | 1141 ''', |
| 762 r''' | 1142 r''' |
| 763 @patch | 1143 @patch |
| 764 int get foo => 1; | 1144 int get foo => 1; |
| 765 '''); | 1145 '''); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 void _setSdkLibraries(String code) { | 1207 void _setSdkLibraries(String code) { |
| 828 provider.newFile( | 1208 provider.newFile( |
| 829 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); | 1209 _p('/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart'), code); |
| 830 } | 1210 } |
| 831 | 1211 |
| 832 static void _assertPrevNextToken(Token prev, Token next) { | 1212 static void _assertPrevNextToken(Token prev, Token next) { |
| 833 expect(prev.next, same(next)); | 1213 expect(prev.next, same(next)); |
| 834 expect(next.previous, same(prev)); | 1214 expect(next.previous, same(prev)); |
| 835 } | 1215 } |
| 836 } | 1216 } |
| OLD | NEW |