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

Side by Side Diff: packages/analyzer/test/generated/incremental_resolver_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698