OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library engine.incremental_resolver_test; |
| 6 |
| 7 import 'package:analyzer/src/context/cache.dart' as task; |
| 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/element.dart'; |
| 10 import 'package:analyzer/src/generated/engine.dart'; |
| 11 import 'package:analyzer/src/generated/error.dart'; |
| 12 import 'package:analyzer/src/generated/incremental_logger.dart' as log; |
| 13 import 'package:analyzer/src/generated/incremental_resolution_validator.dart'; |
| 14 import 'package:analyzer/src/generated/incremental_resolver.dart'; |
| 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 16 import 'package:analyzer/src/generated/parser.dart'; |
| 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 18 import 'package:analyzer/src/generated/scanner.dart'; |
| 19 import 'package:analyzer/src/generated/source_io.dart'; |
| 20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 21 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 22 import 'package:analyzer/task/dart.dart'; |
| 23 import 'package:unittest/unittest.dart'; |
| 24 |
| 25 import '../reflective_tests.dart'; |
| 26 import 'parser_test.dart'; |
| 27 import 'resolver_test.dart'; |
| 28 import 'test_support.dart'; |
| 29 |
| 30 main() { |
| 31 initializeTestEnvironment(); |
| 32 runReflectiveTests(DeclarationMatcherTest); |
| 33 runReflectiveTests(IncrementalResolverTest); |
| 34 runReflectiveTests(PoorMansIncrementalResolutionTest); |
| 35 runReflectiveTests(ResolutionContextBuilderTest); |
| 36 } |
| 37 |
| 38 void initializeTestEnvironment() {} |
| 39 |
| 40 void _assertEqualError(AnalysisError incrError, AnalysisError fullError) { |
| 41 expect(incrError.errorCode, same(fullError.errorCode)); |
| 42 expect(incrError.source, fullError.source); |
| 43 expect(incrError.offset, fullError.offset); |
| 44 expect(incrError.length, fullError.length); |
| 45 expect(incrError.message, fullError.message); |
| 46 } |
| 47 |
| 48 void _assertEqualErrors( |
| 49 List<AnalysisError> incrErrors, List<AnalysisError> fullErrors) { |
| 50 expect(incrErrors, hasLength(fullErrors.length)); |
| 51 if (incrErrors.isNotEmpty) { |
| 52 incrErrors.sort((a, b) => a.offset - b.offset); |
| 53 } |
| 54 if (fullErrors.isNotEmpty) { |
| 55 fullErrors.sort((a, b) => a.offset - b.offset); |
| 56 } |
| 57 int length = incrErrors.length; |
| 58 for (int i = 0; i < length; i++) { |
| 59 AnalysisError incrError = incrErrors[i]; |
| 60 AnalysisError fullError = fullErrors[i]; |
| 61 _assertEqualError(incrError, fullError); |
| 62 } |
| 63 } |
| 64 |
| 65 @reflectiveTest |
| 66 class DeclarationMatcherTest extends ResolverTestCase { |
| 67 void setUp() { |
| 68 super.setUp(); |
| 69 test_resolveApiChanges = true; |
| 70 } |
| 71 |
| 72 void test_false_class_annotation_accessor_edit() { |
| 73 _assertDoesNotMatch( |
| 74 r''' |
| 75 const my_annotationA = const Object(); |
| 76 const my_annotationB = const Object(); |
| 77 @my_annotationA |
| 78 class A { |
| 79 } |
| 80 ''', |
| 81 r''' |
| 82 const my_annotationA = const Object(); |
| 83 const my_annotationB = const Object(); |
| 84 @my_annotationB |
| 85 class A { |
| 86 } |
| 87 '''); |
| 88 } |
| 89 |
| 90 void test_false_class_annotation_constructor_edit() { |
| 91 _assertDoesNotMatch( |
| 92 r''' |
| 93 class MyAnnotationA { |
| 94 const MyAnnotationA(); |
| 95 } |
| 96 class MyAnnotationB { |
| 97 const MyAnnotationB(); |
| 98 } |
| 99 @MyAnnotationA() |
| 100 class A { |
| 101 } |
| 102 ''', |
| 103 r''' |
| 104 class MyAnnotationA { |
| 105 const MyAnnotationA(); |
| 106 } |
| 107 class MyAnnotationB { |
| 108 const MyAnnotationB(); |
| 109 } |
| 110 @MyAnnotationB() |
| 111 class A { |
| 112 } |
| 113 '''); |
| 114 } |
| 115 |
| 116 void test_false_class_annotations_add() { |
| 117 _assertDoesNotMatch( |
| 118 r''' |
| 119 const my_annotation = const Object(); |
| 120 class A { |
| 121 } |
| 122 ''', |
| 123 r''' |
| 124 const my_annotation = const Object(); |
| 125 @my_annotation |
| 126 class A { |
| 127 } |
| 128 '''); |
| 129 } |
| 130 |
| 131 void test_false_class_annotations_remove() { |
| 132 _assertDoesNotMatch( |
| 133 r''' |
| 134 const my_annotation = const Object(); |
| 135 @my_annotation |
| 136 class A { |
| 137 } |
| 138 ''', |
| 139 r''' |
| 140 const my_annotation = const Object(); |
| 141 class A { |
| 142 } |
| 143 '''); |
| 144 } |
| 145 |
| 146 void test_false_class_list_add() { |
| 147 _assertDoesNotMatch( |
| 148 r''' |
| 149 class A {} |
| 150 class B {} |
| 151 ''', |
| 152 r''' |
| 153 class A {} |
| 154 class B {} |
| 155 class C {} |
| 156 '''); |
| 157 } |
| 158 |
| 159 void test_false_class_list_remove() { |
| 160 _assertDoesNotMatch( |
| 161 r''' |
| 162 class A {} |
| 163 class B {} |
| 164 class C {} |
| 165 ''', |
| 166 r''' |
| 167 class A {} |
| 168 class B {} |
| 169 '''); |
| 170 } |
| 171 |
| 172 void test_false_class_typeParameters_bounds_add() { |
| 173 _assertDoesNotMatch( |
| 174 r''' |
| 175 class A {} |
| 176 class B<T> { |
| 177 T f; |
| 178 } |
| 179 ''', |
| 180 r''' |
| 181 class A {} |
| 182 class B<T extends A> { |
| 183 T f; |
| 184 } |
| 185 '''); |
| 186 } |
| 187 |
| 188 void test_false_class_typeParameters_bounds_remove() { |
| 189 _assertDoesNotMatch( |
| 190 r''' |
| 191 class A {} |
| 192 class B<T extends A> { |
| 193 T f; |
| 194 } |
| 195 ''', |
| 196 r''' |
| 197 class A {} |
| 198 class B<T> { |
| 199 T f; |
| 200 } |
| 201 '''); |
| 202 } |
| 203 |
| 204 void test_false_classMemberAccessor_list_add() { |
| 205 _assertDoesNotMatchOK( |
| 206 r''' |
| 207 class A { |
| 208 get a => 1; |
| 209 get b => 2; |
| 210 } |
| 211 ''', |
| 212 r''' |
| 213 class A { |
| 214 get a => 1; |
| 215 get b => 2; |
| 216 get c => 3; |
| 217 } |
| 218 '''); |
| 219 } |
| 220 |
| 221 void test_false_classMemberAccessor_list_remove() { |
| 222 _assertDoesNotMatch( |
| 223 r''' |
| 224 class A { |
| 225 get a => 1; |
| 226 get b => 2; |
| 227 get c => 3; |
| 228 } |
| 229 ''', |
| 230 r''' |
| 231 class A { |
| 232 get a => 1; |
| 233 get b => 2; |
| 234 } |
| 235 '''); |
| 236 } |
| 237 |
| 238 void test_false_classMemberAccessor_wasGetter() { |
| 239 _assertDoesNotMatchOK( |
| 240 r''' |
| 241 class A { |
| 242 get a => 1; |
| 243 } |
| 244 ''', |
| 245 r''' |
| 246 class A { |
| 247 set a(x) {} |
| 248 } |
| 249 '''); |
| 250 } |
| 251 |
| 252 void test_false_classMemberAccessor_wasInstance() { |
| 253 _assertDoesNotMatchOK( |
| 254 r''' |
| 255 class A { |
| 256 get a => 1; |
| 257 } |
| 258 ''', |
| 259 r''' |
| 260 class A { |
| 261 static get a => 1; |
| 262 } |
| 263 '''); |
| 264 } |
| 265 |
| 266 void test_false_classMemberAccessor_wasSetter() { |
| 267 _assertDoesNotMatchOK( |
| 268 r''' |
| 269 class A { |
| 270 set a(x) {} |
| 271 } |
| 272 ''', |
| 273 r''' |
| 274 class A { |
| 275 get a => 1; |
| 276 } |
| 277 '''); |
| 278 } |
| 279 |
| 280 void test_false_classMemberAccessor_wasStatic() { |
| 281 _assertDoesNotMatchOK( |
| 282 r''' |
| 283 class A { |
| 284 static get a => 1; |
| 285 } |
| 286 ''', |
| 287 r''' |
| 288 class A { |
| 289 get a => 1; |
| 290 } |
| 291 '''); |
| 292 } |
| 293 |
| 294 void test_false_classTypeAlias_list_add() { |
| 295 _assertDoesNotMatch( |
| 296 r''' |
| 297 class M {} |
| 298 class A = Object with M; |
| 299 ''', |
| 300 r''' |
| 301 class M {} |
| 302 class A = Object with M; |
| 303 class B = Object with M; |
| 304 '''); |
| 305 } |
| 306 |
| 307 void test_false_classTypeAlias_list_remove() { |
| 308 _assertDoesNotMatch( |
| 309 r''' |
| 310 class M {} |
| 311 class A = Object with M; |
| 312 class B = Object with M; |
| 313 ''', |
| 314 r''' |
| 315 class M {} |
| 316 class A = Object with M; |
| 317 '''); |
| 318 } |
| 319 |
| 320 void test_false_classTypeAlias_typeParameters_bounds_add() { |
| 321 _assertDoesNotMatch( |
| 322 r''' |
| 323 class M<T> {} |
| 324 class A {} |
| 325 class B<T> = Object with M<T>; |
| 326 ''', |
| 327 r''' |
| 328 class M<T> {} |
| 329 class A {} |
| 330 class B<T extends A> = Object with M<T>; |
| 331 '''); |
| 332 } |
| 333 |
| 334 void test_false_classTypeAlias_typeParameters_bounds_remove() { |
| 335 _assertDoesNotMatch( |
| 336 r''' |
| 337 class M<T> {} |
| 338 class A {} |
| 339 class B<T extends A> = Object with M<T>; |
| 340 ''', |
| 341 r''' |
| 342 class M<T> {} |
| 343 class A {} |
| 344 class B<T> = Object with M<T>; |
| 345 '''); |
| 346 } |
| 347 |
| 348 void test_false_constructor_keywordConst_add() { |
| 349 _assertDoesNotMatch( |
| 350 r''' |
| 351 class A { |
| 352 A(); |
| 353 } |
| 354 ''', |
| 355 r''' |
| 356 class A { |
| 357 const A(); |
| 358 } |
| 359 '''); |
| 360 } |
| 361 |
| 362 void test_false_constructor_keywordConst_remove() { |
| 363 _assertDoesNotMatch( |
| 364 r''' |
| 365 class A { |
| 366 const A(); |
| 367 } |
| 368 ''', |
| 369 r''' |
| 370 class A { |
| 371 A(); |
| 372 } |
| 373 '''); |
| 374 } |
| 375 |
| 376 void test_false_constructor_keywordFactory_add() { |
| 377 _assertDoesNotMatch( |
| 378 r''' |
| 379 class A { |
| 380 A(); |
| 381 A.foo() { |
| 382 return new A(); |
| 383 } |
| 384 } |
| 385 ''', |
| 386 r''' |
| 387 class A { |
| 388 A(); |
| 389 factory A.foo() { |
| 390 return new A(); |
| 391 } |
| 392 } |
| 393 '''); |
| 394 } |
| 395 |
| 396 void test_false_constructor_keywordFactory_remove() { |
| 397 _assertDoesNotMatch( |
| 398 r''' |
| 399 class A { |
| 400 A(); |
| 401 factory A.foo() { |
| 402 return new A(); |
| 403 } |
| 404 } |
| 405 ''', |
| 406 r''' |
| 407 class A { |
| 408 A(); |
| 409 A.foo() { |
| 410 return new A(); |
| 411 } |
| 412 } |
| 413 '''); |
| 414 } |
| 415 |
| 416 void test_false_constructor_parameters_list_add() { |
| 417 _assertDoesNotMatch( |
| 418 r''' |
| 419 class A { |
| 420 A(); |
| 421 } |
| 422 ''', |
| 423 r''' |
| 424 class A { |
| 425 A(int p); |
| 426 } |
| 427 '''); |
| 428 } |
| 429 |
| 430 void test_false_constructor_parameters_list_remove() { |
| 431 _assertDoesNotMatch( |
| 432 r''' |
| 433 class A { |
| 434 A(int p); |
| 435 } |
| 436 ''', |
| 437 r''' |
| 438 class A { |
| 439 A(); |
| 440 } |
| 441 '''); |
| 442 } |
| 443 |
| 444 void test_false_constructor_parameters_type_edit() { |
| 445 _assertDoesNotMatch( |
| 446 r''' |
| 447 class A { |
| 448 A(int p); |
| 449 } |
| 450 ''', |
| 451 r''' |
| 452 class A { |
| 453 A(String p); |
| 454 } |
| 455 '''); |
| 456 } |
| 457 |
| 458 void test_false_constructor_unnamed_add_hadParameters() { |
| 459 _assertDoesNotMatch( |
| 460 r''' |
| 461 class A { |
| 462 } |
| 463 ''', |
| 464 r''' |
| 465 class A { |
| 466 A(int p) {} |
| 467 } |
| 468 '''); |
| 469 } |
| 470 |
| 471 void test_false_constructor_unnamed_remove_hadParameters() { |
| 472 _assertDoesNotMatch( |
| 473 r''' |
| 474 class A { |
| 475 A(int p) {} |
| 476 } |
| 477 ''', |
| 478 r''' |
| 479 class A { |
| 480 } |
| 481 '''); |
| 482 } |
| 483 |
| 484 void test_false_defaultFieldFormalParameterElement_wasSimple() { |
| 485 _assertDoesNotMatch( |
| 486 r''' |
| 487 class A { |
| 488 int field; |
| 489 A(int field); |
| 490 } |
| 491 ''', |
| 492 r''' |
| 493 class A { |
| 494 int field; |
| 495 A([this.field = 0]); |
| 496 } |
| 497 '''); |
| 498 } |
| 499 |
| 500 void test_false_enum_constants_add() { |
| 501 _assertDoesNotMatch( |
| 502 r''' |
| 503 enum E {A, B} |
| 504 ''', |
| 505 r''' |
| 506 enum E {A, B, C} |
| 507 '''); |
| 508 } |
| 509 |
| 510 void test_false_enum_constants_remove() { |
| 511 _assertDoesNotMatch( |
| 512 r''' |
| 513 enum E {A, B, C} |
| 514 ''', |
| 515 r''' |
| 516 enum E {A, B} |
| 517 '''); |
| 518 } |
| 519 |
| 520 void test_false_export_hide_add() { |
| 521 _assertDoesNotMatch( |
| 522 r''' |
| 523 export 'dart:async' hide Future; |
| 524 ''', |
| 525 r''' |
| 526 export 'dart:async' hide Future, Stream; |
| 527 '''); |
| 528 } |
| 529 |
| 530 void test_false_export_hide_remove() { |
| 531 _assertDoesNotMatch( |
| 532 r''' |
| 533 export 'dart:async' hide Future, Stream; |
| 534 ''', |
| 535 r''' |
| 536 export 'dart:async' hide Future; |
| 537 '''); |
| 538 } |
| 539 |
| 540 void test_false_export_list_add() { |
| 541 _assertDoesNotMatch( |
| 542 r''' |
| 543 export 'dart:async'; |
| 544 ''', |
| 545 r''' |
| 546 export 'dart:async'; |
| 547 export 'dart:math'; |
| 548 '''); |
| 549 } |
| 550 |
| 551 void test_false_export_list_remove() { |
| 552 _assertDoesNotMatch( |
| 553 r''' |
| 554 export 'dart:async'; |
| 555 export 'dart:math'; |
| 556 ''', |
| 557 r''' |
| 558 export 'dart:async'; |
| 559 '''); |
| 560 } |
| 561 |
| 562 void test_false_export_show_add() { |
| 563 _assertDoesNotMatch( |
| 564 r''' |
| 565 export 'dart:async' show Future; |
| 566 ''', |
| 567 r''' |
| 568 export 'dart:async' show Future, Stream; |
| 569 '''); |
| 570 } |
| 571 |
| 572 void test_false_export_show_remove() { |
| 573 _assertDoesNotMatch( |
| 574 r''' |
| 575 export 'dart:async' show Future, Stream; |
| 576 ''', |
| 577 r''' |
| 578 export 'dart:async' show Future; |
| 579 '''); |
| 580 } |
| 581 |
| 582 void test_false_extendsClause_add() { |
| 583 _assertDoesNotMatch( |
| 584 r''' |
| 585 class A {} |
| 586 class B {} |
| 587 ''', |
| 588 r''' |
| 589 class A {} |
| 590 class B extends A {} |
| 591 '''); |
| 592 } |
| 593 |
| 594 void test_false_extendsClause_different() { |
| 595 _assertDoesNotMatch( |
| 596 r''' |
| 597 class A {} |
| 598 class B {} |
| 599 class C extends A {} |
| 600 ''', |
| 601 r''' |
| 602 class A {} |
| 603 class B {} |
| 604 class C extends B {} |
| 605 '''); |
| 606 } |
| 607 |
| 608 void test_false_extendsClause_remove() { |
| 609 _assertDoesNotMatch( |
| 610 r''' |
| 611 class A {} |
| 612 class B extends A{} |
| 613 ''', |
| 614 r''' |
| 615 class A {} |
| 616 class B {} |
| 617 '''); |
| 618 } |
| 619 |
| 620 void test_false_field_list_add() { |
| 621 _assertDoesNotMatch( |
| 622 r''' |
| 623 class T { |
| 624 int A = 1; |
| 625 int C = 3; |
| 626 } |
| 627 ''', |
| 628 r''' |
| 629 class T { |
| 630 int A = 1; |
| 631 int B = 2; |
| 632 int C = 3; |
| 633 } |
| 634 '''); |
| 635 } |
| 636 |
| 637 void test_false_field_list_remove() { |
| 638 _assertDoesNotMatch( |
| 639 r''' |
| 640 class T { |
| 641 int A = 1; |
| 642 int B = 2; |
| 643 int C = 3; |
| 644 } |
| 645 ''', |
| 646 r''' |
| 647 class T { |
| 648 int A = 1; |
| 649 int C = 3; |
| 650 } |
| 651 '''); |
| 652 } |
| 653 |
| 654 void test_false_field_modifier_isConst() { |
| 655 _assertDoesNotMatch( |
| 656 r''' |
| 657 class T { |
| 658 static final A = 1; |
| 659 } |
| 660 ''', |
| 661 r''' |
| 662 class T { |
| 663 static const A = 1; |
| 664 } |
| 665 '''); |
| 666 } |
| 667 |
| 668 void test_false_field_modifier_isFinal() { |
| 669 _assertDoesNotMatch( |
| 670 r''' |
| 671 class T { |
| 672 int A = 1; |
| 673 } |
| 674 ''', |
| 675 r''' |
| 676 class T { |
| 677 final int A = 1; |
| 678 } |
| 679 '''); |
| 680 } |
| 681 |
| 682 void test_false_field_modifier_isStatic() { |
| 683 _assertDoesNotMatch( |
| 684 r''' |
| 685 class T { |
| 686 int A = 1; |
| 687 } |
| 688 ''', |
| 689 r''' |
| 690 class T { |
| 691 static int A = 1; |
| 692 } |
| 693 '''); |
| 694 } |
| 695 |
| 696 void test_false_field_modifier_wasConst() { |
| 697 _assertDoesNotMatch( |
| 698 r''' |
| 699 class T { |
| 700 static const A = 1; |
| 701 } |
| 702 ''', |
| 703 r''' |
| 704 class T { |
| 705 static final A = 1; |
| 706 } |
| 707 '''); |
| 708 } |
| 709 |
| 710 void test_false_field_modifier_wasFinal() { |
| 711 _assertDoesNotMatch( |
| 712 r''' |
| 713 class T { |
| 714 final int A = 1; |
| 715 } |
| 716 ''', |
| 717 r''' |
| 718 class T { |
| 719 int A = 1; |
| 720 } |
| 721 '''); |
| 722 } |
| 723 |
| 724 void test_false_field_modifier_wasStatic() { |
| 725 _assertDoesNotMatch( |
| 726 r''' |
| 727 class T { |
| 728 static int A = 1; |
| 729 } |
| 730 ''', |
| 731 r''' |
| 732 class T { |
| 733 int A = 1; |
| 734 } |
| 735 '''); |
| 736 } |
| 737 |
| 738 void test_false_field_type_differentArgs() { |
| 739 _assertDoesNotMatch( |
| 740 r''' |
| 741 class T { |
| 742 List<int> A; |
| 743 } |
| 744 ''', |
| 745 r''' |
| 746 class T { |
| 747 List<String> A; |
| 748 } |
| 749 '''); |
| 750 } |
| 751 |
| 752 void test_false_fieldFormalParameter_add() { |
| 753 _assertDoesNotMatch( |
| 754 r''' |
| 755 class A { |
| 756 final field; |
| 757 A(field); |
| 758 } |
| 759 ''', |
| 760 r''' |
| 761 class A { |
| 762 final field; |
| 763 A(this.field); |
| 764 } |
| 765 '''); |
| 766 } |
| 767 |
| 768 void test_false_fieldFormalParameter_add_function() { |
| 769 _assertDoesNotMatch( |
| 770 r''' |
| 771 class A { |
| 772 final field; |
| 773 A(field(a)); |
| 774 } |
| 775 ''', |
| 776 r''' |
| 777 class A { |
| 778 final field; |
| 779 A(this.field(a)); |
| 780 } |
| 781 '''); |
| 782 } |
| 783 |
| 784 void test_false_fieldFormalParameter_parameters_add() { |
| 785 _assertDoesNotMatch( |
| 786 r''' |
| 787 class A { |
| 788 final field; |
| 789 A(this.field(a)); |
| 790 } |
| 791 ''', |
| 792 r''' |
| 793 class A { |
| 794 final field; |
| 795 A(this.field(a, b)); |
| 796 } |
| 797 '''); |
| 798 } |
| 799 |
| 800 void test_false_fieldFormalParameter_parameters_remove() { |
| 801 _assertDoesNotMatch( |
| 802 r''' |
| 803 class A { |
| 804 final field; |
| 805 A(this.field(a, b)); |
| 806 } |
| 807 ''', |
| 808 r''' |
| 809 class A { |
| 810 final field; |
| 811 A(this.field(a)); |
| 812 } |
| 813 '''); |
| 814 } |
| 815 |
| 816 void test_false_fieldFormalParameter_parameters_typeEdit() { |
| 817 _assertDoesNotMatch( |
| 818 r''' |
| 819 class A { |
| 820 final field; |
| 821 A(this.field(int p)); |
| 822 } |
| 823 ''', |
| 824 r''' |
| 825 class A { |
| 826 final field; |
| 827 A(this.field(String p)); |
| 828 } |
| 829 '''); |
| 830 } |
| 831 |
| 832 void test_false_fieldFormalParameter_remove_default() { |
| 833 _assertDoesNotMatch( |
| 834 r''' |
| 835 class A { |
| 836 final field; |
| 837 A([this.field = 0]); |
| 838 } |
| 839 ''', |
| 840 r''' |
| 841 class A { |
| 842 final field; |
| 843 A([field = 0]); |
| 844 } |
| 845 '''); |
| 846 } |
| 847 |
| 848 void test_false_fieldFormalParameter_remove_function() { |
| 849 _assertDoesNotMatch( |
| 850 r''' |
| 851 class A { |
| 852 final field; |
| 853 A(this.field(a)); |
| 854 } |
| 855 ''', |
| 856 r''' |
| 857 class A { |
| 858 final field; |
| 859 A(field(a)); |
| 860 } |
| 861 '''); |
| 862 } |
| 863 |
| 864 void test_false_fieldFormalParameter_remove_normal() { |
| 865 _assertDoesNotMatch( |
| 866 r''' |
| 867 class A { |
| 868 final field; |
| 869 A(this.field); |
| 870 } |
| 871 ''', |
| 872 r''' |
| 873 class A { |
| 874 final field; |
| 875 A(field); |
| 876 } |
| 877 '''); |
| 878 } |
| 879 |
| 880 void test_false_fieldFormalParameterElement_wasSimple() { |
| 881 _assertDoesNotMatch( |
| 882 r''' |
| 883 class A { |
| 884 int field; |
| 885 A(int field); |
| 886 } |
| 887 ''', |
| 888 r''' |
| 889 class A { |
| 890 int field; |
| 891 A(this.field); |
| 892 } |
| 893 '''); |
| 894 } |
| 895 |
| 896 void test_false_final_type_different() { |
| 897 _assertDoesNotMatch( |
| 898 r''' |
| 899 class T { |
| 900 int A; |
| 901 } |
| 902 ''', |
| 903 r''' |
| 904 class T { |
| 905 String A; |
| 906 } |
| 907 '''); |
| 908 } |
| 909 |
| 910 void test_false_function_async_add() { |
| 911 _assertDoesNotMatch( |
| 912 r''' |
| 913 main() {} |
| 914 ''', |
| 915 r''' |
| 916 main() async {} |
| 917 '''); |
| 918 } |
| 919 |
| 920 void test_false_function_async_remove() { |
| 921 _assertDoesNotMatch( |
| 922 r''' |
| 923 main() async {} |
| 924 ''', |
| 925 r''' |
| 926 main() {} |
| 927 '''); |
| 928 } |
| 929 |
| 930 void test_false_function_generator_add() { |
| 931 _assertDoesNotMatch( |
| 932 r''' |
| 933 main() async {} |
| 934 ''', |
| 935 r''' |
| 936 main() async* {} |
| 937 '''); |
| 938 } |
| 939 |
| 940 void test_false_function_generator_remove() { |
| 941 _assertDoesNotMatch( |
| 942 r''' |
| 943 main() async* {} |
| 944 ''', |
| 945 r''' |
| 946 main() async {} |
| 947 '''); |
| 948 } |
| 949 |
| 950 void test_false_functionTypeAlias_list_add() { |
| 951 _assertDoesNotMatch( |
| 952 r''' |
| 953 typedef A(int pa); |
| 954 typedef B(String pb); |
| 955 ''', |
| 956 r''' |
| 957 typedef A(int pa); |
| 958 typedef B(String pb); |
| 959 typedef C(pc); |
| 960 '''); |
| 961 } |
| 962 |
| 963 void test_false_functionTypeAlias_list_remove() { |
| 964 _assertDoesNotMatch( |
| 965 r''' |
| 966 typedef A(int pa); |
| 967 typedef B(String pb); |
| 968 typedef C(pc); |
| 969 ''', |
| 970 r''' |
| 971 typedef A(int pa); |
| 972 typedef B(String pb); |
| 973 '''); |
| 974 } |
| 975 |
| 976 void test_false_functionTypeAlias_parameters_list_add() { |
| 977 _assertDoesNotMatch( |
| 978 r''' |
| 979 typedef A(a); |
| 980 ''', |
| 981 r''' |
| 982 typedef A(a, b); |
| 983 '''); |
| 984 } |
| 985 |
| 986 void test_false_functionTypeAlias_parameters_list_remove() { |
| 987 _assertDoesNotMatch( |
| 988 r''' |
| 989 typedef A(a, b); |
| 990 ''', |
| 991 r''' |
| 992 typedef A(a); |
| 993 '''); |
| 994 } |
| 995 |
| 996 void test_false_functionTypeAlias_parameters_type_edit() { |
| 997 _assertDoesNotMatch( |
| 998 r''' |
| 999 typedef A(int p); |
| 1000 ''', |
| 1001 r''' |
| 1002 typedef A(String p); |
| 1003 '''); |
| 1004 } |
| 1005 |
| 1006 void test_false_functionTypeAlias_returnType_edit() { |
| 1007 _assertDoesNotMatch( |
| 1008 r''' |
| 1009 typedef int A(); |
| 1010 ''', |
| 1011 r''' |
| 1012 typedef String A(); |
| 1013 '''); |
| 1014 } |
| 1015 |
| 1016 void test_false_functionTypeAlias_typeParameters_bounds_add() { |
| 1017 _assertDoesNotMatch( |
| 1018 r''' |
| 1019 class A {} |
| 1020 typedef F<T>(); |
| 1021 ''', |
| 1022 r''' |
| 1023 class A {} |
| 1024 typedef F<T extends A>(); |
| 1025 '''); |
| 1026 } |
| 1027 |
| 1028 void test_false_functionTypeAlias_typeParameters_bounds_edit() { |
| 1029 _assertDoesNotMatch( |
| 1030 r''' |
| 1031 class A {} |
| 1032 class B {} |
| 1033 typedef F<T extends A>(); |
| 1034 ''', |
| 1035 r''' |
| 1036 class A {} |
| 1037 typedef F<T extends B>(); |
| 1038 '''); |
| 1039 } |
| 1040 |
| 1041 void test_false_functionTypeAlias_typeParameters_bounds_remove() { |
| 1042 _assertDoesNotMatch( |
| 1043 r''' |
| 1044 class A {} |
| 1045 typedef F<T extends A>(); |
| 1046 ''', |
| 1047 r''' |
| 1048 class A {} |
| 1049 typedef F<T>(); |
| 1050 '''); |
| 1051 } |
| 1052 |
| 1053 void test_false_functionTypeAlias_typeParameters_list_add() { |
| 1054 _assertDoesNotMatch( |
| 1055 r''' |
| 1056 typedef F<A>(); |
| 1057 ''', |
| 1058 r''' |
| 1059 typedef F<A, B>(); |
| 1060 '''); |
| 1061 } |
| 1062 |
| 1063 void test_false_functionTypeAlias_typeParameters_list_remove() { |
| 1064 _assertDoesNotMatch( |
| 1065 r''' |
| 1066 typedef F<A, B>(); |
| 1067 ''', |
| 1068 r''' |
| 1069 typedef F<A>(); |
| 1070 '''); |
| 1071 } |
| 1072 |
| 1073 void test_false_FunctionTypedFormalParameter_parameters_list_add() { |
| 1074 _assertDoesNotMatch( |
| 1075 r''' |
| 1076 main(int callback(int a)) { |
| 1077 } |
| 1078 ''', |
| 1079 r''' |
| 1080 main(int callback(int a, String b)) { |
| 1081 } |
| 1082 '''); |
| 1083 } |
| 1084 |
| 1085 void test_false_FunctionTypedFormalParameter_parameters_list_remove() { |
| 1086 _assertDoesNotMatch( |
| 1087 r''' |
| 1088 main(int callback(int a, String b)) { |
| 1089 } |
| 1090 ''', |
| 1091 r''' |
| 1092 main(int callback(int a)) { |
| 1093 } |
| 1094 '''); |
| 1095 } |
| 1096 |
| 1097 void test_false_FunctionTypedFormalParameter_parameterType() { |
| 1098 _assertDoesNotMatch( |
| 1099 r''' |
| 1100 main(int callback(int p)) { |
| 1101 } |
| 1102 ''', |
| 1103 r''' |
| 1104 main(int callback(String p)) { |
| 1105 } |
| 1106 '''); |
| 1107 } |
| 1108 |
| 1109 void test_false_FunctionTypedFormalParameter_returnType() { |
| 1110 _assertDoesNotMatch( |
| 1111 r''' |
| 1112 main(int callback()) { |
| 1113 } |
| 1114 ''', |
| 1115 r''' |
| 1116 main(String callback()) { |
| 1117 } |
| 1118 '''); |
| 1119 } |
| 1120 |
| 1121 void test_false_FunctionTypedFormalParameter_wasSimple() { |
| 1122 _assertDoesNotMatch( |
| 1123 r''' |
| 1124 main(int callback) { |
| 1125 } |
| 1126 ''', |
| 1127 r''' |
| 1128 main(int callback(int a, String b)) { |
| 1129 } |
| 1130 '''); |
| 1131 } |
| 1132 |
| 1133 void test_false_getter_body_add() { |
| 1134 _assertDoesNotMatchOK( |
| 1135 r''' |
| 1136 class A { |
| 1137 int get foo; |
| 1138 } |
| 1139 ''', |
| 1140 r''' |
| 1141 class A { |
| 1142 int get foo => 0; |
| 1143 } |
| 1144 '''); |
| 1145 } |
| 1146 |
| 1147 void test_false_getter_body_remove() { |
| 1148 _assertDoesNotMatchOK( |
| 1149 r''' |
| 1150 class A { |
| 1151 int get foo => 0; |
| 1152 } |
| 1153 ''', |
| 1154 r''' |
| 1155 class A { |
| 1156 int get foo; |
| 1157 } |
| 1158 '''); |
| 1159 } |
| 1160 |
| 1161 void test_false_implementsClause_add() { |
| 1162 _assertDoesNotMatch( |
| 1163 r''' |
| 1164 class A {} |
| 1165 class B {} |
| 1166 ''', |
| 1167 r''' |
| 1168 class A {} |
| 1169 class B implements A {} |
| 1170 '''); |
| 1171 } |
| 1172 |
| 1173 void test_false_implementsClause_remove() { |
| 1174 _assertDoesNotMatch( |
| 1175 r''' |
| 1176 class A {} |
| 1177 class B implements A {} |
| 1178 ''', |
| 1179 r''' |
| 1180 class A {} |
| 1181 class B {} |
| 1182 '''); |
| 1183 } |
| 1184 |
| 1185 void test_false_implementsClause_reorder() { |
| 1186 _assertDoesNotMatch( |
| 1187 r''' |
| 1188 class A {} |
| 1189 class B {} |
| 1190 class C implements A, B {} |
| 1191 ''', |
| 1192 r''' |
| 1193 class A {} |
| 1194 class B {} |
| 1195 class C implements B, A {} |
| 1196 '''); |
| 1197 } |
| 1198 |
| 1199 void test_false_import_hide_add() { |
| 1200 _assertDoesNotMatch( |
| 1201 r''' |
| 1202 import 'dart:async' hide Future; |
| 1203 ''', |
| 1204 r''' |
| 1205 import 'dart:async' hide Future, Stream; |
| 1206 '''); |
| 1207 } |
| 1208 |
| 1209 void test_false_import_hide_remove() { |
| 1210 _assertDoesNotMatch( |
| 1211 r''' |
| 1212 import 'dart:async' hide Future, Stream; |
| 1213 ''', |
| 1214 r''' |
| 1215 import 'dart:async' hide Future; |
| 1216 '''); |
| 1217 } |
| 1218 |
| 1219 void test_false_import_list_add() { |
| 1220 _assertDoesNotMatch( |
| 1221 r''' |
| 1222 import 'dart:async'; |
| 1223 ''', |
| 1224 r''' |
| 1225 import 'dart:async'; |
| 1226 import 'dart:math'; |
| 1227 '''); |
| 1228 } |
| 1229 |
| 1230 void test_false_import_list_remove() { |
| 1231 _assertDoesNotMatch( |
| 1232 r''' |
| 1233 import 'dart:async'; |
| 1234 import 'dart:math'; |
| 1235 ''', |
| 1236 r''' |
| 1237 import 'dart:async'; |
| 1238 '''); |
| 1239 } |
| 1240 |
| 1241 void test_false_import_prefix_add() { |
| 1242 _assertDoesNotMatch( |
| 1243 r''' |
| 1244 import 'dart:async'; |
| 1245 ''', |
| 1246 r''' |
| 1247 import 'dart:async' as async; |
| 1248 '''); |
| 1249 } |
| 1250 |
| 1251 void test_false_import_prefix_edit() { |
| 1252 _assertDoesNotMatch( |
| 1253 r''' |
| 1254 import 'dart:async' as oldPrefix; |
| 1255 ''', |
| 1256 r''' |
| 1257 import 'dart:async' as newPrefix; |
| 1258 '''); |
| 1259 } |
| 1260 |
| 1261 void test_false_import_prefix_remove() { |
| 1262 _assertDoesNotMatch( |
| 1263 r''' |
| 1264 import 'dart:async' as async; |
| 1265 ''', |
| 1266 r''' |
| 1267 import 'dart:async'; |
| 1268 '''); |
| 1269 } |
| 1270 |
| 1271 void test_false_import_show_add() { |
| 1272 _assertDoesNotMatch( |
| 1273 r''' |
| 1274 import 'dart:async' show Future; |
| 1275 ''', |
| 1276 r''' |
| 1277 import 'dart:async' show Future, Stream; |
| 1278 '''); |
| 1279 } |
| 1280 |
| 1281 void test_false_import_show_remove() { |
| 1282 _assertDoesNotMatch( |
| 1283 r''' |
| 1284 import 'dart:async' show Future, Stream; |
| 1285 ''', |
| 1286 r''' |
| 1287 import 'dart:async' show Future; |
| 1288 '''); |
| 1289 } |
| 1290 |
| 1291 void test_false_method_annotation_edit() { |
| 1292 _assertDoesNotMatchOK( |
| 1293 r''' |
| 1294 const my_annotationA = const Object(); |
| 1295 const my_annotationB = const Object(); |
| 1296 class A { |
| 1297 @my_annotationA |
| 1298 void m() {} |
| 1299 } |
| 1300 ''', |
| 1301 r''' |
| 1302 const my_annotationA = const Object(); |
| 1303 const my_annotationB = const Object(); |
| 1304 class A { |
| 1305 @my_annotationB |
| 1306 void m() {} |
| 1307 } |
| 1308 '''); |
| 1309 } |
| 1310 |
| 1311 void test_false_method_annotations_add() { |
| 1312 _assertDoesNotMatchOK( |
| 1313 r''' |
| 1314 const my_annotation = const Object(); |
| 1315 class A { |
| 1316 void m() {} |
| 1317 } |
| 1318 ''', |
| 1319 r''' |
| 1320 const my_annotation = const Object(); |
| 1321 class A { |
| 1322 @my_annotation |
| 1323 void m() {} |
| 1324 } |
| 1325 '''); |
| 1326 } |
| 1327 |
| 1328 void test_false_method_annotations_remove() { |
| 1329 _assertDoesNotMatchOK( |
| 1330 r''' |
| 1331 const my_annotation = const Object(); |
| 1332 class A { |
| 1333 @my_annotation |
| 1334 void m() {} |
| 1335 } |
| 1336 ''', |
| 1337 r''' |
| 1338 const my_annotation = const Object(); |
| 1339 class A { |
| 1340 void m() {} |
| 1341 } |
| 1342 '''); |
| 1343 } |
| 1344 |
| 1345 void test_false_method_async_add() { |
| 1346 _assertDoesNotMatchOK( |
| 1347 r''' |
| 1348 class A { |
| 1349 m() {} |
| 1350 } |
| 1351 ''', |
| 1352 r''' |
| 1353 class A { |
| 1354 m() async {} |
| 1355 } |
| 1356 '''); |
| 1357 } |
| 1358 |
| 1359 void test_false_method_async_remove() { |
| 1360 _assertDoesNotMatchOK( |
| 1361 r''' |
| 1362 class A { |
| 1363 m() async {} |
| 1364 } |
| 1365 ''', |
| 1366 r''' |
| 1367 class A { |
| 1368 m() {} |
| 1369 } |
| 1370 '''); |
| 1371 } |
| 1372 |
| 1373 void test_false_method_body_add() { |
| 1374 _assertDoesNotMatchOK( |
| 1375 r''' |
| 1376 class A { |
| 1377 void foo(); |
| 1378 } |
| 1379 ''', |
| 1380 r''' |
| 1381 class A { |
| 1382 void foo() {} |
| 1383 } |
| 1384 '''); |
| 1385 } |
| 1386 |
| 1387 void test_false_method_body_remove() { |
| 1388 _assertDoesNotMatchOK( |
| 1389 r''' |
| 1390 class A { |
| 1391 void foo() {} |
| 1392 } |
| 1393 ''', |
| 1394 r''' |
| 1395 class A { |
| 1396 void foo(); |
| 1397 } |
| 1398 '''); |
| 1399 } |
| 1400 |
| 1401 void test_false_method_generator_add() { |
| 1402 _assertDoesNotMatchOK( |
| 1403 r''' |
| 1404 class A { |
| 1405 m() async {} |
| 1406 } |
| 1407 ''', |
| 1408 r''' |
| 1409 class A { |
| 1410 m() async* {} |
| 1411 } |
| 1412 '''); |
| 1413 } |
| 1414 |
| 1415 void test_false_method_generator_remove() { |
| 1416 _assertDoesNotMatchOK( |
| 1417 r''' |
| 1418 class A { |
| 1419 m() async* {} |
| 1420 } |
| 1421 ''', |
| 1422 r''' |
| 1423 class A { |
| 1424 m() async {} |
| 1425 } |
| 1426 '''); |
| 1427 } |
| 1428 |
| 1429 void test_false_method_list_add() { |
| 1430 _assertDoesNotMatchOK( |
| 1431 r''' |
| 1432 class A { |
| 1433 a() {} |
| 1434 b() {} |
| 1435 } |
| 1436 ''', |
| 1437 r''' |
| 1438 class A { |
| 1439 a() {} |
| 1440 b() {} |
| 1441 c() {} |
| 1442 } |
| 1443 '''); |
| 1444 } |
| 1445 |
| 1446 void test_false_method_list_remove() { |
| 1447 _assertDoesNotMatch( |
| 1448 r''' |
| 1449 class A { |
| 1450 a() {} |
| 1451 b() {} |
| 1452 c() {} |
| 1453 } |
| 1454 ''', |
| 1455 r''' |
| 1456 class A { |
| 1457 a() {} |
| 1458 b() {} |
| 1459 } |
| 1460 '''); |
| 1461 } |
| 1462 |
| 1463 void test_false_method_parameters_type_edit() { |
| 1464 _assertDoesNotMatchOK( |
| 1465 r''' |
| 1466 class A { |
| 1467 m(int p) { |
| 1468 } |
| 1469 } |
| 1470 ''', |
| 1471 r''' |
| 1472 class A { |
| 1473 m(String p) { |
| 1474 } |
| 1475 } |
| 1476 '''); |
| 1477 } |
| 1478 |
| 1479 void test_false_method_parameters_type_edit_insertImportPrefix() { |
| 1480 _assertDoesNotMatchOK( |
| 1481 r''' |
| 1482 import 'dart:async' as a; |
| 1483 |
| 1484 class C { |
| 1485 void foo(Future f) {} |
| 1486 } |
| 1487 |
| 1488 class Future {} |
| 1489 |
| 1490 bar(C c, a.Future f) { |
| 1491 c.foo(f); |
| 1492 } |
| 1493 ''', |
| 1494 r''' |
| 1495 import 'dart:async' as a; |
| 1496 |
| 1497 class C { |
| 1498 void foo(a.Future f) {} |
| 1499 } |
| 1500 |
| 1501 class Future {} |
| 1502 |
| 1503 bar(C c, a.Future f) { |
| 1504 c.foo(f); |
| 1505 } |
| 1506 '''); |
| 1507 } |
| 1508 |
| 1509 void test_false_method_returnType_edit() { |
| 1510 _assertDoesNotMatchOK( |
| 1511 r''' |
| 1512 class A { |
| 1513 int m() {} |
| 1514 } |
| 1515 ''', |
| 1516 r''' |
| 1517 class A { |
| 1518 String m() {} |
| 1519 } |
| 1520 '''); |
| 1521 } |
| 1522 |
| 1523 void test_false_part_list_add() { |
| 1524 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 1525 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 1526 _assertDoesNotMatch( |
| 1527 r''' |
| 1528 library lib; |
| 1529 part 'unitA.dart'; |
| 1530 ''', |
| 1531 r''' |
| 1532 library lib; |
| 1533 part 'unitA.dart'; |
| 1534 part 'unitB.dart'; |
| 1535 '''); |
| 1536 } |
| 1537 |
| 1538 void test_false_part_list_remove() { |
| 1539 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 1540 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 1541 _assertDoesNotMatch( |
| 1542 r''' |
| 1543 library lib; |
| 1544 part 'unitA.dart'; |
| 1545 part 'unitB.dart'; |
| 1546 ''', |
| 1547 r''' |
| 1548 library lib; |
| 1549 part 'unitA.dart'; |
| 1550 '''); |
| 1551 } |
| 1552 |
| 1553 void test_false_SimpleFormalParameter_named_differentName() { |
| 1554 _assertDoesNotMatch( |
| 1555 r''' |
| 1556 main({int oldName}) { |
| 1557 } |
| 1558 ''', |
| 1559 r''' |
| 1560 main({int newName}) { |
| 1561 } |
| 1562 '''); |
| 1563 } |
| 1564 |
| 1565 void test_false_SimpleFormalParameter_namedDefault_addValue() { |
| 1566 _assertDoesNotMatch( |
| 1567 r''' |
| 1568 main({int p}) { |
| 1569 } |
| 1570 ''', |
| 1571 r''' |
| 1572 main({int p: 2}) { |
| 1573 } |
| 1574 '''); |
| 1575 } |
| 1576 |
| 1577 void test_false_SimpleFormalParameter_namedDefault_differentValue() { |
| 1578 _assertDoesNotMatch( |
| 1579 r''' |
| 1580 main({int p: 1}) { |
| 1581 } |
| 1582 ''', |
| 1583 r''' |
| 1584 main({int p: 2}) { |
| 1585 } |
| 1586 '''); |
| 1587 } |
| 1588 |
| 1589 void test_false_SimpleFormalParameter_namedDefault_removeValue() { |
| 1590 _assertDoesNotMatch( |
| 1591 r''' |
| 1592 main({int p: 1}) { |
| 1593 } |
| 1594 ''', |
| 1595 r''' |
| 1596 main({int p}) { |
| 1597 } |
| 1598 '''); |
| 1599 } |
| 1600 |
| 1601 void test_false_SimpleFormalParameter_optionalDefault_addValue() { |
| 1602 _assertDoesNotMatch( |
| 1603 r''' |
| 1604 main([int p]) { |
| 1605 } |
| 1606 ''', |
| 1607 r''' |
| 1608 main([int p = 2]) { |
| 1609 } |
| 1610 '''); |
| 1611 } |
| 1612 |
| 1613 void test_false_SimpleFormalParameter_optionalDefault_differentValue() { |
| 1614 _assertDoesNotMatch( |
| 1615 r''' |
| 1616 main([int p = 1]) { |
| 1617 } |
| 1618 ''', |
| 1619 r''' |
| 1620 main([int p = 2]) { |
| 1621 } |
| 1622 '''); |
| 1623 } |
| 1624 |
| 1625 void test_false_SimpleFormalParameter_optionalDefault_removeValue() { |
| 1626 _assertDoesNotMatch( |
| 1627 r''' |
| 1628 main([int p = 1]) { |
| 1629 } |
| 1630 ''', |
| 1631 r''' |
| 1632 main([int p]) { |
| 1633 } |
| 1634 '''); |
| 1635 } |
| 1636 |
| 1637 void test_false_topLevelAccessor_list_add() { |
| 1638 _assertDoesNotMatch( |
| 1639 r''' |
| 1640 get a => 1; |
| 1641 get b => 2; |
| 1642 ''', |
| 1643 r''' |
| 1644 get a => 1; |
| 1645 get b => 2; |
| 1646 get c => 3; |
| 1647 '''); |
| 1648 } |
| 1649 |
| 1650 void test_false_topLevelAccessor_list_remove() { |
| 1651 _assertDoesNotMatch( |
| 1652 r''' |
| 1653 get a => 1; |
| 1654 get b => 2; |
| 1655 get c => 3; |
| 1656 ''', |
| 1657 r''' |
| 1658 get a => 1; |
| 1659 get b => 2; |
| 1660 '''); |
| 1661 } |
| 1662 |
| 1663 void test_false_topLevelAccessor_wasGetter() { |
| 1664 _assertDoesNotMatch( |
| 1665 r''' |
| 1666 get a => 1; |
| 1667 ''', |
| 1668 r''' |
| 1669 set a(x) {} |
| 1670 '''); |
| 1671 } |
| 1672 |
| 1673 void test_false_topLevelAccessor_wasSetter() { |
| 1674 _assertDoesNotMatch( |
| 1675 r''' |
| 1676 set a(x) {} |
| 1677 ''', |
| 1678 r''' |
| 1679 get a => 1; |
| 1680 '''); |
| 1681 } |
| 1682 |
| 1683 void test_false_topLevelFunction_list_add() { |
| 1684 _assertDoesNotMatch( |
| 1685 r''' |
| 1686 a() {} |
| 1687 b() {} |
| 1688 ''', |
| 1689 r''' |
| 1690 a() {} |
| 1691 b() {} |
| 1692 c() {} |
| 1693 '''); |
| 1694 } |
| 1695 |
| 1696 void test_false_topLevelFunction_list_remove() { |
| 1697 _assertDoesNotMatch( |
| 1698 r''' |
| 1699 a() {} |
| 1700 b() {} |
| 1701 c() {} |
| 1702 ''', |
| 1703 r''' |
| 1704 a() {} |
| 1705 b() {} |
| 1706 '''); |
| 1707 } |
| 1708 |
| 1709 void test_false_topLevelFunction_parameters_list_add() { |
| 1710 _assertDoesNotMatch( |
| 1711 r''' |
| 1712 main(int a, int b) { |
| 1713 } |
| 1714 ''', |
| 1715 r''' |
| 1716 main(int a, int b, int c) { |
| 1717 } |
| 1718 '''); |
| 1719 } |
| 1720 |
| 1721 void test_false_topLevelFunction_parameters_list_remove() { |
| 1722 _assertDoesNotMatch( |
| 1723 r''' |
| 1724 main(int a, int b, int c) { |
| 1725 } |
| 1726 ''', |
| 1727 r''' |
| 1728 main(int a, int b) { |
| 1729 } |
| 1730 '''); |
| 1731 } |
| 1732 |
| 1733 void test_false_topLevelFunction_parameters_type_edit() { |
| 1734 _assertDoesNotMatch( |
| 1735 r''' |
| 1736 main(int a, int b, int c) { |
| 1737 } |
| 1738 ''', |
| 1739 r''' |
| 1740 main(int a, String b, int c) { |
| 1741 } |
| 1742 '''); |
| 1743 } |
| 1744 |
| 1745 void test_false_topLevelFunction_returnType_edit() { |
| 1746 _assertDoesNotMatch( |
| 1747 r''' |
| 1748 int a() {} |
| 1749 ''', |
| 1750 r''' |
| 1751 String a() {} |
| 1752 '''); |
| 1753 } |
| 1754 |
| 1755 void test_false_topLevelVariable_list_add() { |
| 1756 _assertDoesNotMatch( |
| 1757 r''' |
| 1758 const int A = 1; |
| 1759 const int C = 3; |
| 1760 ''', |
| 1761 r''' |
| 1762 const int A = 1; |
| 1763 const int B = 2; |
| 1764 const int C = 3; |
| 1765 '''); |
| 1766 } |
| 1767 |
| 1768 void test_false_topLevelVariable_list_remove() { |
| 1769 _assertDoesNotMatch( |
| 1770 r''' |
| 1771 const int A = 1; |
| 1772 const int B = 2; |
| 1773 const int C = 3; |
| 1774 ''', |
| 1775 r''' |
| 1776 const int A = 1; |
| 1777 const int C = 3; |
| 1778 '''); |
| 1779 } |
| 1780 |
| 1781 void test_false_topLevelVariable_modifier_isConst() { |
| 1782 _assertDoesNotMatch( |
| 1783 r''' |
| 1784 final int A = 1; |
| 1785 ''', |
| 1786 r''' |
| 1787 const int A = 1; |
| 1788 '''); |
| 1789 } |
| 1790 |
| 1791 void test_false_topLevelVariable_modifier_isFinal() { |
| 1792 _assertDoesNotMatch( |
| 1793 r''' |
| 1794 int A = 1; |
| 1795 ''', |
| 1796 r''' |
| 1797 final int A = 1; |
| 1798 '''); |
| 1799 } |
| 1800 |
| 1801 void test_false_topLevelVariable_modifier_wasConst() { |
| 1802 _assertDoesNotMatch( |
| 1803 r''' |
| 1804 const int A = 1; |
| 1805 ''', |
| 1806 r''' |
| 1807 final int A = 1; |
| 1808 '''); |
| 1809 } |
| 1810 |
| 1811 void test_false_topLevelVariable_modifier_wasFinal() { |
| 1812 _assertDoesNotMatch( |
| 1813 r''' |
| 1814 final int A = 1; |
| 1815 ''', |
| 1816 r''' |
| 1817 int A = 1; |
| 1818 '''); |
| 1819 } |
| 1820 |
| 1821 void test_false_topLevelVariable_synthetic_wasGetter() { |
| 1822 _assertDoesNotMatch( |
| 1823 r''' |
| 1824 int get A => 1; |
| 1825 ''', |
| 1826 r''' |
| 1827 final int A = 1; |
| 1828 '''); |
| 1829 } |
| 1830 |
| 1831 void test_false_topLevelVariable_type_different() { |
| 1832 _assertDoesNotMatch( |
| 1833 r''' |
| 1834 int A; |
| 1835 ''', |
| 1836 r''' |
| 1837 String A; |
| 1838 '''); |
| 1839 } |
| 1840 |
| 1841 void test_false_topLevelVariable_type_differentArgs() { |
| 1842 _assertDoesNotMatch( |
| 1843 r''' |
| 1844 List<int> A; |
| 1845 ''', |
| 1846 r''' |
| 1847 List<String> A; |
| 1848 '''); |
| 1849 } |
| 1850 |
| 1851 void test_false_type_noTypeArguments_hadTypeArguments() { |
| 1852 _assertDoesNotMatch( |
| 1853 r''' |
| 1854 class A<T> {} |
| 1855 A<int> main() { |
| 1856 } |
| 1857 ''', |
| 1858 r''' |
| 1859 class A<T> {} |
| 1860 A main() { |
| 1861 } |
| 1862 '''); |
| 1863 } |
| 1864 |
| 1865 void test_false_withClause_add() { |
| 1866 _assertDoesNotMatch( |
| 1867 r''' |
| 1868 class A {} |
| 1869 class B {} |
| 1870 ''', |
| 1871 r''' |
| 1872 class A {} |
| 1873 class B extends Object with A {} |
| 1874 '''); |
| 1875 } |
| 1876 |
| 1877 void test_false_withClause_remove() { |
| 1878 _assertDoesNotMatch( |
| 1879 r''' |
| 1880 class A {} |
| 1881 class B extends Object with A {} |
| 1882 ''', |
| 1883 r''' |
| 1884 class A {} |
| 1885 class B {} |
| 1886 '''); |
| 1887 } |
| 1888 |
| 1889 void test_false_withClause_reorder() { |
| 1890 _assertDoesNotMatch( |
| 1891 r''' |
| 1892 class A {} |
| 1893 class B {} |
| 1894 class C extends Object with A, B {} |
| 1895 ''', |
| 1896 r''' |
| 1897 class A {} |
| 1898 class B {} |
| 1899 class C extends Object with B, A {} |
| 1900 '''); |
| 1901 } |
| 1902 |
| 1903 void test_true_class_annotations_same() { |
| 1904 _assertMatches( |
| 1905 r''' |
| 1906 const my_annotation = const Object(); |
| 1907 @my_annotation |
| 1908 class A { |
| 1909 } |
| 1910 ''', |
| 1911 r''' |
| 1912 const my_annotation = const Object(); |
| 1913 @my_annotation |
| 1914 class A { |
| 1915 } |
| 1916 '''); |
| 1917 } |
| 1918 |
| 1919 void test_true_class_list_reorder() { |
| 1920 _assertMatches( |
| 1921 r''' |
| 1922 class A {} |
| 1923 class B {} |
| 1924 class C {} |
| 1925 ''', |
| 1926 r''' |
| 1927 class C {} |
| 1928 class A {} |
| 1929 class B {} |
| 1930 '''); |
| 1931 } |
| 1932 |
| 1933 void test_true_class_list_same() { |
| 1934 _assertMatches( |
| 1935 r''' |
| 1936 class A {} |
| 1937 class B {} |
| 1938 class C {} |
| 1939 ''', |
| 1940 r''' |
| 1941 class A {} |
| 1942 class B {} |
| 1943 class C {} |
| 1944 '''); |
| 1945 } |
| 1946 |
| 1947 void test_true_class_typeParameters_same() { |
| 1948 _assertMatches( |
| 1949 r''' |
| 1950 class A<T> {} |
| 1951 ''', |
| 1952 r''' |
| 1953 class A<T> {} |
| 1954 '''); |
| 1955 } |
| 1956 |
| 1957 void test_true_classMemberAccessor_getterSetter() { |
| 1958 _assertMatches( |
| 1959 r''' |
| 1960 class A { |
| 1961 int _test; |
| 1962 get test => _test; |
| 1963 set test(v) { |
| 1964 _test = v; |
| 1965 } |
| 1966 } |
| 1967 ''', |
| 1968 r''' |
| 1969 class A { |
| 1970 int _test; |
| 1971 get test => _test; |
| 1972 set test(v) { |
| 1973 _test = v; |
| 1974 } |
| 1975 } |
| 1976 '''); |
| 1977 } |
| 1978 |
| 1979 void test_true_classMemberAccessor_list_reorder() { |
| 1980 _assertMatches( |
| 1981 r''' |
| 1982 class A { |
| 1983 get a => 1; |
| 1984 get b => 2; |
| 1985 get c => 3; |
| 1986 } |
| 1987 ''', |
| 1988 r''' |
| 1989 class A { |
| 1990 get c => 3; |
| 1991 get a => 1; |
| 1992 get b => 2; |
| 1993 } |
| 1994 '''); |
| 1995 } |
| 1996 |
| 1997 void test_true_classMemberAccessor_list_same() { |
| 1998 _assertMatches( |
| 1999 r''' |
| 2000 class A { |
| 2001 get a => 1; |
| 2002 get b => 2; |
| 2003 get c => 3; |
| 2004 } |
| 2005 ''', |
| 2006 r''' |
| 2007 class A { |
| 2008 get a => 1; |
| 2009 get b => 2; |
| 2010 get c => 3; |
| 2011 } |
| 2012 '''); |
| 2013 } |
| 2014 |
| 2015 void test_true_classTypeAlias_list_reorder() { |
| 2016 _assertMatches( |
| 2017 r''' |
| 2018 class M {} |
| 2019 class A = Object with M; |
| 2020 class B = Object with M; |
| 2021 class C = Object with M; |
| 2022 ''', |
| 2023 r''' |
| 2024 class M {} |
| 2025 class C = Object with M; |
| 2026 class A = Object with M; |
| 2027 class B = Object with M; |
| 2028 '''); |
| 2029 } |
| 2030 |
| 2031 void test_true_classTypeAlias_list_same() { |
| 2032 _assertMatches( |
| 2033 r''' |
| 2034 class M {} |
| 2035 class A = Object with M; |
| 2036 class B = Object with M; |
| 2037 class C = Object with M; |
| 2038 ''', |
| 2039 r''' |
| 2040 class M {} |
| 2041 class A = Object with M; |
| 2042 class B = Object with M; |
| 2043 class C = Object with M; |
| 2044 '''); |
| 2045 } |
| 2046 |
| 2047 void test_true_classTypeAlias_typeParameters_same() { |
| 2048 _assertMatches( |
| 2049 r''' |
| 2050 class M<T> {} |
| 2051 class A<T> {} |
| 2052 class B<T> = A<T> with M<T>; |
| 2053 ''', |
| 2054 r''' |
| 2055 class M<T> {} |
| 2056 class A<T> {} |
| 2057 class B<T> = A<T> with M<T>; |
| 2058 '''); |
| 2059 } |
| 2060 |
| 2061 void test_true_constructor_body_add() { |
| 2062 _assertMatches( |
| 2063 r''' |
| 2064 class A { |
| 2065 A(int p); |
| 2066 } |
| 2067 ''', |
| 2068 r''' |
| 2069 class A { |
| 2070 A(int p) {} |
| 2071 } |
| 2072 '''); |
| 2073 } |
| 2074 |
| 2075 void test_true_constructor_body_remove() { |
| 2076 _assertMatches( |
| 2077 r''' |
| 2078 class A { |
| 2079 A(int p) {} |
| 2080 } |
| 2081 ''', |
| 2082 r''' |
| 2083 class A { |
| 2084 A(int p); |
| 2085 } |
| 2086 '''); |
| 2087 } |
| 2088 |
| 2089 void test_true_constructor_named_same() { |
| 2090 _assertMatches( |
| 2091 r''' |
| 2092 class A { |
| 2093 A.name(int p); |
| 2094 } |
| 2095 ''', |
| 2096 r''' |
| 2097 class A { |
| 2098 A.name(int p); |
| 2099 } |
| 2100 '''); |
| 2101 } |
| 2102 |
| 2103 void test_true_constructor_unnamed_add_noParameters() { |
| 2104 _assertMatches( |
| 2105 r''' |
| 2106 class A { |
| 2107 } |
| 2108 ''', |
| 2109 r''' |
| 2110 class A { |
| 2111 A() {} |
| 2112 } |
| 2113 '''); |
| 2114 } |
| 2115 |
| 2116 void test_true_constructor_unnamed_remove_noParameters() { |
| 2117 _assertMatches( |
| 2118 r''' |
| 2119 class A { |
| 2120 A() {} |
| 2121 } |
| 2122 ''', |
| 2123 r''' |
| 2124 class A { |
| 2125 } |
| 2126 '''); |
| 2127 } |
| 2128 |
| 2129 void test_true_constructor_unnamed_same() { |
| 2130 _assertMatches( |
| 2131 r''' |
| 2132 class A { |
| 2133 A(int p); |
| 2134 } |
| 2135 ''', |
| 2136 r''' |
| 2137 class A { |
| 2138 A(int p); |
| 2139 } |
| 2140 '''); |
| 2141 } |
| 2142 |
| 2143 void test_true_defaultFieldFormalParameterElement() { |
| 2144 _assertMatches( |
| 2145 r''' |
| 2146 class A { |
| 2147 int field; |
| 2148 A([this.field = 0]); |
| 2149 } |
| 2150 ''', |
| 2151 r''' |
| 2152 class A { |
| 2153 int field; |
| 2154 A([this.field = 0]); |
| 2155 } |
| 2156 '''); |
| 2157 } |
| 2158 |
| 2159 void test_true_enum_constants_reorder() { |
| 2160 _assertMatches( |
| 2161 r''' |
| 2162 enum E {A, B, C} |
| 2163 ''', |
| 2164 r''' |
| 2165 enum E {C, A, B} |
| 2166 '''); |
| 2167 } |
| 2168 |
| 2169 void test_true_enum_list_reorder() { |
| 2170 _assertMatches( |
| 2171 r''' |
| 2172 enum A {A1, A2, A3} |
| 2173 enum B {B1, B2, B3} |
| 2174 enum C {C1, C2, C3} |
| 2175 ''', |
| 2176 r''' |
| 2177 enum C {C1, C2, C3} |
| 2178 enum A {A1, A2, A3} |
| 2179 enum B {B1, B2, B3} |
| 2180 '''); |
| 2181 } |
| 2182 |
| 2183 void test_true_enum_list_same() { |
| 2184 _assertMatches( |
| 2185 r''' |
| 2186 enum A {A1, A2, A3} |
| 2187 enum B {B1, B2, B3} |
| 2188 enum C {C1, C2, C3} |
| 2189 ''', |
| 2190 r''' |
| 2191 enum A {A1, A2, A3} |
| 2192 enum B {B1, B2, B3} |
| 2193 enum C {C1, C2, C3} |
| 2194 '''); |
| 2195 } |
| 2196 |
| 2197 void test_true_executable_same_hasLabel() { |
| 2198 _assertMatches( |
| 2199 r''' |
| 2200 main() { |
| 2201 label: return 42; |
| 2202 } |
| 2203 ''', |
| 2204 r''' |
| 2205 main() { |
| 2206 label: return 42; |
| 2207 } |
| 2208 '''); |
| 2209 } |
| 2210 |
| 2211 void test_true_executable_same_hasLocalVariable() { |
| 2212 _assertMatches( |
| 2213 r''' |
| 2214 main() { |
| 2215 int a = 42; |
| 2216 } |
| 2217 ''', |
| 2218 r''' |
| 2219 main() { |
| 2220 int a = 42; |
| 2221 } |
| 2222 '''); |
| 2223 } |
| 2224 |
| 2225 void test_true_export_hide_reorder() { |
| 2226 _assertMatches( |
| 2227 r''' |
| 2228 export 'dart:async' hide Future, Stream; |
| 2229 ''', |
| 2230 r''' |
| 2231 export 'dart:async' hide Stream, Future; |
| 2232 '''); |
| 2233 } |
| 2234 |
| 2235 void test_true_export_list_reorder() { |
| 2236 _assertMatches( |
| 2237 r''' |
| 2238 export 'dart:async'; |
| 2239 export 'dart:math'; |
| 2240 ''', |
| 2241 r''' |
| 2242 export 'dart:math'; |
| 2243 export 'dart:async'; |
| 2244 '''); |
| 2245 } |
| 2246 |
| 2247 void test_true_export_list_same() { |
| 2248 _assertMatches( |
| 2249 r''' |
| 2250 export 'dart:async'; |
| 2251 export 'dart:math'; |
| 2252 ''', |
| 2253 r''' |
| 2254 export 'dart:async'; |
| 2255 export 'dart:math'; |
| 2256 '''); |
| 2257 } |
| 2258 |
| 2259 void test_true_export_show_reorder() { |
| 2260 _assertMatches( |
| 2261 r''' |
| 2262 export 'dart:async' show Future, Stream; |
| 2263 ''', |
| 2264 r''' |
| 2265 export 'dart:async' show Stream, Future; |
| 2266 '''); |
| 2267 } |
| 2268 |
| 2269 void test_true_extendsClause_same() { |
| 2270 _assertMatches( |
| 2271 r''' |
| 2272 class A {} |
| 2273 class B extends A {} |
| 2274 ''', |
| 2275 r''' |
| 2276 class A {} |
| 2277 class B extends A {} |
| 2278 '''); |
| 2279 } |
| 2280 |
| 2281 void test_true_field_list_reorder() { |
| 2282 _assertMatches( |
| 2283 r''' |
| 2284 class T { |
| 2285 int A = 1; |
| 2286 int B = 2; |
| 2287 int C = 3; |
| 2288 } |
| 2289 ''', |
| 2290 r''' |
| 2291 class T { |
| 2292 int C = 3; |
| 2293 int A = 1; |
| 2294 int B = 2; |
| 2295 } |
| 2296 '''); |
| 2297 } |
| 2298 |
| 2299 void test_true_field_list_same() { |
| 2300 _assertMatches( |
| 2301 r''' |
| 2302 class T { |
| 2303 int A = 1; |
| 2304 int B = 2; |
| 2305 int C = 3; |
| 2306 } |
| 2307 ''', |
| 2308 r''' |
| 2309 class T { |
| 2310 int A = 1; |
| 2311 int B = 2; |
| 2312 int C = 3; |
| 2313 } |
| 2314 '''); |
| 2315 } |
| 2316 |
| 2317 void test_true_fieldFormalParameter() { |
| 2318 _assertMatches( |
| 2319 r''' |
| 2320 class A { |
| 2321 int field; |
| 2322 A(this.field); |
| 2323 } |
| 2324 ''', |
| 2325 r''' |
| 2326 class A { |
| 2327 int field; |
| 2328 A(this.field); |
| 2329 } |
| 2330 '''); |
| 2331 } |
| 2332 |
| 2333 void test_true_fieldFormalParameter_function() { |
| 2334 _assertMatches( |
| 2335 r''' |
| 2336 class A { |
| 2337 final field; |
| 2338 A(this.field(int a, String b)); |
| 2339 } |
| 2340 ''', |
| 2341 r''' |
| 2342 class A { |
| 2343 final field; |
| 2344 A(this.field(int a, String b)); |
| 2345 } |
| 2346 '''); |
| 2347 } |
| 2348 |
| 2349 void test_true_functionTypeAlias_list_reorder() { |
| 2350 _assertMatches( |
| 2351 r''' |
| 2352 typedef A(int pa); |
| 2353 typedef B(String pb); |
| 2354 typedef C(pc); |
| 2355 ''', |
| 2356 r''' |
| 2357 typedef C(pc); |
| 2358 typedef A(int pa); |
| 2359 typedef B(String pb); |
| 2360 '''); |
| 2361 } |
| 2362 |
| 2363 void test_true_functionTypeAlias_list_same() { |
| 2364 _assertMatches( |
| 2365 r''' |
| 2366 typedef String A(int pa); |
| 2367 typedef int B(String pb); |
| 2368 typedef C(pc); |
| 2369 ''', |
| 2370 r''' |
| 2371 typedef String A(int pa); |
| 2372 typedef int B(String pb); |
| 2373 typedef C(pc); |
| 2374 '''); |
| 2375 } |
| 2376 |
| 2377 void test_true_functionTypeAlias_typeParameters_list_same() { |
| 2378 _assertMatches( |
| 2379 r''' |
| 2380 typedef F<A, B, C>(); |
| 2381 ''', |
| 2382 r''' |
| 2383 typedef F<A, B, C>(); |
| 2384 '''); |
| 2385 } |
| 2386 |
| 2387 void test_true_FunctionTypedFormalParameter() { |
| 2388 _assertMatches( |
| 2389 r''' |
| 2390 main(int callback(int a, String b)) { |
| 2391 } |
| 2392 ''', |
| 2393 r''' |
| 2394 main(int callback(int a, String b)) { |
| 2395 } |
| 2396 '''); |
| 2397 } |
| 2398 |
| 2399 void test_true_implementsClause_same() { |
| 2400 _assertMatches( |
| 2401 r''' |
| 2402 class A {} |
| 2403 class B implements A {} |
| 2404 ''', |
| 2405 r''' |
| 2406 class A {} |
| 2407 class B implements A {} |
| 2408 '''); |
| 2409 } |
| 2410 |
| 2411 void test_true_import_hide_reorder() { |
| 2412 _assertMatches( |
| 2413 r''' |
| 2414 import 'dart:async' hide Future, Stream; |
| 2415 ''', |
| 2416 r''' |
| 2417 import 'dart:async' hide Stream, Future; |
| 2418 '''); |
| 2419 } |
| 2420 |
| 2421 void test_true_import_list_reorder() { |
| 2422 _assertMatches( |
| 2423 r''' |
| 2424 import 'dart:async'; |
| 2425 import 'dart:math'; |
| 2426 ''', |
| 2427 r''' |
| 2428 import 'dart:math'; |
| 2429 import 'dart:async'; |
| 2430 '''); |
| 2431 } |
| 2432 |
| 2433 void test_true_import_list_same() { |
| 2434 _assertMatches( |
| 2435 r''' |
| 2436 import 'dart:async'; |
| 2437 import 'dart:math'; |
| 2438 ''', |
| 2439 r''' |
| 2440 import 'dart:async'; |
| 2441 import 'dart:math'; |
| 2442 '''); |
| 2443 } |
| 2444 |
| 2445 void test_true_import_prefix() { |
| 2446 _assertMatches( |
| 2447 r''' |
| 2448 import 'dart:async' as async; |
| 2449 ''', |
| 2450 r''' |
| 2451 import 'dart:async' as async; |
| 2452 '''); |
| 2453 } |
| 2454 |
| 2455 void test_true_import_show_reorder() { |
| 2456 _assertMatches( |
| 2457 r''' |
| 2458 import 'dart:async' show Future, Stream; |
| 2459 ''', |
| 2460 r''' |
| 2461 import 'dart:async' show Stream, Future; |
| 2462 '''); |
| 2463 } |
| 2464 |
| 2465 void test_true_method_annotation_accessor_same() { |
| 2466 _assertMatches( |
| 2467 r''' |
| 2468 const my_annotation = const Object(); |
| 2469 class A { |
| 2470 @my_annotation |
| 2471 void m() {} |
| 2472 } |
| 2473 ''', |
| 2474 r''' |
| 2475 const my_annotation = const Object(); |
| 2476 class A { |
| 2477 @my_annotation |
| 2478 void m() {} |
| 2479 } |
| 2480 '''); |
| 2481 } |
| 2482 |
| 2483 void test_true_method_annotation_constructor_same() { |
| 2484 _assertMatches( |
| 2485 r''' |
| 2486 class MyAnnotation { |
| 2487 const MyAnnotation(); |
| 2488 } |
| 2489 class A { |
| 2490 @MyAnnotation() |
| 2491 void m() {} |
| 2492 } |
| 2493 ''', |
| 2494 r''' |
| 2495 class MyAnnotation { |
| 2496 const MyAnnotation(); |
| 2497 } |
| 2498 class A { |
| 2499 @MyAnnotation() |
| 2500 void m() {} |
| 2501 } |
| 2502 '''); |
| 2503 } |
| 2504 |
| 2505 void test_true_method_async() { |
| 2506 _assertMatches( |
| 2507 r''' |
| 2508 class A { |
| 2509 m() async {} |
| 2510 } |
| 2511 ''', |
| 2512 r''' |
| 2513 class A { |
| 2514 m() async {} |
| 2515 } |
| 2516 '''); |
| 2517 } |
| 2518 |
| 2519 void test_true_method_list_reorder() { |
| 2520 _assertMatches( |
| 2521 r''' |
| 2522 class A { |
| 2523 a() {} |
| 2524 b() {} |
| 2525 c() {} |
| 2526 } |
| 2527 ''', |
| 2528 r''' |
| 2529 class A { |
| 2530 c() {} |
| 2531 a() {} |
| 2532 b() {} |
| 2533 } |
| 2534 '''); |
| 2535 } |
| 2536 |
| 2537 void test_true_method_list_same() { |
| 2538 _assertMatches( |
| 2539 r''' |
| 2540 class A { |
| 2541 a() {} |
| 2542 b() {} |
| 2543 c() {} |
| 2544 } |
| 2545 ''', |
| 2546 r''' |
| 2547 class A { |
| 2548 a() {} |
| 2549 b() {} |
| 2550 c() {} |
| 2551 } |
| 2552 '''); |
| 2553 } |
| 2554 |
| 2555 void test_true_method_operator_minus() { |
| 2556 _assertMatches( |
| 2557 r''' |
| 2558 class A { |
| 2559 operator -(other) {} |
| 2560 } |
| 2561 ''', |
| 2562 r''' |
| 2563 class A { |
| 2564 operator -(other) {} |
| 2565 } |
| 2566 '''); |
| 2567 } |
| 2568 |
| 2569 void test_true_method_operator_minusUnary() { |
| 2570 _assertMatches( |
| 2571 r''' |
| 2572 class A { |
| 2573 operator -() {} |
| 2574 } |
| 2575 ''', |
| 2576 r''' |
| 2577 class A { |
| 2578 operator -() {} |
| 2579 } |
| 2580 '''); |
| 2581 } |
| 2582 |
| 2583 void test_true_method_operator_plus() { |
| 2584 _assertMatches( |
| 2585 r''' |
| 2586 class A { |
| 2587 operator +(other) {} |
| 2588 } |
| 2589 ''', |
| 2590 r''' |
| 2591 class A { |
| 2592 operator +(other) {} |
| 2593 } |
| 2594 '''); |
| 2595 } |
| 2596 |
| 2597 void test_true_method_parameters_type_functionType() { |
| 2598 _assertMatches( |
| 2599 r''' |
| 2600 typedef F(); |
| 2601 class A { |
| 2602 m(F p) {} |
| 2603 } |
| 2604 ''', |
| 2605 r''' |
| 2606 typedef F(); |
| 2607 class A { |
| 2608 m(F p) {} |
| 2609 } |
| 2610 '''); |
| 2611 } |
| 2612 |
| 2613 void test_true_method_parameters_type_sameImportPrefix() { |
| 2614 _assertMatches( |
| 2615 r''' |
| 2616 import 'dart:async' as a; |
| 2617 |
| 2618 bar(a.Future f) { |
| 2619 print(f); |
| 2620 } |
| 2621 ''', |
| 2622 r''' |
| 2623 import 'dart:async' as a; |
| 2624 |
| 2625 bar(a.Future ff) { |
| 2626 print(ff); |
| 2627 } |
| 2628 '''); |
| 2629 } |
| 2630 |
| 2631 void test_true_part_list_reorder() { |
| 2632 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 2633 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 2634 _assertMatches( |
| 2635 r''' |
| 2636 library lib; |
| 2637 part 'unitA.dart'; |
| 2638 part 'unitB.dart'; |
| 2639 ''', |
| 2640 r''' |
| 2641 library lib; |
| 2642 part 'unitB.dart'; |
| 2643 part 'unitA.dart'; |
| 2644 '''); |
| 2645 } |
| 2646 |
| 2647 void test_true_part_list_same() { |
| 2648 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 2649 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 2650 _assertMatches( |
| 2651 r''' |
| 2652 library lib; |
| 2653 part 'unitA.dart'; |
| 2654 part 'unitB.dart'; |
| 2655 ''', |
| 2656 r''' |
| 2657 library lib; |
| 2658 part 'unitA.dart'; |
| 2659 part 'unitB.dart'; |
| 2660 '''); |
| 2661 } |
| 2662 |
| 2663 void test_true_SimpleFormalParameter_optional_differentName() { |
| 2664 _assertMatches( |
| 2665 r''' |
| 2666 main([int oldName]) { |
| 2667 } |
| 2668 ''', |
| 2669 r''' |
| 2670 main([int newName]) { |
| 2671 } |
| 2672 '''); |
| 2673 } |
| 2674 |
| 2675 void test_true_SimpleFormalParameter_optionalDefault_differentName() { |
| 2676 _assertMatches( |
| 2677 r''' |
| 2678 main([int oldName = 1]) { |
| 2679 } |
| 2680 ''', |
| 2681 r''' |
| 2682 main([int newName = 1]) { |
| 2683 } |
| 2684 '''); |
| 2685 } |
| 2686 |
| 2687 void test_true_SimpleFormalParameter_required_differentName() { |
| 2688 _assertMatches( |
| 2689 r''' |
| 2690 main(int oldName) { |
| 2691 } |
| 2692 ''', |
| 2693 r''' |
| 2694 main(int newName) { |
| 2695 } |
| 2696 '''); |
| 2697 } |
| 2698 |
| 2699 void test_true_topLevelAccessor_list_reorder() { |
| 2700 _assertMatches( |
| 2701 r''' |
| 2702 set a(x) {} |
| 2703 set b(x) {} |
| 2704 set c(x) {} |
| 2705 ''', |
| 2706 r''' |
| 2707 set c(x) {} |
| 2708 set a(x) {} |
| 2709 set b(x) {} |
| 2710 '''); |
| 2711 } |
| 2712 |
| 2713 void test_true_topLevelAccessor_list_same() { |
| 2714 _assertMatches( |
| 2715 r''' |
| 2716 get a => 1; |
| 2717 get b => 2; |
| 2718 get c => 3; |
| 2719 ''', |
| 2720 r''' |
| 2721 get a => 1; |
| 2722 get b => 2; |
| 2723 get c => 3; |
| 2724 '''); |
| 2725 } |
| 2726 |
| 2727 void test_true_topLevelFunction_list_reorder() { |
| 2728 _assertMatches( |
| 2729 r''' |
| 2730 a() {} |
| 2731 b() {} |
| 2732 c() {} |
| 2733 ''', |
| 2734 r''' |
| 2735 c() {} |
| 2736 a() {} |
| 2737 b() {} |
| 2738 '''); |
| 2739 } |
| 2740 |
| 2741 void test_true_topLevelFunction_list_same() { |
| 2742 _assertMatches( |
| 2743 r''' |
| 2744 a() {} |
| 2745 b() {} |
| 2746 c() {} |
| 2747 ''', |
| 2748 r''' |
| 2749 a() {} |
| 2750 b() {} |
| 2751 c() {} |
| 2752 '''); |
| 2753 } |
| 2754 |
| 2755 void test_true_topLevelVariable_list_reorder() { |
| 2756 _assertMatches( |
| 2757 r''' |
| 2758 const int A = 1; |
| 2759 const int B = 2; |
| 2760 const int C = 3; |
| 2761 ''', |
| 2762 r''' |
| 2763 const int C = 3; |
| 2764 const int A = 1; |
| 2765 const int B = 2; |
| 2766 '''); |
| 2767 } |
| 2768 |
| 2769 void test_true_topLevelVariable_list_same() { |
| 2770 _assertMatches( |
| 2771 r''' |
| 2772 const int A = 1; |
| 2773 const int B = 2; |
| 2774 const int C = 3; |
| 2775 ''', |
| 2776 r''' |
| 2777 const int A = 1; |
| 2778 const int B = 2; |
| 2779 const int C = 3; |
| 2780 '''); |
| 2781 } |
| 2782 |
| 2783 void test_true_topLevelVariable_type_sameArgs() { |
| 2784 _assertMatches( |
| 2785 r''' |
| 2786 Map<int, String> A; |
| 2787 ''', |
| 2788 r''' |
| 2789 Map<int, String> A; |
| 2790 '''); |
| 2791 } |
| 2792 |
| 2793 void test_true_type_dynamic() { |
| 2794 _assertMatches( |
| 2795 r''' |
| 2796 dynamic a() {} |
| 2797 ''', |
| 2798 r''' |
| 2799 dynamic a() {} |
| 2800 '''); |
| 2801 } |
| 2802 |
| 2803 void test_true_type_hasImportPrefix() { |
| 2804 _assertMatches( |
| 2805 r''' |
| 2806 import 'dart:async' as async; |
| 2807 async.Future F; |
| 2808 ''', |
| 2809 r''' |
| 2810 import 'dart:async' as async; |
| 2811 async.Future F; |
| 2812 '''); |
| 2813 } |
| 2814 |
| 2815 void test_true_type_noTypeArguments_implyAllDynamic() { |
| 2816 _assertMatches( |
| 2817 r''' |
| 2818 class A<T> {} |
| 2819 A main() { |
| 2820 } |
| 2821 ''', |
| 2822 r''' |
| 2823 class A<T> {} |
| 2824 A main() { |
| 2825 } |
| 2826 '''); |
| 2827 } |
| 2828 |
| 2829 void test_true_type_void() { |
| 2830 _assertMatches( |
| 2831 r''' |
| 2832 void a() {} |
| 2833 ''', |
| 2834 r''' |
| 2835 void a() {} |
| 2836 '''); |
| 2837 } |
| 2838 |
| 2839 void test_true_withClause_same() { |
| 2840 _assertMatches( |
| 2841 r''' |
| 2842 class A {} |
| 2843 class B extends Object with A {} |
| 2844 ''', |
| 2845 r''' |
| 2846 class A {} |
| 2847 class B extends Object with A {} |
| 2848 '''); |
| 2849 } |
| 2850 |
| 2851 void _assertDoesNotMatch(String oldContent, String newContent) { |
| 2852 _assertMatchKind(DeclarationMatchKind.MISMATCH, oldContent, newContent); |
| 2853 } |
| 2854 |
| 2855 void _assertDoesNotMatchOK(String oldContent, String newContent) { |
| 2856 _assertMatchKind(DeclarationMatchKind.MISMATCH_OK, oldContent, newContent); |
| 2857 } |
| 2858 |
| 2859 void _assertMatches(String oldContent, String newContent) { |
| 2860 _assertMatchKind(DeclarationMatchKind.MATCH, oldContent, newContent); |
| 2861 } |
| 2862 |
| 2863 void _assertMatchKind( |
| 2864 DeclarationMatchKind expectMatch, String oldContent, String newContent) { |
| 2865 Source source = addSource(oldContent); |
| 2866 LibraryElement library = resolve2(source); |
| 2867 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 2868 // parse |
| 2869 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); |
| 2870 // build elements |
| 2871 { |
| 2872 ElementHolder holder = new ElementHolder(); |
| 2873 ElementBuilder builder = new ElementBuilder(holder); |
| 2874 newUnit.accept(builder); |
| 2875 } |
| 2876 // match |
| 2877 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 2878 DeclarationMatchKind matchKind = matcher.matches(newUnit, oldUnit.element); |
| 2879 expect(matchKind, same(expectMatch)); |
| 2880 } |
| 2881 } |
| 2882 |
| 2883 @reflectiveTest |
| 2884 class IncrementalResolverTest extends ResolverTestCase { |
| 2885 Source source; |
| 2886 String code; |
| 2887 LibraryElement library; |
| 2888 CompilationUnit unit; |
| 2889 |
| 2890 @override |
| 2891 void reset() { |
| 2892 if (AnalysisEngine.instance.useTaskModel) { |
| 2893 analysisContext2 = AnalysisContextFactory.contextWithCore(); |
| 2894 } else { |
| 2895 analysisContext2 = AnalysisContextFactory.oldContextWithCore(); |
| 2896 } |
| 2897 } |
| 2898 |
| 2899 @override |
| 2900 void resetWithOptions(AnalysisOptions options) { |
| 2901 if (AnalysisEngine.instance.useTaskModel) { |
| 2902 analysisContext2 = |
| 2903 AnalysisContextFactory.contextWithCoreAndOptions(options); |
| 2904 } else { |
| 2905 analysisContext2 = |
| 2906 AnalysisContextFactory.oldContextWithCoreAndOptions(options); |
| 2907 } |
| 2908 } |
| 2909 |
| 2910 void setUp() { |
| 2911 super.setUp(); |
| 2912 test_resolveApiChanges = true; |
| 2913 log.logger = log.NULL_LOGGER; |
| 2914 } |
| 2915 |
| 2916 void test_classMemberAccessor_body() { |
| 2917 _resolveUnit(r''' |
| 2918 class A { |
| 2919 int get test { |
| 2920 return 1 + 2; |
| 2921 } |
| 2922 }'''); |
| 2923 _resolve(_editString('+', '*'), _isFunctionBody); |
| 2924 } |
| 2925 |
| 2926 void test_constructor_body() { |
| 2927 _resolveUnit(r''' |
| 2928 class A { |
| 2929 int f; |
| 2930 A(int a, int b) { |
| 2931 f = a + b; |
| 2932 } |
| 2933 }'''); |
| 2934 _resolve(_editString('+', '*'), _isFunctionBody); |
| 2935 } |
| 2936 |
| 2937 void test_constructor_fieldFormalParameter() { |
| 2938 _resolveUnit(r''' |
| 2939 class A { |
| 2940 int xy; |
| 2941 A(this.x); |
| 2942 }'''); |
| 2943 _resolve(_editString('this.x', 'this.xy'), _isDeclaration); |
| 2944 } |
| 2945 |
| 2946 void test_constructor_fieldInitializer_add() { |
| 2947 _resolveUnit(r''' |
| 2948 class A { |
| 2949 int f; |
| 2950 A(int a, int b); |
| 2951 }'''); |
| 2952 _resolve(_editString(');', ') : f = a + b;'), _isClassMember); |
| 2953 } |
| 2954 |
| 2955 void test_constructor_fieldInitializer_edit() { |
| 2956 _resolveUnit(r''' |
| 2957 class A { |
| 2958 int f; |
| 2959 A(int a, int b) : f = a + b { |
| 2960 int a = 42; |
| 2961 } |
| 2962 }'''); |
| 2963 _resolve(_editString('+', '*'), _isExpression); |
| 2964 } |
| 2965 |
| 2966 void test_constructor_label_add() { |
| 2967 _resolveUnit(r''' |
| 2968 class A { |
| 2969 A() { |
| 2970 return 42; |
| 2971 } |
| 2972 } |
| 2973 '''); |
| 2974 _resolve(_editString('return', 'label: return'), _isBlock); |
| 2975 } |
| 2976 |
| 2977 void test_constructor_localVariable_add() { |
| 2978 _resolveUnit(r''' |
| 2979 class A { |
| 2980 A() { |
| 2981 42; |
| 2982 } |
| 2983 } |
| 2984 '''); |
| 2985 _resolve(_editString('42;', 'var res = 42;'), _isBlock); |
| 2986 } |
| 2987 |
| 2988 void test_constructor_superConstructorInvocation() { |
| 2989 _resolveUnit(r''' |
| 2990 class A { |
| 2991 A(int p); |
| 2992 } |
| 2993 class B extends A { |
| 2994 B(int a, int b) : super(a + b); |
| 2995 } |
| 2996 '''); |
| 2997 _resolve(_editString('+', '*'), _isExpression); |
| 2998 } |
| 2999 |
| 3000 void test_function_localFunction_add() { |
| 3001 _resolveUnit(r''' |
| 3002 int main() { |
| 3003 return 0; |
| 3004 } |
| 3005 callIt(f) {} |
| 3006 '''); |
| 3007 _resolve(_editString('return 0;', 'callIt((p) {});'), _isBlock); |
| 3008 } |
| 3009 |
| 3010 void test_functionBody_body() { |
| 3011 _resolveUnit(r''' |
| 3012 main(int a, int b) { |
| 3013 return a + b; |
| 3014 }'''); |
| 3015 _resolve(_editString('+', '*'), _isFunctionBody); |
| 3016 } |
| 3017 |
| 3018 void test_functionBody_expression() { |
| 3019 _resolveUnit(r''' |
| 3020 main(int a, int b) => a + b; |
| 3021 '''); |
| 3022 _resolve(_editString('+', '*'), _isExpression); |
| 3023 } |
| 3024 |
| 3025 void test_functionBody_statement() { |
| 3026 _resolveUnit(r''' |
| 3027 main(int a, int b) { |
| 3028 return a + b; |
| 3029 }'''); |
| 3030 _resolve(_editString('+', '*'), _isStatement); |
| 3031 } |
| 3032 |
| 3033 void test_method_body() { |
| 3034 _resolveUnit(r''' |
| 3035 class A { |
| 3036 m(int a, int b) { |
| 3037 return a + b; |
| 3038 } |
| 3039 }'''); |
| 3040 _resolve(_editString('+', '*'), _isFunctionBody); |
| 3041 } |
| 3042 |
| 3043 void test_method_label_add() { |
| 3044 _resolveUnit(r''' |
| 3045 class A { |
| 3046 int m(int a, int b) { |
| 3047 return a + b; |
| 3048 } |
| 3049 } |
| 3050 '''); |
| 3051 _resolve(_editString('return', 'label: return'), _isBlock); |
| 3052 } |
| 3053 |
| 3054 void test_method_localFunction_add() { |
| 3055 _resolveUnit(r''' |
| 3056 class A { |
| 3057 int m() { |
| 3058 return 0; |
| 3059 } |
| 3060 } |
| 3061 callIt(f) {} |
| 3062 '''); |
| 3063 _resolve(_editString('return 0;', 'callIt((p) {});'), _isBlock); |
| 3064 } |
| 3065 |
| 3066 void test_method_localVariable_add() { |
| 3067 _resolveUnit(r''' |
| 3068 class A { |
| 3069 int m(int a, int b) { |
| 3070 return a + b; |
| 3071 } |
| 3072 } |
| 3073 '''); |
| 3074 _resolve( |
| 3075 _editString( |
| 3076 ' return a + b;', |
| 3077 r''' |
| 3078 int res = a + b; |
| 3079 return res; |
| 3080 '''), |
| 3081 _isBlock); |
| 3082 } |
| 3083 |
| 3084 void test_method_parameter_rename() { |
| 3085 _resolveUnit(r''' |
| 3086 class A { |
| 3087 int m(int a, int b, int c) { |
| 3088 return a + b + c; |
| 3089 } |
| 3090 } |
| 3091 '''); |
| 3092 _resolve( |
| 3093 _editString( |
| 3094 r'''(int a, int b, int c) { |
| 3095 return a + b + c;''', |
| 3096 r'''(int a, int second, int c) { |
| 3097 return a + second + c;'''), |
| 3098 _isDeclaration); |
| 3099 } |
| 3100 |
| 3101 void test_superInvocation() { |
| 3102 _resolveUnit(r''' |
| 3103 class A { |
| 3104 foo(p) {} |
| 3105 } |
| 3106 class B extends A { |
| 3107 bar() { |
| 3108 super.foo(1 + 2); |
| 3109 } |
| 3110 }'''); |
| 3111 _resolve(_editString('+', '*'), _isFunctionBody); |
| 3112 } |
| 3113 |
| 3114 void test_topLevelAccessor_body() { |
| 3115 _resolveUnit(r''' |
| 3116 int get test { |
| 3117 return 1 + 2; |
| 3118 }'''); |
| 3119 _resolve(_editString('+', '*'), _isFunctionBody); |
| 3120 } |
| 3121 |
| 3122 void test_topLevelFunction_label_add() { |
| 3123 _resolveUnit(r''' |
| 3124 int main(int a, int b) { |
| 3125 return a + b; |
| 3126 } |
| 3127 '''); |
| 3128 _resolve(_editString(' return', 'label: return a + b;'), _isBlock); |
| 3129 } |
| 3130 |
| 3131 void test_topLevelFunction_label_remove() { |
| 3132 _resolveUnit(r''' |
| 3133 int main(int a, int b) { |
| 3134 label: return a + b; |
| 3135 } |
| 3136 '''); |
| 3137 _resolve(_editString('label: ', ''), _isBlock); |
| 3138 } |
| 3139 |
| 3140 void test_topLevelFunction_localVariable_add() { |
| 3141 _resolveUnit(r''' |
| 3142 int main(int a, int b) { |
| 3143 return a + b; |
| 3144 } |
| 3145 '''); |
| 3146 _resolve( |
| 3147 _editString( |
| 3148 ' return a + b;', |
| 3149 r''' |
| 3150 int res = a + b; |
| 3151 return res; |
| 3152 '''), |
| 3153 _isBlock); |
| 3154 } |
| 3155 |
| 3156 void test_topLevelFunction_localVariable_remove() { |
| 3157 _resolveUnit(r''' |
| 3158 int main(int a, int b) { |
| 3159 int res = a * b; |
| 3160 return a + b; |
| 3161 } |
| 3162 '''); |
| 3163 _resolve(_editString('int res = a * b;', ''), _isBlock); |
| 3164 } |
| 3165 |
| 3166 void test_topLevelFunction_parameter_inFunctionTyped_rename() { |
| 3167 _resolveUnit(r''' |
| 3168 test(f(int a, int b)) { |
| 3169 } |
| 3170 '''); |
| 3171 _resolve(_editString('test(f(int a', 'test(f2(int a2'), _isDeclaration); |
| 3172 } |
| 3173 |
| 3174 void test_topLevelFunction_parameter_rename() { |
| 3175 _resolveUnit(r''' |
| 3176 int main(int a, int b) { |
| 3177 return a + b; |
| 3178 } |
| 3179 '''); |
| 3180 _resolve( |
| 3181 _editString( |
| 3182 r'''(int a, int b) { |
| 3183 return a + b;''', |
| 3184 r'''(int first, int b) { |
| 3185 return first + b;'''), |
| 3186 _isDeclaration); |
| 3187 } |
| 3188 |
| 3189 void test_topLevelVariable_initializer() { |
| 3190 _resolveUnit(r''' |
| 3191 int C = 1 + 2; |
| 3192 '''); |
| 3193 _resolve(_editString('+', '*'), _isExpression); |
| 3194 } |
| 3195 |
| 3196 void test_updateElementOffset() { |
| 3197 _resolveUnit(r''' |
| 3198 class A { |
| 3199 int am(String ap) { |
| 3200 int av = 1; |
| 3201 return av; |
| 3202 } |
| 3203 } |
| 3204 main(int a, int b) { |
| 3205 return a + b; |
| 3206 } |
| 3207 class B { |
| 3208 int bm(String bp) { |
| 3209 int bv = 1; |
| 3210 return bv; |
| 3211 } |
| 3212 } |
| 3213 '''); |
| 3214 _resolve(_editString('+', ' + '), _isStatement); |
| 3215 } |
| 3216 |
| 3217 _Edit _editString(String search, String replacement, [int length]) { |
| 3218 int offset = code.indexOf(search); |
| 3219 expect(offset, isNot(-1)); |
| 3220 if (length == null) { |
| 3221 length = search.length; |
| 3222 } |
| 3223 return new _Edit(offset, length, replacement); |
| 3224 } |
| 3225 |
| 3226 /** |
| 3227 * Applies [edit] to [code], find the [AstNode] specified by [predicate] |
| 3228 * and incrementally resolves it. |
| 3229 * |
| 3230 * Then resolves the new code from scratch and validates that results of |
| 3231 * the incremental resolution and non-incremental resolutions are the same. |
| 3232 */ |
| 3233 void _resolve(_Edit edit, Predicate<AstNode> predicate) { |
| 3234 int offset = edit.offset; |
| 3235 // parse "newCode" |
| 3236 String newCode = code.substring(0, offset) + |
| 3237 edit.replacement + |
| 3238 code.substring(offset + edit.length); |
| 3239 CompilationUnit newUnit = _parseUnit(newCode); |
| 3240 // replace the node |
| 3241 AstNode oldNode = _findNodeAt(unit, offset, predicate); |
| 3242 AstNode newNode = _findNodeAt(newUnit, offset, predicate); |
| 3243 { |
| 3244 bool success = NodeReplacer.replace(oldNode, newNode); |
| 3245 expect(success, isTrue); |
| 3246 } |
| 3247 // update tokens |
| 3248 { |
| 3249 int delta = edit.replacement.length - edit.length; |
| 3250 _shiftTokens(unit.beginToken, offset, delta); |
| 3251 } |
| 3252 // do incremental resolution |
| 3253 int updateOffset = edit.offset; |
| 3254 int updateEndOld = updateOffset + edit.length; |
| 3255 int updateOldNew = updateOffset + edit.replacement.length; |
| 3256 IncrementalResolver resolver; |
| 3257 if (AnalysisEngine.instance.useTaskModel) { |
| 3258 LibrarySpecificUnit lsu = new LibrarySpecificUnit(source, source); |
| 3259 task.AnalysisCache cache = analysisContext2.analysisCache; |
| 3260 resolver = new IncrementalResolver( |
| 3261 null, |
| 3262 cache.get(source), |
| 3263 cache.get(lsu), |
| 3264 unit.element, |
| 3265 updateOffset, |
| 3266 updateEndOld, |
| 3267 updateOldNew); |
| 3268 } else { |
| 3269 resolver = new IncrementalResolver( |
| 3270 (analysisContext2 as AnalysisContextImpl) |
| 3271 .getReadableSourceEntryOrNull(source), |
| 3272 null, |
| 3273 null, |
| 3274 unit.element, |
| 3275 updateOffset, |
| 3276 updateEndOld, |
| 3277 updateOldNew); |
| 3278 } |
| 3279 bool success = resolver.resolve(newNode); |
| 3280 expect(success, isTrue); |
| 3281 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
| 3282 // resolve "newCode" from scratch |
| 3283 CompilationUnit fullNewUnit; |
| 3284 { |
| 3285 source = addSource(newCode); |
| 3286 _runTasks(); |
| 3287 LibraryElement library = resolve2(source); |
| 3288 fullNewUnit = resolveCompilationUnit(source, library); |
| 3289 } |
| 3290 try { |
| 3291 assertSameResolution(unit, fullNewUnit); |
| 3292 } on IncrementalResolutionMismatch catch (mismatch) { |
| 3293 fail(mismatch.message); |
| 3294 } |
| 3295 // errors |
| 3296 List<AnalysisError> newFullErrors = |
| 3297 analysisContext.getErrors(source).errors; |
| 3298 _assertEqualErrors(newErrors, newFullErrors); |
| 3299 // prepare for the next cycle |
| 3300 code = newCode; |
| 3301 } |
| 3302 |
| 3303 void _resolveUnit(String code) { |
| 3304 this.code = code; |
| 3305 source = addSource(code); |
| 3306 library = resolve2(source); |
| 3307 unit = resolveCompilationUnit(source, library); |
| 3308 _runTasks(); |
| 3309 } |
| 3310 |
| 3311 void _runTasks() { |
| 3312 AnalysisResult result = analysisContext.performAnalysisTask(); |
| 3313 while (result.changeNotices != null) { |
| 3314 result = analysisContext.performAnalysisTask(); |
| 3315 } |
| 3316 } |
| 3317 |
| 3318 static AstNode _findNodeAt( |
| 3319 CompilationUnit oldUnit, int offset, Predicate<AstNode> predicate) { |
| 3320 NodeLocator locator = new NodeLocator(offset); |
| 3321 AstNode node = locator.searchWithin(oldUnit); |
| 3322 return node.getAncestor(predicate); |
| 3323 } |
| 3324 |
| 3325 static bool _isBlock(AstNode node) => node is Block; |
| 3326 |
| 3327 static bool _isClassMember(AstNode node) => node is ClassMember; |
| 3328 |
| 3329 static bool _isDeclaration(AstNode node) => node is Declaration; |
| 3330 |
| 3331 static bool _isExpression(AstNode node) => node is Expression; |
| 3332 |
| 3333 static bool _isFunctionBody(AstNode node) => node is FunctionBody; |
| 3334 |
| 3335 static bool _isStatement(AstNode node) => node is Statement; |
| 3336 |
| 3337 static CompilationUnit _parseUnit(String code) { |
| 3338 var errorListener = new BooleanErrorListener(); |
| 3339 var reader = new CharSequenceReader(code); |
| 3340 var scanner = new Scanner(null, reader, errorListener); |
| 3341 var token = scanner.tokenize(); |
| 3342 var parser = new Parser(null, errorListener); |
| 3343 return parser.parseCompilationUnit(token); |
| 3344 } |
| 3345 |
| 3346 static void _shiftTokens(Token token, int afterOffset, int delta) { |
| 3347 while (token.type != TokenType.EOF) { |
| 3348 if (token.offset >= afterOffset) { |
| 3349 token.applyDelta(delta); |
| 3350 } |
| 3351 token = token.next; |
| 3352 } |
| 3353 } |
| 3354 } |
| 3355 |
| 3356 /** |
| 3357 * The test for [poorMansIncrementalResolution] function and its integration |
| 3358 * into [AnalysisContext]. |
| 3359 */ |
| 3360 @reflectiveTest |
| 3361 class PoorMansIncrementalResolutionTest extends ResolverTestCase { |
| 3362 Source source; |
| 3363 String code; |
| 3364 LibraryElement oldLibrary; |
| 3365 CompilationUnit oldUnit; |
| 3366 CompilationUnitElement oldUnitElement; |
| 3367 |
| 3368 void fail_updateErrors_removeExisting_duplicateMethodDeclaration() { |
| 3369 // TODO(scheglov) We fail to remove the second "foo" declaration. |
| 3370 // So, we still have the same duplicate declaration problem. |
| 3371 _resolveUnit(r''' |
| 3372 class A { |
| 3373 void foo() {} |
| 3374 void foo() {} |
| 3375 } |
| 3376 '''); |
| 3377 _updateAndValidate(r''' |
| 3378 class A { |
| 3379 void foo() {} |
| 3380 void foo2() {} |
| 3381 } |
| 3382 '''); |
| 3383 } |
| 3384 |
| 3385 void setUp() { |
| 3386 super.setUp(); |
| 3387 _resetWithIncremental(true); |
| 3388 } |
| 3389 |
| 3390 void test_computeConstants() { |
| 3391 _resolveUnit(r''' |
| 3392 int f() => 0; |
| 3393 main() { |
| 3394 const x = f(); |
| 3395 print(x + 1); |
| 3396 } |
| 3397 '''); |
| 3398 _updateAndValidate(r''' |
| 3399 int f() => 0; |
| 3400 main() { |
| 3401 const x = f(); |
| 3402 print(x + 2); |
| 3403 } |
| 3404 '''); |
| 3405 } |
| 3406 |
| 3407 void test_dartDoc_beforeField() { |
| 3408 _resolveUnit(r''' |
| 3409 class A { |
| 3410 /** |
| 3411 * A field [field] of type [int] in class [A]. |
| 3412 */ |
| 3413 int field; |
| 3414 } |
| 3415 '''); |
| 3416 _updateAndValidate(r''' |
| 3417 class A { |
| 3418 /** |
| 3419 * A field [field] of the type [int] in the class [A]. |
| 3420 * Updated, with a reference to the [String] type. |
| 3421 */ |
| 3422 int field; |
| 3423 } |
| 3424 '''); |
| 3425 } |
| 3426 |
| 3427 void test_dartDoc_clumsy_addReference() { |
| 3428 _resolveUnit(r''' |
| 3429 /** |
| 3430 * aaa bbbb |
| 3431 */ |
| 3432 main() { |
| 3433 } |
| 3434 '''); |
| 3435 _updateAndValidate(r''' |
| 3436 /** |
| 3437 * aaa [main] bbbb |
| 3438 */ |
| 3439 main() { |
| 3440 } |
| 3441 '''); |
| 3442 } |
| 3443 |
| 3444 void test_dartDoc_clumsy_removeReference() { |
| 3445 _resolveUnit(r''' |
| 3446 /** |
| 3447 * aaa [main] bbbb |
| 3448 */ |
| 3449 main() { |
| 3450 } |
| 3451 '''); |
| 3452 _updateAndValidate(r''' |
| 3453 /** |
| 3454 * aaa bbbb |
| 3455 */ |
| 3456 main() { |
| 3457 } |
| 3458 '''); |
| 3459 } |
| 3460 |
| 3461 void test_dartDoc_clumsy_updateText_beforeKeywordToken() { |
| 3462 _resolveUnit(r''' |
| 3463 /** |
| 3464 * A comment with the [int] type reference. |
| 3465 */ |
| 3466 class A {} |
| 3467 '''); |
| 3468 _updateAndValidate(r''' |
| 3469 /** |
| 3470 * A comment with the [int] type reference. |
| 3471 * Plus reference to [A] itself. |
| 3472 */ |
| 3473 class A {} |
| 3474 '''); |
| 3475 } |
| 3476 |
| 3477 void test_dartDoc_clumsy_updateText_insert() { |
| 3478 _resolveUnit(r''' |
| 3479 /** |
| 3480 * A function [main] with a parameter [p] of type [int]. |
| 3481 */ |
| 3482 main(int p) { |
| 3483 unresolvedFunctionProblem(); |
| 3484 } |
| 3485 /** |
| 3486 * Other comment with [int] reference. |
| 3487 */ |
| 3488 foo() {} |
| 3489 '''); |
| 3490 _updateAndValidate(r''' |
| 3491 /** |
| 3492 * A function [main] with a parameter [p] of type [int]. |
| 3493 * Inserted text with [String] reference. |
| 3494 */ |
| 3495 main(int p) { |
| 3496 unresolvedFunctionProblem(); |
| 3497 } |
| 3498 /** |
| 3499 * Other comment with [int] reference. |
| 3500 */ |
| 3501 foo() {} |
| 3502 '''); |
| 3503 } |
| 3504 |
| 3505 void test_dartDoc_clumsy_updateText_remove() { |
| 3506 _resolveUnit(r''' |
| 3507 /** |
| 3508 * A function [main] with a parameter [p] of type [int]. |
| 3509 * Some text with [String] reference to remove. |
| 3510 */ |
| 3511 main(int p) { |
| 3512 } |
| 3513 /** |
| 3514 * Other comment with [int] reference. |
| 3515 */ |
| 3516 foo() {} |
| 3517 '''); |
| 3518 _updateAndValidate(r''' |
| 3519 /** |
| 3520 * A function [main] with a parameter [p] of type [int]. |
| 3521 */ |
| 3522 main(int p) { |
| 3523 } |
| 3524 /** |
| 3525 * Other comment with [int] reference. |
| 3526 */ |
| 3527 foo() {} |
| 3528 '''); |
| 3529 } |
| 3530 |
| 3531 void test_dartDoc_elegant_addReference() { |
| 3532 _resolveUnit(r''' |
| 3533 /// aaa bbb |
| 3534 main() { |
| 3535 return 1; |
| 3536 } |
| 3537 '''); |
| 3538 _updateAndValidate(r''' |
| 3539 /// aaa [main] bbb |
| 3540 /// ccc [int] ddd |
| 3541 main() { |
| 3542 return 1; |
| 3543 } |
| 3544 '''); |
| 3545 } |
| 3546 |
| 3547 void test_dartDoc_elegant_removeReference() { |
| 3548 _resolveUnit(r''' |
| 3549 /// aaa [main] bbb |
| 3550 /// ccc [int] ddd |
| 3551 main() { |
| 3552 return 1; |
| 3553 } |
| 3554 '''); |
| 3555 _updateAndValidate(r''' |
| 3556 /// aaa bbb |
| 3557 main() { |
| 3558 return 1; |
| 3559 } |
| 3560 '''); |
| 3561 } |
| 3562 |
| 3563 void test_dartDoc_elegant_updateText_insertToken() { |
| 3564 _resolveUnit(r''' |
| 3565 /// A |
| 3566 /// [int] |
| 3567 class Test { |
| 3568 } |
| 3569 '''); |
| 3570 _updateAndValidate(r''' |
| 3571 /// A |
| 3572 /// |
| 3573 /// [int] |
| 3574 class Test { |
| 3575 } |
| 3576 '''); |
| 3577 } |
| 3578 |
| 3579 void test_dartDoc_elegant_updateText_removeToken() { |
| 3580 _resolveUnit(r''' |
| 3581 /// A |
| 3582 /// |
| 3583 /// [int] |
| 3584 class Test { |
| 3585 } |
| 3586 '''); |
| 3587 _updateAndValidate(r''' |
| 3588 /// A |
| 3589 /// [int] |
| 3590 class Test { |
| 3591 } |
| 3592 '''); |
| 3593 } |
| 3594 |
| 3595 void test_endOfLineComment_add_beforeKeywordToken() { |
| 3596 _resolveUnit(r''' |
| 3597 main() { |
| 3598 var v = 42; |
| 3599 } |
| 3600 '''); |
| 3601 _updateAndValidate(r''' |
| 3602 main() { |
| 3603 // some comment |
| 3604 var v = 42; |
| 3605 } |
| 3606 '''); |
| 3607 } |
| 3608 |
| 3609 void test_endOfLineComment_add_beforeStringToken() { |
| 3610 _resolveUnit(r''' |
| 3611 main() { |
| 3612 print(0); |
| 3613 } |
| 3614 '''); |
| 3615 _updateAndValidate(r''' |
| 3616 main() { |
| 3617 // some comment |
| 3618 print(0); |
| 3619 } |
| 3620 '''); |
| 3621 } |
| 3622 |
| 3623 void test_endOfLineComment_edit() { |
| 3624 _resolveUnit(r''' |
| 3625 main() { |
| 3626 // some comment |
| 3627 print(0); |
| 3628 } |
| 3629 '''); |
| 3630 _updateAndValidate(r''' |
| 3631 main() { |
| 3632 // edited comment text |
| 3633 print(0); |
| 3634 } |
| 3635 '''); |
| 3636 } |
| 3637 |
| 3638 void test_endOfLineComment_localFunction_inTopLevelVariable() { |
| 3639 _resolveUnit(r''' |
| 3640 typedef int Binary(one, two, three); |
| 3641 |
| 3642 int Global = f((a, b, c) { |
| 3643 return 0; // Some comment |
| 3644 }); |
| 3645 '''); |
| 3646 _updateAndValidate(r''' |
| 3647 typedef int Binary(one, two, three); |
| 3648 |
| 3649 int Global = f((a, b, c) { |
| 3650 return 0; // Some comment |
| 3651 }); |
| 3652 '''); |
| 3653 } |
| 3654 |
| 3655 void test_endOfLineComment_outBody_add() { |
| 3656 _resolveUnit(r''' |
| 3657 main() { |
| 3658 Object x; |
| 3659 x.foo(); |
| 3660 } |
| 3661 '''); |
| 3662 _updateAndValidate( |
| 3663 r''' |
| 3664 // 000 |
| 3665 main() { |
| 3666 Object x; |
| 3667 x.foo(); |
| 3668 } |
| 3669 ''', |
| 3670 expectedSuccess: false); |
| 3671 } |
| 3672 |
| 3673 void test_endOfLineComment_outBody_remove() { |
| 3674 _resolveUnit(r''' |
| 3675 // 000 |
| 3676 main() { |
| 3677 Object x; |
| 3678 x.foo(); |
| 3679 } |
| 3680 '''); |
| 3681 _updateAndValidate( |
| 3682 r''' |
| 3683 main() { |
| 3684 Object x; |
| 3685 x.foo(); |
| 3686 } |
| 3687 ''', |
| 3688 expectedSuccess: false); |
| 3689 } |
| 3690 |
| 3691 void test_endOfLineComment_outBody_update() { |
| 3692 _resolveUnit(r''' |
| 3693 // 000 |
| 3694 main() { |
| 3695 Object x; |
| 3696 x.foo(); |
| 3697 } |
| 3698 '''); |
| 3699 _updateAndValidate( |
| 3700 r''' |
| 3701 // 10 |
| 3702 main() { |
| 3703 Object x; |
| 3704 x.foo(); |
| 3705 } |
| 3706 ''', |
| 3707 expectedSuccess: false); |
| 3708 } |
| 3709 |
| 3710 void test_endOfLineComment_remove() { |
| 3711 _resolveUnit(r''' |
| 3712 main() { |
| 3713 // some comment |
| 3714 print(0); |
| 3715 } |
| 3716 '''); |
| 3717 _updateAndValidate(r''' |
| 3718 main() { |
| 3719 print(0); |
| 3720 } |
| 3721 '''); |
| 3722 } |
| 3723 |
| 3724 void test_false_constConstructor_initializer() { |
| 3725 _resolveUnit(r''' |
| 3726 class C { |
| 3727 final int x; |
| 3728 const C(this.x); |
| 3729 const C.foo() : x = 0; |
| 3730 } |
| 3731 main() { |
| 3732 const {const C(0): 0, const C.foo(): 1}; |
| 3733 } |
| 3734 '''); |
| 3735 _updateAndValidate( |
| 3736 r''' |
| 3737 class C { |
| 3738 final int x; |
| 3739 const C(this.x); |
| 3740 const C.foo() : x = 1; |
| 3741 } |
| 3742 main() { |
| 3743 const {const C(0): 0, const C.foo(): 1}; |
| 3744 } |
| 3745 ''', |
| 3746 expectedSuccess: false); |
| 3747 } |
| 3748 |
| 3749 void test_false_expressionBody() { |
| 3750 _resolveUnit(r''' |
| 3751 class A { |
| 3752 final f = (() => 1)(); |
| 3753 } |
| 3754 '''); |
| 3755 _updateAndValidate( |
| 3756 r''' |
| 3757 class A { |
| 3758 final f = (() => 2)(); |
| 3759 } |
| 3760 ''', |
| 3761 expectedSuccess: false); |
| 3762 } |
| 3763 |
| 3764 void test_false_topLevelFunction_name() { |
| 3765 _resolveUnit(r''' |
| 3766 a() {} |
| 3767 b() {} |
| 3768 '''); |
| 3769 _updateAndValidate( |
| 3770 r''' |
| 3771 a() {} |
| 3772 bb() {} |
| 3773 ''', |
| 3774 expectedSuccess: false); |
| 3775 } |
| 3776 |
| 3777 void test_false_unbalancedCurlyBrackets_inNew() { |
| 3778 _resolveUnit(r''' |
| 3779 class A { |
| 3780 aaa() { |
| 3781 if (true) { |
| 3782 1; |
| 3783 } |
| 3784 } |
| 3785 |
| 3786 bbb() { |
| 3787 print(0123456789); |
| 3788 } |
| 3789 }'''); |
| 3790 _updateAndValidate( |
| 3791 r''' |
| 3792 class A { |
| 3793 aaa() { |
| 3794 1; |
| 3795 } |
| 3796 } |
| 3797 |
| 3798 bbb() { |
| 3799 print(0123456789); |
| 3800 } |
| 3801 }''', |
| 3802 expectedSuccess: false); |
| 3803 } |
| 3804 |
| 3805 void test_false_unbalancedCurlyBrackets_inOld() { |
| 3806 _resolveUnit(r''' |
| 3807 class A { |
| 3808 aaa() { |
| 3809 1; |
| 3810 } |
| 3811 } |
| 3812 |
| 3813 bbb() { |
| 3814 print(0123456789); |
| 3815 } |
| 3816 }'''); |
| 3817 _updateAndValidate( |
| 3818 r''' |
| 3819 class A { |
| 3820 aaa() { |
| 3821 if (true) { |
| 3822 1; |
| 3823 } |
| 3824 } |
| 3825 |
| 3826 bbb() { |
| 3827 print(0123456789); |
| 3828 } |
| 3829 }''', |
| 3830 expectedSuccess: false); |
| 3831 } |
| 3832 |
| 3833 void test_fieldClassField_propagatedType() { |
| 3834 _resolveUnit(r''' |
| 3835 class A { |
| 3836 static const A b = const B(); |
| 3837 const A(); |
| 3838 } |
| 3839 |
| 3840 class B extends A { |
| 3841 const B(); |
| 3842 } |
| 3843 |
| 3844 main() { |
| 3845 print(12); |
| 3846 A.b; |
| 3847 } |
| 3848 '''); |
| 3849 _updateAndValidate(r''' |
| 3850 class A { |
| 3851 static const A b = const B(); |
| 3852 const A(); |
| 3853 } |
| 3854 |
| 3855 class B extends A { |
| 3856 const B(); |
| 3857 } |
| 3858 |
| 3859 main() { |
| 3860 print(123); |
| 3861 A.b; |
| 3862 } |
| 3863 '''); |
| 3864 } |
| 3865 |
| 3866 void test_inBody_expression() { |
| 3867 _resolveUnit(r''' |
| 3868 class A { |
| 3869 m() { |
| 3870 print(1); |
| 3871 } |
| 3872 } |
| 3873 '''); |
| 3874 _updateAndValidate(r''' |
| 3875 class A { |
| 3876 m() { |
| 3877 print(2 + 3); |
| 3878 } |
| 3879 } |
| 3880 '''); |
| 3881 } |
| 3882 |
| 3883 void test_inBody_insertStatement() { |
| 3884 _resolveUnit(r''' |
| 3885 main() { |
| 3886 print(1); |
| 3887 } |
| 3888 '''); |
| 3889 _updateAndValidate(r''' |
| 3890 main() { |
| 3891 print(0); |
| 3892 print(1); |
| 3893 } |
| 3894 '''); |
| 3895 } |
| 3896 |
| 3897 void test_inBody_tokenToNode() { |
| 3898 _resolveUnit(r''' |
| 3899 main() { |
| 3900 var v = 42; |
| 3901 print(v); |
| 3902 } |
| 3903 '''); |
| 3904 _updateAndValidate(r''' |
| 3905 main() { |
| 3906 int v = 42; |
| 3907 print(v); |
| 3908 } |
| 3909 '''); |
| 3910 } |
| 3911 |
| 3912 void test_multiple_emptyLine() { |
| 3913 _resolveUnit(r''' |
| 3914 class A { |
| 3915 m() { |
| 3916 return true; |
| 3917 } |
| 3918 }'''); |
| 3919 for (int i = 0; i < 6; i++) { |
| 3920 if (i.isEven) { |
| 3921 _updateAndValidate( |
| 3922 r''' |
| 3923 class A { |
| 3924 m() { |
| 3925 return true; |
| 3926 |
| 3927 } |
| 3928 }''', |
| 3929 compareWithFull: false); |
| 3930 } else { |
| 3931 _updateAndValidate( |
| 3932 r''' |
| 3933 class A { |
| 3934 m() { |
| 3935 return true; |
| 3936 } |
| 3937 }''', |
| 3938 compareWithFull: false); |
| 3939 } |
| 3940 } |
| 3941 } |
| 3942 |
| 3943 void test_multiple_expression() { |
| 3944 _resolveUnit(r''' |
| 3945 main() { |
| 3946 print(1); |
| 3947 }'''); |
| 3948 for (int i = 0; i < 6; i++) { |
| 3949 if (i.isEven) { |
| 3950 _updateAndValidate( |
| 3951 r''' |
| 3952 main() { |
| 3953 print(12); |
| 3954 }''', |
| 3955 compareWithFull: false); |
| 3956 } else { |
| 3957 _updateAndValidate( |
| 3958 r''' |
| 3959 main() { |
| 3960 print(1); |
| 3961 }''', |
| 3962 compareWithFull: false); |
| 3963 } |
| 3964 } |
| 3965 } |
| 3966 |
| 3967 void test_true_emptyLine_betweenClassMembers_insert() { |
| 3968 _resolveUnit(r''' |
| 3969 class A { |
| 3970 a() {} |
| 3971 b() {} |
| 3972 } |
| 3973 '''); |
| 3974 _updateAndValidate(r''' |
| 3975 class A { |
| 3976 a() {} |
| 3977 |
| 3978 b() {} |
| 3979 } |
| 3980 '''); |
| 3981 } |
| 3982 |
| 3983 void test_true_emptyLine_betweenClassMembers_remove() { |
| 3984 _resolveUnit(r''' |
| 3985 class A { |
| 3986 a() {} |
| 3987 |
| 3988 b() {} |
| 3989 } |
| 3990 '''); |
| 3991 _updateAndValidate(r''' |
| 3992 class A { |
| 3993 a() {} |
| 3994 b() {} |
| 3995 } |
| 3996 '''); |
| 3997 } |
| 3998 |
| 3999 void test_true_emptyLine_betweenCompilationUnitMembers_insert() { |
| 4000 _resolveUnit(r''' |
| 4001 a() {} |
| 4002 b() {} |
| 4003 '''); |
| 4004 _updateAndValidate(r''' |
| 4005 a() {} |
| 4006 |
| 4007 b() {} |
| 4008 '''); |
| 4009 } |
| 4010 |
| 4011 void test_true_emptyLine_betweenCompilationUnitMembers_remove() { |
| 4012 _resolveUnit(r''' |
| 4013 a() { |
| 4014 print(1) |
| 4015 } |
| 4016 |
| 4017 b() { |
| 4018 foo(42); |
| 4019 } |
| 4020 foo(String p) {} |
| 4021 '''); |
| 4022 _updateAndValidate(r''' |
| 4023 a() { |
| 4024 print(1) |
| 4025 } |
| 4026 b() { |
| 4027 foo(42); |
| 4028 } |
| 4029 foo(String p) {} |
| 4030 '''); |
| 4031 } |
| 4032 |
| 4033 void test_true_wholeConstructor() { |
| 4034 _resolveUnit(r''' |
| 4035 class A { |
| 4036 A(int a) { |
| 4037 print(a); |
| 4038 } |
| 4039 } |
| 4040 '''); |
| 4041 _updateAndValidate(r''' |
| 4042 class A { |
| 4043 A(int b) { |
| 4044 print(b); |
| 4045 } |
| 4046 } |
| 4047 '''); |
| 4048 } |
| 4049 |
| 4050 void test_true_wholeConstructor_addInitializer() { |
| 4051 _resolveUnit(r''' |
| 4052 class A { |
| 4053 int field; |
| 4054 A(); |
| 4055 } |
| 4056 '''); |
| 4057 _updateAndValidate(r''' |
| 4058 class A { |
| 4059 int field; |
| 4060 A() : field = 5; |
| 4061 } |
| 4062 '''); |
| 4063 } |
| 4064 |
| 4065 void test_true_wholeFunction() { |
| 4066 _resolveUnit(r''' |
| 4067 foo() {} |
| 4068 main(int a) { |
| 4069 print(a); |
| 4070 } |
| 4071 '''); |
| 4072 _updateAndValidate(r''' |
| 4073 foo() {} |
| 4074 main(int b) { |
| 4075 print(b); |
| 4076 } |
| 4077 '''); |
| 4078 } |
| 4079 |
| 4080 void test_true_wholeFunction_firstTokenInUnit() { |
| 4081 _resolveUnit(r''' |
| 4082 main(int a) { |
| 4083 print(a); |
| 4084 } |
| 4085 '''); |
| 4086 _updateAndValidate(r''' |
| 4087 main(int b) { |
| 4088 print(b); |
| 4089 } |
| 4090 '''); |
| 4091 } |
| 4092 |
| 4093 void test_true_wholeMethod() { |
| 4094 _resolveUnit(r''' |
| 4095 class A { |
| 4096 main(int a) { |
| 4097 print(a); |
| 4098 } |
| 4099 } |
| 4100 '''); |
| 4101 _updateAndValidate(r''' |
| 4102 class A { |
| 4103 main(int b) { |
| 4104 print(b); |
| 4105 } |
| 4106 } |
| 4107 '''); |
| 4108 } |
| 4109 |
| 4110 void test_unusedHint_add_wasUsedOnlyInPart() { |
| 4111 Source partSource = addNamedSource( |
| 4112 '/my_unit.dart', |
| 4113 r''' |
| 4114 part of lib; |
| 4115 |
| 4116 f(A a) { |
| 4117 a._foo(); |
| 4118 } |
| 4119 '''); |
| 4120 _resolveUnit(r''' |
| 4121 library lib; |
| 4122 part 'my_unit.dart'; |
| 4123 class A { |
| 4124 _foo() { |
| 4125 print(1); |
| 4126 } |
| 4127 } |
| 4128 '''); |
| 4129 _runTasks(); |
| 4130 // perform incremental resolution |
| 4131 _resetWithIncremental(true); |
| 4132 analysisContext2.setContents( |
| 4133 partSource, |
| 4134 r''' |
| 4135 part of lib; |
| 4136 |
| 4137 f(A a) { |
| 4138 // a._foo(); |
| 4139 } |
| 4140 '''); |
| 4141 // no hints right now, because we delay hints computing |
| 4142 { |
| 4143 List<AnalysisError> errors = analysisContext.getErrors(source).errors; |
| 4144 expect(errors, isEmpty); |
| 4145 } |
| 4146 // a new hint should be added |
| 4147 List<AnalysisError> errors = analysisContext.computeErrors(source); |
| 4148 expect(errors, hasLength(1)); |
| 4149 expect(errors[0].errorCode.type, ErrorType.HINT); |
| 4150 // the same hint should be reported using a ChangeNotice |
| 4151 bool noticeFound = false; |
| 4152 AnalysisResult result = analysisContext2.performAnalysisTask(); |
| 4153 for (ChangeNotice notice in result.changeNotices) { |
| 4154 if (notice.source == source) { |
| 4155 expect(notice.errors, contains(errors[0])); |
| 4156 noticeFound = true; |
| 4157 } |
| 4158 } |
| 4159 expect(noticeFound, isTrue); |
| 4160 } |
| 4161 |
| 4162 void test_unusedHint_false_stillUsedInPart() { |
| 4163 addNamedSource( |
| 4164 '/my_unit.dart', |
| 4165 r''' |
| 4166 part of lib; |
| 4167 |
| 4168 f(A a) { |
| 4169 a._foo(); |
| 4170 } |
| 4171 '''); |
| 4172 _resolveUnit(r''' |
| 4173 library lib; |
| 4174 part 'my_unit.dart'; |
| 4175 class A { |
| 4176 _foo() { |
| 4177 print(1); |
| 4178 } |
| 4179 } |
| 4180 '''); |
| 4181 // perform incremental resolution |
| 4182 _resetWithIncremental(true); |
| 4183 analysisContext2.setContents( |
| 4184 source, |
| 4185 r''' |
| 4186 library lib; |
| 4187 part 'my_unit.dart'; |
| 4188 class A { |
| 4189 _foo() { |
| 4190 print(12); |
| 4191 } |
| 4192 } |
| 4193 '''); |
| 4194 // no hints |
| 4195 List<AnalysisError> errors = analysisContext.getErrors(source).errors; |
| 4196 expect(errors, isEmpty); |
| 4197 } |
| 4198 |
| 4199 void test_updateErrors_addNew_hint1() { |
| 4200 _resolveUnit(r''' |
| 4201 int main() { |
| 4202 return 42; |
| 4203 } |
| 4204 '''); |
| 4205 _updateAndValidate(r''' |
| 4206 int main() { |
| 4207 } |
| 4208 '''); |
| 4209 } |
| 4210 |
| 4211 void test_updateErrors_addNew_hint2() { |
| 4212 _resolveUnit(r''' |
| 4213 main() { |
| 4214 int v = 0; |
| 4215 print(v); |
| 4216 } |
| 4217 '''); |
| 4218 _updateAndValidate(r''' |
| 4219 main() { |
| 4220 int v = 0; |
| 4221 } |
| 4222 '''); |
| 4223 } |
| 4224 |
| 4225 void test_updateErrors_addNew_parse() { |
| 4226 _resolveUnit(r''' |
| 4227 main() { |
| 4228 print(42); |
| 4229 } |
| 4230 '''); |
| 4231 _updateAndValidate(r''' |
| 4232 main() { |
| 4233 print(42) |
| 4234 } |
| 4235 '''); |
| 4236 } |
| 4237 |
| 4238 void test_updateErrors_addNew_resolve() { |
| 4239 _resolveUnit(r''' |
| 4240 main() { |
| 4241 foo(); |
| 4242 } |
| 4243 foo() {} |
| 4244 '''); |
| 4245 _updateAndValidate(r''' |
| 4246 main() { |
| 4247 bar(); |
| 4248 } |
| 4249 foo() {} |
| 4250 '''); |
| 4251 } |
| 4252 |
| 4253 void test_updateErrors_addNew_resolve2() { |
| 4254 _resolveUnit(r''' |
| 4255 // this comment is important to reproduce the problem |
| 4256 main() { |
| 4257 int vvv = 42; |
| 4258 print(vvv); |
| 4259 } |
| 4260 '''); |
| 4261 _updateAndValidate(r''' |
| 4262 // this comment is important to reproduce the problem |
| 4263 main() { |
| 4264 int vvv = 42; |
| 4265 print(vvv2); |
| 4266 } |
| 4267 '''); |
| 4268 } |
| 4269 |
| 4270 void test_updateErrors_addNew_scan() { |
| 4271 _resolveUnit(r''' |
| 4272 main() { |
| 4273 1; |
| 4274 } |
| 4275 '''); |
| 4276 _updateAndValidate(r''' |
| 4277 main() { |
| 4278 1e; |
| 4279 } |
| 4280 '''); |
| 4281 } |
| 4282 |
| 4283 void test_updateErrors_addNew_verify() { |
| 4284 _resolveUnit(r''' |
| 4285 main() { |
| 4286 foo(0); |
| 4287 } |
| 4288 foo(int p) {} |
| 4289 '''); |
| 4290 _updateAndValidate(r''' |
| 4291 main() { |
| 4292 foo('abc'); |
| 4293 } |
| 4294 foo(int p) {} |
| 4295 '''); |
| 4296 } |
| 4297 |
| 4298 void test_updateErrors_removeExisting_hint() { |
| 4299 _resolveUnit(r''' |
| 4300 int main() { |
| 4301 } |
| 4302 '''); |
| 4303 _updateAndValidate(r''' |
| 4304 int main() { |
| 4305 return 42; |
| 4306 } |
| 4307 '''); |
| 4308 } |
| 4309 |
| 4310 void test_updateErrors_removeExisting_verify() { |
| 4311 _resolveUnit(r''' |
| 4312 f1() { |
| 4313 print(1) |
| 4314 } |
| 4315 f2() { |
| 4316 print(22) |
| 4317 } |
| 4318 f3() { |
| 4319 print(333) |
| 4320 } |
| 4321 '''); |
| 4322 _updateAndValidate(r''' |
| 4323 f1() { |
| 4324 print(1) |
| 4325 } |
| 4326 f2() { |
| 4327 print(22); |
| 4328 } |
| 4329 f3() { |
| 4330 print(333) |
| 4331 } |
| 4332 '''); |
| 4333 } |
| 4334 |
| 4335 void test_updateErrors_shiftExisting() { |
| 4336 _resolveUnit(r''' |
| 4337 f1() { |
| 4338 print(1) |
| 4339 } |
| 4340 f2() { |
| 4341 print(2); |
| 4342 } |
| 4343 f3() { |
| 4344 print(333) |
| 4345 } |
| 4346 '''); |
| 4347 _updateAndValidate(r''' |
| 4348 f1() { |
| 4349 print(1) |
| 4350 } |
| 4351 f2() { |
| 4352 print(22); |
| 4353 } |
| 4354 f3() { |
| 4355 print(333) |
| 4356 } |
| 4357 '''); |
| 4358 } |
| 4359 |
| 4360 void _assertEqualLineInfo(LineInfo incrLineInfo, LineInfo fullLineInfo) { |
| 4361 for (int offset = 0; offset < 1000; offset++) { |
| 4362 LineInfo_Location incrLocation = incrLineInfo.getLocation(offset); |
| 4363 LineInfo_Location fullLocation = fullLineInfo.getLocation(offset); |
| 4364 if (incrLocation.lineNumber != fullLocation.lineNumber || |
| 4365 incrLocation.columnNumber != fullLocation.columnNumber) { |
| 4366 fail('At offset $offset ' + |
| 4367 '(${incrLocation.lineNumber}, ${incrLocation.columnNumber})' + |
| 4368 ' != ' + |
| 4369 '(${fullLocation.lineNumber}, ${fullLocation.columnNumber})'); |
| 4370 } |
| 4371 } |
| 4372 } |
| 4373 |
| 4374 /** |
| 4375 * Reset the analysis context to have the 'incremental' option set to the |
| 4376 * given value. |
| 4377 */ |
| 4378 void _resetWithIncremental(bool enable) { |
| 4379 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 4380 analysisOptions.incremental = enable; |
| 4381 analysisOptions.incrementalApi = enable; |
| 4382 // log.logger = log.PRINT_LOGGER; |
| 4383 log.logger = log.NULL_LOGGER; |
| 4384 analysisContext2.analysisOptions = analysisOptions; |
| 4385 } |
| 4386 |
| 4387 void _resolveUnit(String code) { |
| 4388 this.code = code; |
| 4389 source = addSource(code); |
| 4390 oldLibrary = resolve2(source); |
| 4391 oldUnit = resolveCompilationUnit(source, oldLibrary); |
| 4392 oldUnitElement = oldUnit.element; |
| 4393 } |
| 4394 |
| 4395 void _runTasks() { |
| 4396 AnalysisResult result = analysisContext.performAnalysisTask(); |
| 4397 while (result.changeNotices != null) { |
| 4398 result = analysisContext.performAnalysisTask(); |
| 4399 } |
| 4400 } |
| 4401 |
| 4402 void _updateAndValidate(String newCode, |
| 4403 {bool expectedSuccess: true, bool compareWithFull: true}) { |
| 4404 // Run any pending tasks tasks. |
| 4405 _runTasks(); |
| 4406 // Update the source - currently this may cause incremental resolution. |
| 4407 // Then request the updated resolved unit. |
| 4408 _resetWithIncremental(true); |
| 4409 analysisContext2.setContents(source, newCode); |
| 4410 CompilationUnit newUnit = resolveCompilationUnit(source, oldLibrary); |
| 4411 List<AnalysisError> newErrors = analysisContext.computeErrors(source); |
| 4412 LineInfo newLineInfo = analysisContext.getLineInfo(source); |
| 4413 // check for expected failure |
| 4414 if (!expectedSuccess) { |
| 4415 expect(newUnit.element, isNot(same(oldUnitElement))); |
| 4416 return; |
| 4417 } |
| 4418 // The existing CompilationUnitElement should be updated. |
| 4419 expect(newUnit.element, same(oldUnitElement)); |
| 4420 // The only expected pending task should return the same resolved |
| 4421 // "newUnit", so all clients will get it using the usual way. |
| 4422 AnalysisResult analysisResult = analysisContext.performAnalysisTask(); |
| 4423 ChangeNotice notice = analysisResult.changeNotices[0]; |
| 4424 expect(notice.resolvedDartUnit, same(newUnit)); |
| 4425 // Resolve "newCode" from scratch. |
| 4426 if (compareWithFull) { |
| 4427 _resetWithIncremental(false); |
| 4428 source = addSource(newCode + ' '); |
| 4429 source = addSource(newCode); |
| 4430 _runTasks(); |
| 4431 LibraryElement library = resolve2(source); |
| 4432 CompilationUnit fullNewUnit = resolveCompilationUnit(source, library); |
| 4433 // Validate tokens. |
| 4434 _assertEqualTokens(newUnit, fullNewUnit); |
| 4435 // Validate LineInfo |
| 4436 _assertEqualLineInfo(newLineInfo, analysisContext.getLineInfo(source)); |
| 4437 // Validate that "incremental" and "full" units have the same resolution. |
| 4438 try { |
| 4439 assertSameResolution(newUnit, fullNewUnit, validateTypes: true); |
| 4440 } on IncrementalResolutionMismatch catch (mismatch) { |
| 4441 fail(mismatch.message); |
| 4442 } |
| 4443 List<AnalysisError> newFullErrors = |
| 4444 analysisContext.getErrors(source).errors; |
| 4445 _assertEqualErrors(newErrors, newFullErrors); |
| 4446 } |
| 4447 } |
| 4448 |
| 4449 static void _assertEqualToken(Token incrToken, Token fullToken) { |
| 4450 // print('[${incrToken.offset}] |$incrToken| vs. [${fullToken.offset}] |$full
Token|'); |
| 4451 expect(incrToken.type, fullToken.type); |
| 4452 expect(incrToken.offset, fullToken.offset); |
| 4453 expect(incrToken.length, fullToken.length); |
| 4454 expect(incrToken.lexeme, fullToken.lexeme); |
| 4455 } |
| 4456 |
| 4457 static void _assertEqualTokens( |
| 4458 CompilationUnit incrUnit, CompilationUnit fullUnit) { |
| 4459 Token incrToken = incrUnit.beginToken; |
| 4460 Token fullToken = fullUnit.beginToken; |
| 4461 while (incrToken.type != TokenType.EOF && fullToken.type != TokenType.EOF) { |
| 4462 _assertEqualToken(incrToken, fullToken); |
| 4463 // comments |
| 4464 { |
| 4465 Token incrComment = incrToken.precedingComments; |
| 4466 Token fullComment = fullToken.precedingComments; |
| 4467 while (true) { |
| 4468 if (fullComment == null) { |
| 4469 expect(incrComment, isNull); |
| 4470 break; |
| 4471 } |
| 4472 expect(incrComment, isNotNull); |
| 4473 _assertEqualToken(incrComment, fullComment); |
| 4474 incrComment = incrComment.next; |
| 4475 fullComment = fullComment.next; |
| 4476 } |
| 4477 } |
| 4478 // next tokens |
| 4479 incrToken = incrToken.next; |
| 4480 fullToken = fullToken.next; |
| 4481 } |
| 4482 } |
| 4483 } |
| 4484 |
| 4485 @reflectiveTest |
| 4486 class ResolutionContextBuilderTest extends EngineTestCase { |
| 4487 GatheringErrorListener listener = new GatheringErrorListener(); |
| 4488 |
| 4489 void test_scopeFor_ClassDeclaration() { |
| 4490 Scope scope = _scopeFor(_createResolvedClassDeclaration()); |
| 4491 EngineTestCase.assertInstanceOf( |
| 4492 (obj) => obj is LibraryScope, LibraryScope, scope); |
| 4493 } |
| 4494 |
| 4495 void test_scopeFor_ClassTypeAlias() { |
| 4496 Scope scope = _scopeFor(_createResolvedClassTypeAlias()); |
| 4497 EngineTestCase.assertInstanceOf( |
| 4498 (obj) => obj is LibraryScope, LibraryScope, scope); |
| 4499 } |
| 4500 |
| 4501 void test_scopeFor_CompilationUnit() { |
| 4502 Scope scope = _scopeFor(_createResolvedCompilationUnit()); |
| 4503 EngineTestCase.assertInstanceOf( |
| 4504 (obj) => obj is LibraryScope, LibraryScope, scope); |
| 4505 } |
| 4506 |
| 4507 void test_scopeFor_ConstructorDeclaration() { |
| 4508 Scope scope = _scopeFor(_createResolvedConstructorDeclaration()); |
| 4509 EngineTestCase.assertInstanceOf( |
| 4510 (obj) => obj is ClassScope, ClassScope, scope); |
| 4511 } |
| 4512 |
| 4513 void test_scopeFor_ConstructorDeclaration_parameters() { |
| 4514 Scope scope = _scopeFor(_createResolvedConstructorDeclaration().parameters); |
| 4515 EngineTestCase.assertInstanceOf( |
| 4516 (obj) => obj is FunctionScope, FunctionScope, scope); |
| 4517 } |
| 4518 |
| 4519 void test_scopeFor_FunctionDeclaration() { |
| 4520 Scope scope = _scopeFor(_createResolvedFunctionDeclaration()); |
| 4521 EngineTestCase.assertInstanceOf( |
| 4522 (obj) => obj is LibraryScope, LibraryScope, scope); |
| 4523 } |
| 4524 |
| 4525 void test_scopeFor_FunctionDeclaration_parameters() { |
| 4526 Scope scope = _scopeFor( |
| 4527 _createResolvedFunctionDeclaration().functionExpression.parameters); |
| 4528 EngineTestCase.assertInstanceOf( |
| 4529 (obj) => obj is FunctionScope, FunctionScope, scope); |
| 4530 } |
| 4531 |
| 4532 void test_scopeFor_FunctionTypeAlias() { |
| 4533 Scope scope = _scopeFor(_createResolvedFunctionTypeAlias()); |
| 4534 EngineTestCase.assertInstanceOf( |
| 4535 (obj) => obj is LibraryScope, LibraryScope, scope); |
| 4536 } |
| 4537 |
| 4538 void test_scopeFor_FunctionTypeAlias_parameters() { |
| 4539 Scope scope = _scopeFor(_createResolvedFunctionTypeAlias().parameters); |
| 4540 EngineTestCase.assertInstanceOf( |
| 4541 (obj) => obj is FunctionTypeScope, FunctionTypeScope, scope); |
| 4542 } |
| 4543 |
| 4544 void test_scopeFor_MethodDeclaration() { |
| 4545 Scope scope = _scopeFor(_createResolvedMethodDeclaration()); |
| 4546 EngineTestCase.assertInstanceOf( |
| 4547 (obj) => obj is ClassScope, ClassScope, scope); |
| 4548 } |
| 4549 |
| 4550 void test_scopeFor_MethodDeclaration_body() { |
| 4551 Scope scope = _scopeFor(_createResolvedMethodDeclaration().body); |
| 4552 EngineTestCase.assertInstanceOf( |
| 4553 (obj) => obj is FunctionScope, FunctionScope, scope); |
| 4554 } |
| 4555 |
| 4556 void test_scopeFor_notInCompilationUnit() { |
| 4557 try { |
| 4558 _scopeFor(AstFactory.identifier3("x")); |
| 4559 fail("Expected AnalysisException"); |
| 4560 } on AnalysisException { |
| 4561 // Expected |
| 4562 } |
| 4563 } |
| 4564 |
| 4565 void test_scopeFor_null() { |
| 4566 try { |
| 4567 _scopeFor(null); |
| 4568 fail("Expected AnalysisException"); |
| 4569 } on AnalysisException { |
| 4570 // Expected |
| 4571 } |
| 4572 } |
| 4573 |
| 4574 void test_scopeFor_unresolved() { |
| 4575 try { |
| 4576 _scopeFor(AstFactory.compilationUnit()); |
| 4577 fail("Expected AnalysisException"); |
| 4578 } on AnalysisException { |
| 4579 // Expected |
| 4580 } |
| 4581 } |
| 4582 |
| 4583 ClassDeclaration _createResolvedClassDeclaration() { |
| 4584 CompilationUnit unit = _createResolvedCompilationUnit(); |
| 4585 String className = "C"; |
| 4586 ClassDeclaration classNode = AstFactory.classDeclaration( |
| 4587 null, className, AstFactory.typeParameterList(), null, null, null); |
| 4588 unit.declarations.add(classNode); |
| 4589 ClassElement classElement = ElementFactory.classElement2(className); |
| 4590 classNode.name.staticElement = classElement; |
| 4591 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ |
| 4592 classElement |
| 4593 ]; |
| 4594 return classNode; |
| 4595 } |
| 4596 |
| 4597 ClassTypeAlias _createResolvedClassTypeAlias() { |
| 4598 CompilationUnit unit = _createResolvedCompilationUnit(); |
| 4599 String className = "C"; |
| 4600 ClassTypeAlias classNode = AstFactory.classTypeAlias( |
| 4601 className, AstFactory.typeParameterList(), null, null, null, null); |
| 4602 unit.declarations.add(classNode); |
| 4603 ClassElement classElement = ElementFactory.classElement2(className); |
| 4604 classNode.name.staticElement = classElement; |
| 4605 (unit.element as CompilationUnitElementImpl).types = <ClassElement>[ |
| 4606 classElement |
| 4607 ]; |
| 4608 return classNode; |
| 4609 } |
| 4610 |
| 4611 CompilationUnit _createResolvedCompilationUnit() { |
| 4612 CompilationUnit unit = AstFactory.compilationUnit(); |
| 4613 LibraryElementImpl library = |
| 4614 ElementFactory.library(AnalysisContextFactory.contextWithCore(), "lib"); |
| 4615 unit.element = library.definingCompilationUnit; |
| 4616 return unit; |
| 4617 } |
| 4618 |
| 4619 ConstructorDeclaration _createResolvedConstructorDeclaration() { |
| 4620 ClassDeclaration classNode = _createResolvedClassDeclaration(); |
| 4621 String constructorName = "f"; |
| 4622 ConstructorDeclaration constructorNode = AstFactory.constructorDeclaration( |
| 4623 AstFactory.identifier3(constructorName), |
| 4624 null, |
| 4625 AstFactory.formalParameterList(), |
| 4626 null); |
| 4627 classNode.members.add(constructorNode); |
| 4628 ConstructorElement constructorElement = |
| 4629 ElementFactory.constructorElement2(classNode.element, null); |
| 4630 constructorNode.element = constructorElement; |
| 4631 (classNode.element as ClassElementImpl).constructors = <ConstructorElement>[ |
| 4632 constructorElement |
| 4633 ]; |
| 4634 return constructorNode; |
| 4635 } |
| 4636 |
| 4637 FunctionDeclaration _createResolvedFunctionDeclaration() { |
| 4638 CompilationUnit unit = _createResolvedCompilationUnit(); |
| 4639 String functionName = "f"; |
| 4640 FunctionDeclaration functionNode = AstFactory.functionDeclaration( |
| 4641 null, null, functionName, AstFactory.functionExpression()); |
| 4642 unit.declarations.add(functionNode); |
| 4643 FunctionElement functionElement = |
| 4644 ElementFactory.functionElement(functionName); |
| 4645 functionNode.name.staticElement = functionElement; |
| 4646 (unit.element as CompilationUnitElementImpl).functions = <FunctionElement>[ |
| 4647 functionElement |
| 4648 ]; |
| 4649 return functionNode; |
| 4650 } |
| 4651 |
| 4652 FunctionTypeAlias _createResolvedFunctionTypeAlias() { |
| 4653 CompilationUnit unit = _createResolvedCompilationUnit(); |
| 4654 FunctionTypeAlias aliasNode = AstFactory.typeAlias( |
| 4655 AstFactory.typeName4("A"), |
| 4656 "F", |
| 4657 AstFactory.typeParameterList(), |
| 4658 AstFactory.formalParameterList()); |
| 4659 unit.declarations.add(aliasNode); |
| 4660 SimpleIdentifier aliasName = aliasNode.name; |
| 4661 FunctionTypeAliasElement aliasElement = |
| 4662 new FunctionTypeAliasElementImpl.forNode(aliasName); |
| 4663 aliasName.staticElement = aliasElement; |
| 4664 (unit.element as CompilationUnitElementImpl).typeAliases = |
| 4665 <FunctionTypeAliasElement>[aliasElement]; |
| 4666 return aliasNode; |
| 4667 } |
| 4668 |
| 4669 MethodDeclaration _createResolvedMethodDeclaration() { |
| 4670 ClassDeclaration classNode = _createResolvedClassDeclaration(); |
| 4671 String methodName = "f"; |
| 4672 MethodDeclaration methodNode = AstFactory.methodDeclaration( |
| 4673 null, |
| 4674 null, |
| 4675 null, |
| 4676 null, |
| 4677 AstFactory.identifier3(methodName), |
| 4678 AstFactory.formalParameterList()); |
| 4679 classNode.members.add(methodNode); |
| 4680 MethodElement methodElement = |
| 4681 ElementFactory.methodElement(methodName, null); |
| 4682 methodNode.name.staticElement = methodElement; |
| 4683 (classNode.element as ClassElementImpl).methods = <MethodElement>[ |
| 4684 methodElement |
| 4685 ]; |
| 4686 return methodNode; |
| 4687 } |
| 4688 |
| 4689 Scope _scopeFor(AstNode node) { |
| 4690 return ResolutionContextBuilder.contextFor(node, listener).scope; |
| 4691 } |
| 4692 } |
| 4693 |
| 4694 class _Edit { |
| 4695 final int offset; |
| 4696 final int length; |
| 4697 final String replacement; |
| 4698 _Edit(this.offset, this.length, this.replacement); |
| 4699 } |
OLD | NEW |