| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 void test_false_enum_constants_remove() { | 218 void test_false_enum_constants_remove() { |
| 219 resetWithEnum(); | 219 resetWithEnum(); |
| 220 _assertCompilationUnitMatches(false, r''' | 220 _assertCompilationUnitMatches(false, r''' |
| 221 enum E {A, B, C} | 221 enum E {A, B, C} |
| 222 ''', r''' | 222 ''', r''' |
| 223 enum E {A, B} | 223 enum E {A, B} |
| 224 '''); | 224 '''); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void test_false_export_hide_add() { |
| 228 _assertCompilationUnitMatches(false, r''' |
| 229 export 'dart:async' hide Future; |
| 230 ''', r''' |
| 231 export 'dart:async' hide Future, Stream; |
| 232 '''); |
| 233 } |
| 234 |
| 235 void test_false_export_hide_remove() { |
| 236 _assertCompilationUnitMatches(false, r''' |
| 237 export 'dart:async' hide Future, Stream; |
| 238 ''', r''' |
| 239 export 'dart:async' hide Future; |
| 240 '''); |
| 241 } |
| 242 |
| 243 void test_false_export_list_add() { |
| 244 _assertCompilationUnitMatches(false, r''' |
| 245 export 'dart:async'; |
| 246 ''', r''' |
| 247 export 'dart:async'; |
| 248 export 'dart:math'; |
| 249 '''); |
| 250 } |
| 251 |
| 252 void test_false_export_list_remove() { |
| 253 _assertCompilationUnitMatches(false, r''' |
| 254 export 'dart:async'; |
| 255 export 'dart:math'; |
| 256 ''', r''' |
| 257 export 'dart:async'; |
| 258 '''); |
| 259 } |
| 260 |
| 261 void test_false_export_show_add() { |
| 262 _assertCompilationUnitMatches(false, r''' |
| 263 export 'dart:async' show Future; |
| 264 ''', r''' |
| 265 export 'dart:async' show Future, Stream; |
| 266 '''); |
| 267 } |
| 268 |
| 269 void test_false_export_show_remove() { |
| 270 _assertCompilationUnitMatches(false, r''' |
| 271 export 'dart:async' show Future, Stream; |
| 272 ''', r''' |
| 273 export 'dart:async' show Future; |
| 274 '''); |
| 275 } |
| 276 |
| 227 void test_false_extendsClause_add() { | 277 void test_false_extendsClause_add() { |
| 228 _assertCompilationUnitMatches(false, r''' | 278 _assertCompilationUnitMatches(false, r''' |
| 229 class A {} | 279 class A {} |
| 230 class B {} | 280 class B {} |
| 231 ''', r''' | 281 ''', r''' |
| 232 class A {} | 282 class A {} |
| 233 class B extends A {} | 283 class B extends A {} |
| 234 '''); | 284 '''); |
| 235 } | 285 } |
| 236 | 286 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 class A {} | 457 class A {} |
| 408 class B {} | 458 class B {} |
| 409 class C implements A, B {} | 459 class C implements A, B {} |
| 410 ''', r''' | 460 ''', r''' |
| 411 class A {} | 461 class A {} |
| 412 class B {} | 462 class B {} |
| 413 class C implements B, A {} | 463 class C implements B, A {} |
| 414 '''); | 464 '''); |
| 415 } | 465 } |
| 416 | 466 |
| 467 void test_false_import_hide_add() { |
| 468 _assertCompilationUnitMatches(false, r''' |
| 469 import 'dart:async' hide Future; |
| 470 ''', r''' |
| 471 import 'dart:async' hide Future, Stream; |
| 472 '''); |
| 473 } |
| 474 |
| 475 void test_false_import_hide_remove() { |
| 476 _assertCompilationUnitMatches(false, r''' |
| 477 import 'dart:async' hide Future, Stream; |
| 478 ''', r''' |
| 479 import 'dart:async' hide Future; |
| 480 '''); |
| 481 } |
| 482 |
| 483 void test_false_import_list_add() { |
| 484 _assertCompilationUnitMatches(false, r''' |
| 485 import 'dart:async'; |
| 486 ''', r''' |
| 487 import 'dart:async'; |
| 488 import 'dart:math'; |
| 489 '''); |
| 490 } |
| 491 |
| 492 void test_false_import_list_remove() { |
| 493 _assertCompilationUnitMatches(false, r''' |
| 494 import 'dart:async'; |
| 495 import 'dart:math'; |
| 496 ''', r''' |
| 497 import 'dart:async'; |
| 498 '''); |
| 499 } |
| 500 |
| 501 void test_false_import_prefix_add() { |
| 502 _assertCompilationUnitMatches(false, r''' |
| 503 import 'dart:async'; |
| 504 ''', r''' |
| 505 import 'dart:async' as async; |
| 506 '''); |
| 507 } |
| 508 |
| 509 void test_false_import_prefix_edit() { |
| 510 _assertCompilationUnitMatches(false, r''' |
| 511 import 'dart:async' as oldPrefix; |
| 512 ''', r''' |
| 513 import 'dart:async' as newPrefix; |
| 514 '''); |
| 515 } |
| 516 |
| 517 void test_false_import_prefix_remove() { |
| 518 _assertCompilationUnitMatches(false, r''' |
| 519 import 'dart:async' as async; |
| 520 ''', r''' |
| 521 import 'dart:async'; |
| 522 '''); |
| 523 } |
| 524 |
| 525 void test_false_import_show_add() { |
| 526 _assertCompilationUnitMatches(false, r''' |
| 527 import 'dart:async' show Future; |
| 528 ''', r''' |
| 529 import 'dart:async' show Future, Stream; |
| 530 '''); |
| 531 } |
| 532 |
| 533 void test_false_import_show_remove() { |
| 534 _assertCompilationUnitMatches(false, r''' |
| 535 import 'dart:async' show Future, Stream; |
| 536 ''', r''' |
| 537 import 'dart:async' show Future; |
| 538 '''); |
| 539 } |
| 540 |
| 541 void test_false_part_list_add() { |
| 542 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 543 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 544 _assertCompilationUnitMatches(false, r''' |
| 545 library lib; |
| 546 part 'unitA.dart'; |
| 547 ''', r''' |
| 548 library lib; |
| 549 part 'unitA.dart'; |
| 550 part 'unitB.dart'; |
| 551 '''); |
| 552 } |
| 553 |
| 554 void test_false_part_list_remove() { |
| 555 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 556 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 557 _assertCompilationUnitMatches(false, r''' |
| 558 library lib; |
| 559 part 'unitA.dart'; |
| 560 part 'unitB.dart'; |
| 561 ''', r''' |
| 562 library lib; |
| 563 part 'unitA.dart'; |
| 564 '''); |
| 565 } |
| 566 |
| 417 void test_false_topLevelVariable_list_add() { | 567 void test_false_topLevelVariable_list_add() { |
| 418 _assertCompilationUnitMatches(false, r''' | 568 _assertCompilationUnitMatches(false, r''' |
| 419 const int A = 1; | 569 const int A = 1; |
| 420 const int C = 3; | 570 const int C = 3; |
| 421 ''', r''' | 571 ''', r''' |
| 422 const int A = 1; | 572 const int A = 1; |
| 423 const int B = 2; | 573 const int B = 2; |
| 424 const int C = 3; | 574 const int C = 3; |
| 425 '''); | 575 '''); |
| 426 } | 576 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 main() { | 844 main() { |
| 695 int a = 42; | 845 int a = 42; |
| 696 } | 846 } |
| 697 ''', r''' | 847 ''', r''' |
| 698 main() { | 848 main() { |
| 699 int a = 42; | 849 int a = 42; |
| 700 } | 850 } |
| 701 '''); | 851 '''); |
| 702 } | 852 } |
| 703 | 853 |
| 854 void test_true_export_hide_reorder() { |
| 855 _assertCompilationUnitMatches(true, r''' |
| 856 export 'dart:async' hide Future, Stream; |
| 857 ''', r''' |
| 858 export 'dart:async' hide Stream, Future; |
| 859 '''); |
| 860 } |
| 861 |
| 862 void test_true_export_list_reorder() { |
| 863 _assertCompilationUnitMatches(true, r''' |
| 864 export 'dart:async'; |
| 865 export 'dart:math'; |
| 866 ''', r''' |
| 867 export 'dart:math'; |
| 868 export 'dart:async'; |
| 869 '''); |
| 870 } |
| 871 |
| 872 void test_true_export_list_same() { |
| 873 _assertCompilationUnitMatches(true, r''' |
| 874 export 'dart:async'; |
| 875 export 'dart:math'; |
| 876 ''', r''' |
| 877 export 'dart:async'; |
| 878 export 'dart:math'; |
| 879 '''); |
| 880 } |
| 881 |
| 882 void test_true_export_show_reorder() { |
| 883 _assertCompilationUnitMatches(true, r''' |
| 884 export 'dart:async' show Future, Stream; |
| 885 ''', r''' |
| 886 export 'dart:async' show Stream, Future; |
| 887 '''); |
| 888 } |
| 889 |
| 704 void test_true_extendsClause_same() { | 890 void test_true_extendsClause_same() { |
| 705 _assertCompilationUnitMatches(true, r''' | 891 _assertCompilationUnitMatches(true, r''' |
| 706 class A {} | 892 class A {} |
| 707 class B extends A {} | 893 class B extends A {} |
| 708 ''', r''' | 894 ''', r''' |
| 709 class A {} | 895 class A {} |
| 710 class B extends A {} | 896 class B extends A {} |
| 711 '''); | 897 '''); |
| 712 } | 898 } |
| 713 | 899 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 void test_true_implementsClause_same() { | 932 void test_true_implementsClause_same() { |
| 747 _assertCompilationUnitMatches(true, r''' | 933 _assertCompilationUnitMatches(true, r''' |
| 748 class A {} | 934 class A {} |
| 749 class B implements A {} | 935 class B implements A {} |
| 750 ''', r''' | 936 ''', r''' |
| 751 class A {} | 937 class A {} |
| 752 class B implements A {} | 938 class B implements A {} |
| 753 '''); | 939 '''); |
| 754 } | 940 } |
| 755 | 941 |
| 942 void test_true_import_hide_reorder() { |
| 943 _assertCompilationUnitMatches(true, r''' |
| 944 import 'dart:async' hide Future, Stream; |
| 945 ''', r''' |
| 946 import 'dart:async' hide Stream, Future; |
| 947 '''); |
| 948 } |
| 949 |
| 950 void test_true_import_list_reorder() { |
| 951 _assertCompilationUnitMatches(true, r''' |
| 952 import 'dart:async'; |
| 953 import 'dart:math'; |
| 954 ''', r''' |
| 955 import 'dart:math'; |
| 956 import 'dart:async'; |
| 957 '''); |
| 958 } |
| 959 |
| 960 void test_true_import_list_same() { |
| 961 _assertCompilationUnitMatches(true, r''' |
| 962 import 'dart:async'; |
| 963 import 'dart:math'; |
| 964 ''', r''' |
| 965 import 'dart:async'; |
| 966 import 'dart:math'; |
| 967 '''); |
| 968 } |
| 969 |
| 970 void test_true_import_prefix() { |
| 971 _assertCompilationUnitMatches(true, r''' |
| 972 import 'dart:async' as async; |
| 973 ''', r''' |
| 974 import 'dart:async' as async; |
| 975 '''); |
| 976 } |
| 977 |
| 978 void test_true_import_show_reorder() { |
| 979 _assertCompilationUnitMatches(true, r''' |
| 980 import 'dart:async' show Future, Stream; |
| 981 ''', r''' |
| 982 import 'dart:async' show Stream, Future; |
| 983 '''); |
| 984 } |
| 985 |
| 986 void test_true_part_list_reorder() { |
| 987 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 988 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 989 _assertCompilationUnitMatches(true, r''' |
| 990 library lib; |
| 991 part 'unitA.dart'; |
| 992 part 'unitB.dart'; |
| 993 ''', r''' |
| 994 library lib; |
| 995 part 'unitB.dart'; |
| 996 part 'unitA.dart'; |
| 997 '''); |
| 998 } |
| 999 |
| 1000 void test_true_part_list_same() { |
| 1001 addNamedSource('/unitA.dart', 'part of lib; class A {}'); |
| 1002 addNamedSource('/unitB.dart', 'part of lib; class B {}'); |
| 1003 _assertCompilationUnitMatches(true, r''' |
| 1004 library lib; |
| 1005 part 'unitA.dart'; |
| 1006 part 'unitB.dart'; |
| 1007 ''', r''' |
| 1008 library lib; |
| 1009 part 'unitA.dart'; |
| 1010 part 'unitB.dart'; |
| 1011 '''); |
| 1012 } |
| 1013 |
| 756 void test_true_topLevelVariable_list_reorder() { | 1014 void test_true_topLevelVariable_list_reorder() { |
| 757 _assertCompilationUnitMatches(true, r''' | 1015 _assertCompilationUnitMatches(true, r''' |
| 758 const int A = 1; | 1016 const int A = 1; |
| 759 const int B = 2; | 1017 const int B = 2; |
| 760 const int C = 3; | 1018 const int C = 3; |
| 761 ''', r''' | 1019 ''', r''' |
| 762 const int C = 3; | 1020 const int C = 3; |
| 763 const int A = 1; | 1021 const int A = 1; |
| 764 const int B = 2; | 1022 const int B = 2; |
| 765 '''); | 1023 '''); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 } | 1083 } |
| 826 } | 1084 } |
| 827 | 1085 |
| 828 | 1086 |
| 829 class IncrementalResolverTest extends ResolverTestCase { | 1087 class IncrementalResolverTest extends ResolverTestCase { |
| 830 Source source; | 1088 Source source; |
| 831 String code; | 1089 String code; |
| 832 LibraryElement library; | 1090 LibraryElement library; |
| 833 CompilationUnit unit; | 1091 CompilationUnit unit; |
| 834 | 1092 |
| 1093 void fail_test_constructor_fieldInitializer_add() { |
| 1094 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet |
| 1095 _resolveUnit(r''' |
| 1096 class A { |
| 1097 int f; |
| 1098 A(int a, int b); |
| 1099 }'''); |
| 1100 _resolve(_editString(');', ') : f = a + b;'), _isClassMember); |
| 1101 } |
| 1102 |
| 835 void fail_test_functionBody_addLocalVariable() { | 1103 void fail_test_functionBody_addLocalVariable() { |
| 836 // TODO(scheglov) this test fails, because we don't create element models | 1104 // TODO(scheglov) this test fails, because we don't create element models |
| 837 // for new local variables | 1105 // for new local variables |
| 838 _resolveUnit(r''' | 1106 _resolveUnit(r''' |
| 839 main(int a, int b) { | 1107 main(int a, int b) { |
| 840 return a + b; | 1108 return a + b; |
| 841 } | 1109 } |
| 842 '''); | 1110 '''); |
| 843 _resolve(_editString(' return a + b;', r''' | 1111 _resolve(_editString(' return a + b;', r''' |
| 844 int res = a + b; | 1112 int res = a + b; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 861 _resolveUnit(r''' | 1129 _resolveUnit(r''' |
| 862 class A { | 1130 class A { |
| 863 int f; | 1131 int f; |
| 864 A(int a, int b) : f = a + b { | 1132 A(int a, int b) : f = a + b { |
| 865 int a = 42; | 1133 int a = 42; |
| 866 } | 1134 } |
| 867 }'''); | 1135 }'''); |
| 868 _resolve(_editString('+', '*'), _isExpression); | 1136 _resolve(_editString('+', '*'), _isExpression); |
| 869 } | 1137 } |
| 870 | 1138 |
| 871 void fail_test_constructor_fieldInitializer_add() { | |
| 872 // TODO(scheglov) resolver uses "enclosingClass", which we don't set yet | |
| 873 _resolveUnit(r''' | |
| 874 class A { | |
| 875 int f; | |
| 876 A(int a, int b); | |
| 877 }'''); | |
| 878 _resolve(_editString(');', ') : f = a + b;'), _isClassMember); | |
| 879 } | |
| 880 | |
| 881 void test_constructor_superConstructorInvocation() { | 1139 void test_constructor_superConstructorInvocation() { |
| 882 _resolveUnit(r''' | 1140 _resolveUnit(r''' |
| 883 class A { | 1141 class A { |
| 884 A(int p); | 1142 A(int p); |
| 885 } | 1143 } |
| 886 class A { | 1144 class A { |
| 887 A(int a, int b) : super(a + b); | 1145 A(int a, int b) : super(a + b); |
| 888 } | 1146 } |
| 889 '''); | 1147 '''); |
| 890 _resolve(_editString('+', '*'), _isExpression); | 1148 _resolve(_editString('+', '*'), _isExpression); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 | 1269 |
| 1012 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset, | 1270 static AstNode _findNodeAt(CompilationUnit oldUnit, int offset, |
| 1013 Predicate<AstNode> predicate) { | 1271 Predicate<AstNode> predicate) { |
| 1014 NodeLocator locator = new NodeLocator.con1(offset); | 1272 NodeLocator locator = new NodeLocator.con1(offset); |
| 1015 AstNode node = locator.searchWithin(oldUnit); | 1273 AstNode node = locator.searchWithin(oldUnit); |
| 1016 return node.getAncestor(predicate); | 1274 return node.getAncestor(predicate); |
| 1017 } | 1275 } |
| 1018 | 1276 |
| 1019 static bool _isBlock(AstNode node) => node is Block; | 1277 static bool _isBlock(AstNode node) => node is Block; |
| 1020 | 1278 |
| 1279 static bool _isClassMember(AstNode node) => node is ClassMember; |
| 1280 |
| 1021 static bool _isExpression(AstNode node) => node is Expression; | 1281 static bool _isExpression(AstNode node) => node is Expression; |
| 1022 | 1282 |
| 1023 static bool _isClassMember(AstNode node) => node is ClassMember; | |
| 1024 | |
| 1025 static bool _isFunctionBody(AstNode node) => node is FunctionBody; | 1283 static bool _isFunctionBody(AstNode node) => node is FunctionBody; |
| 1026 | 1284 |
| 1027 static bool _isStatement(AstNode node) => node is Statement; | 1285 static bool _isStatement(AstNode node) => node is Statement; |
| 1028 | 1286 |
| 1029 static CompilationUnit _parseUnit(String code) { | 1287 static CompilationUnit _parseUnit(String code) { |
| 1030 var errorListener = new BooleanErrorListener(); | 1288 var errorListener = new BooleanErrorListener(); |
| 1031 var reader = new CharSequenceReader(code); | 1289 var reader = new CharSequenceReader(code); |
| 1032 var scanner = new Scanner(null, reader, errorListener); | 1290 var scanner = new Scanner(null, reader, errorListener); |
| 1033 var token = scanner.tokenize(); | 1291 var token = scanner.tokenize(); |
| 1034 var parser = new Parser(null, errorListener); | 1292 var parser = new Parser(null, errorListener); |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2114 _visitList(node.metadata, other.metadata); | 2372 _visitList(node.metadata, other.metadata); |
| 2115 _visitNode(node.identifier, other.identifier); | 2373 _visitNode(node.identifier, other.identifier); |
| 2116 } | 2374 } |
| 2117 | 2375 |
| 2118 static void assertSameResolution(CompilationUnit actual, | 2376 static void assertSameResolution(CompilationUnit actual, |
| 2119 CompilationUnit expected) { | 2377 CompilationUnit expected) { |
| 2120 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 2378 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 2121 actual.accept(validator); | 2379 actual.accept(validator); |
| 2122 } | 2380 } |
| 2123 } | 2381 } |
| OLD | NEW |