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

Side by Side Diff: pkg/analyzer/test/src/task/incremental_element_builder_test.dart

Issue 2413023003: Test that IncrementalCompilationUnitElementBuilder keeps elements in the same order as nodes. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.src.task.incremental_element_builder_test; 5 library analyzer.test.src.task.incremental_element_builder_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/visitor.dart'; 9 import 'package:analyzer/dart/element/visitor.dart';
10 import 'package:analyzer/src/dart/ast/utilities.dart'; 10 import 'package:analyzer/src/dart/ast/utilities.dart';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 '''); 90 ''');
91 helper.initNew(newUnit, unitDelta); 91 helper.initNew(newUnit, unitDelta);
92 // nodes 92 // nodes
93 ClassMember newConstructorNode = helper.newMembers[0]; 93 ClassMember newConstructorNode = helper.newMembers[0];
94 // elements 94 // elements
95 ConstructorElement newConstructorElement = newConstructorNode.element; 95 ConstructorElement newConstructorElement = newConstructorNode.element;
96 expect(newConstructorElement, isNotNull); 96 expect(newConstructorElement, isNotNull);
97 expect(newConstructorElement.name, 'a'); 97 expect(newConstructorElement.name, 'a');
98 // classElement.constructors 98 // classElement.constructors
99 ClassElement classElement = helper.element; 99 ClassElement classElement = helper.element;
100 expect(classElement.constructors, unorderedEquals([newConstructorElement])); 100 expect(classElement.constructors, [newConstructorElement]);
101 // verify delta 101 // verify delta
102 expect(helper.delta.hasUnnamedConstructorChange, isTrue); 102 expect(helper.delta.hasUnnamedConstructorChange, isTrue);
103 expect(helper.delta.addedConstructors, 103 expect(helper.delta.addedConstructors,
104 unorderedEquals([newConstructorElement])); 104 unorderedEquals([newConstructorElement]));
105 expect(helper.delta.removedConstructors, 105 expect(helper.delta.removedConstructors,
106 unorderedEquals([oldConstructorElement])); 106 unorderedEquals([oldConstructorElement]));
107 expect(helper.delta.addedAccessors, isEmpty); 107 expect(helper.delta.addedAccessors, isEmpty);
108 expect(helper.delta.removedAccessors, isEmpty); 108 expect(helper.delta.removedAccessors, isEmpty);
109 expect(helper.delta.addedMethods, isEmpty); 109 expect(helper.delta.addedMethods, isEmpty);
110 expect(helper.delta.removedMethods, isEmpty); 110 expect(helper.delta.removedMethods, isEmpty);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 expect(nodeA, same(helper.oldMembers[0])); 224 expect(nodeA, same(helper.oldMembers[0]));
225 // elements 225 // elements
226 ConstructorElement elementA = nodeA.element; 226 ConstructorElement elementA = nodeA.element;
227 ConstructorElement elementB = nodeB.element; 227 ConstructorElement elementB = nodeB.element;
228 expect(elementA, isNotNull); 228 expect(elementA, isNotNull);
229 expect(elementB, isNotNull); 229 expect(elementB, isNotNull);
230 expect(elementA.name, 'a'); 230 expect(elementA.name, 'a');
231 expect(elementB.name, 'b'); 231 expect(elementB.name, 'b');
232 // classElement.constructors 232 // classElement.constructors
233 ClassElement classElement = helper.element; 233 ClassElement classElement = helper.element;
234 expect(classElement.constructors, unorderedEquals([elementA, elementB])); 234 expect(classElement.constructors, [elementA, elementB]);
235 // verify delta 235 // verify delta
236 expect(helper.delta.addedConstructors, unorderedEquals([elementB])); 236 expect(helper.delta.addedConstructors, unorderedEquals([elementB]));
237 expect(helper.delta.removedConstructors, unorderedEquals([])); 237 expect(helper.delta.removedConstructors, unorderedEquals([]));
238 expect(helper.delta.addedAccessors, isEmpty); 238 expect(helper.delta.addedAccessors, isEmpty);
239 expect(helper.delta.removedAccessors, isEmpty); 239 expect(helper.delta.removedAccessors, isEmpty);
240 expect(helper.delta.addedMethods, isEmpty); 240 expect(helper.delta.addedMethods, isEmpty);
241 expect(helper.delta.removedMethods, isEmpty); 241 expect(helper.delta.removedMethods, isEmpty);
242 } 242 }
243 243
244 test_classDelta_constructor_2to1() { 244 test_classDelta_constructor_2to1() {
(...skipping 15 matching lines...) Expand all
260 expect(helper.delta.hasUnnamedConstructorChange, isFalse); 260 expect(helper.delta.hasUnnamedConstructorChange, isFalse);
261 // nodes 261 // nodes
262 ClassMember nodeB = helper.newMembers[0]; 262 ClassMember nodeB = helper.newMembers[0];
263 expect(nodeB, same(helper.oldMembers[1])); 263 expect(nodeB, same(helper.oldMembers[1]));
264 // elements 264 // elements
265 ConstructorElement elementB = nodeB.element; 265 ConstructorElement elementB = nodeB.element;
266 expect(elementB, isNotNull); 266 expect(elementB, isNotNull);
267 expect(elementB.name, 'b'); 267 expect(elementB.name, 'b');
268 // classElement.constructors 268 // classElement.constructors
269 ClassElement classElement = helper.element; 269 ClassElement classElement = helper.element;
270 expect(classElement.constructors, unorderedEquals([elementB])); 270 expect(classElement.constructors, [elementB]);
271 // verify delta 271 // verify delta
272 expect(helper.delta.addedConstructors, unorderedEquals([])); 272 expect(helper.delta.addedConstructors, unorderedEquals([]));
273 expect(helper.delta.removedConstructors, unorderedEquals([oldElementA])); 273 expect(helper.delta.removedConstructors, unorderedEquals([oldElementA]));
274 expect(helper.delta.addedAccessors, isEmpty); 274 expect(helper.delta.addedAccessors, isEmpty);
275 expect(helper.delta.removedAccessors, isEmpty); 275 expect(helper.delta.removedAccessors, isEmpty);
276 expect(helper.delta.addedMethods, isEmpty); 276 expect(helper.delta.addedMethods, isEmpty);
277 expect(helper.delta.removedMethods, isEmpty); 277 expect(helper.delta.removedMethods, isEmpty);
278 } 278 }
279 279
280 test_classDelta_constructor_2to2_reorder() { 280 test_classDelta_constructor_2to2_reorder() {
(...skipping 19 matching lines...) Expand all
300 expect(nodeA, same(helper.oldMembers[0])); 300 expect(nodeA, same(helper.oldMembers[0]));
301 // elements 301 // elements
302 ConstructorElement elementB = nodeB.element; 302 ConstructorElement elementB = nodeB.element;
303 ConstructorElement elementA = nodeA.element; 303 ConstructorElement elementA = nodeA.element;
304 expect(elementB, isNotNull); 304 expect(elementB, isNotNull);
305 expect(elementA, isNotNull); 305 expect(elementA, isNotNull);
306 expect(elementB.name, 'b'); 306 expect(elementB.name, 'b');
307 expect(elementA.name, 'a'); 307 expect(elementA.name, 'a');
308 // classElement.constructors 308 // classElement.constructors
309 ClassElement classElement = helper.element; 309 ClassElement classElement = helper.element;
310 expect(classElement.constructors, unorderedEquals([elementB, elementA])); 310 expect(classElement.constructors, [elementB, elementA]);
311 // verify delta 311 // verify delta
312 expect(helper.delta.addedConstructors, isEmpty); 312 expect(helper.delta.addedConstructors, isEmpty);
313 expect(helper.delta.removedConstructors, isEmpty); 313 expect(helper.delta.removedConstructors, isEmpty);
314 expect(helper.delta.addedAccessors, isEmpty); 314 expect(helper.delta.addedAccessors, isEmpty);
315 expect(helper.delta.removedAccessors, isEmpty); 315 expect(helper.delta.removedAccessors, isEmpty);
316 expect(helper.delta.addedMethods, isEmpty); 316 expect(helper.delta.addedMethods, isEmpty);
317 expect(helper.delta.removedMethods, isEmpty); 317 expect(helper.delta.removedMethods, isEmpty);
318 } 318 }
319 319
320 test_classDelta_constructor_fieldReference_initializer() { 320 test_classDelta_constructor_fieldReference_initializer() {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 _buildNewUnit(r''' 456 _buildNewUnit(r'''
457 class A { 457 class A {
458 int aaa; 458 int aaa;
459 int bbb; 459 int bbb;
460 } 460 }
461 '''); 461 ''');
462 helper.initNew(newUnit, unitDelta); 462 helper.initNew(newUnit, unitDelta);
463 // nodes 463 // nodes
464 FieldDeclaration nodeA = helper.newMembers[0]; 464 FieldDeclaration nodeA = helper.newMembers[0];
465 FieldDeclaration newNodeB = helper.newMembers[1]; 465 FieldDeclaration newNodeB = helper.newMembers[1];
466 List<VariableDeclaration> fieldsA = nodeA.fields.variables;
466 List<VariableDeclaration> newFieldsB = newNodeB.fields.variables; 467 List<VariableDeclaration> newFieldsB = newNodeB.fields.variables;
467 expect(nodeA, same(helper.oldMembers[0])); 468 expect(nodeA, same(helper.oldMembers[0]));
468 expect(newFieldsB, hasLength(1)); 469 expect(newFieldsB, hasLength(1));
469 // elements 470 // elements
471 FieldElement fieldElementA = fieldsA[0].name.staticElement;
470 FieldElement newFieldElementB = newFieldsB[0].name.staticElement; 472 FieldElement newFieldElementB = newFieldsB[0].name.staticElement;
471 expect(newFieldElementB.name, 'bbb'); 473 expect(newFieldElementB.name, 'bbb');
474 // members
475 ClassElement classElement = helper.element;
476 expect(classElement.fields, [fieldElementA, newFieldElementB]);
472 // verify delta 477 // verify delta
473 expect(helper.delta.hasAnnotationChanges, isFalse); 478 expect(helper.delta.hasAnnotationChanges, isFalse);
474 expect(helper.delta.addedConstructors, isEmpty); 479 expect(helper.delta.addedConstructors, isEmpty);
475 expect(helper.delta.removedConstructors, isEmpty); 480 expect(helper.delta.removedConstructors, isEmpty);
476 expect(helper.delta.addedAccessors, 481 expect(helper.delta.addedAccessors,
477 unorderedEquals([newFieldElementB.getter, newFieldElementB.setter])); 482 unorderedEquals([newFieldElementB.getter, newFieldElementB.setter]));
478 expect(helper.delta.removedAccessors, isEmpty); 483 expect(helper.delta.removedAccessors, isEmpty);
479 expect(helper.delta.addedMethods, isEmpty); 484 expect(helper.delta.addedMethods, isEmpty);
480 expect(helper.delta.removedMethods, isEmpty); 485 expect(helper.delta.removedMethods, isEmpty);
481 } 486 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 helper.initNew(newUnit, unitDelta); 539 helper.initNew(newUnit, unitDelta);
535 // nodes 540 // nodes
536 FieldDeclaration newFieldDeclNode = helper.newMembers[0]; 541 FieldDeclaration newFieldDeclNode = helper.newMembers[0];
537 VariableDeclaration newFieldNode = newFieldDeclNode.fields.variables.single; 542 VariableDeclaration newFieldNode = newFieldDeclNode.fields.variables.single;
538 MethodDeclaration getterNode = helper.newMembers[1]; 543 MethodDeclaration getterNode = helper.newMembers[1];
539 expect(getterNode, same(helper.oldMembers[1])); 544 expect(getterNode, same(helper.oldMembers[1]));
540 // elements 545 // elements
541 FieldElement newFieldElement = newFieldNode.name.staticElement; 546 FieldElement newFieldElement = newFieldNode.name.staticElement;
542 PropertyAccessorElement getterElement = getterNode.element; 547 PropertyAccessorElement getterElement = getterNode.element;
543 expect(newFieldElement.name, '_foo'); 548 expect(newFieldElement.name, '_foo');
544 expect( 549 expect(helper.element.fields,
545 helper.element.fields, 550 [same(newFieldElement), same(getterElement.variable)]);
546 unorderedMatches( 551 expect(helper.element.accessors, [
547 [same(newFieldElement), same(getterElement.variable)])); 552 same(newFieldElement.getter),
548 expect( 553 same(newFieldElement.setter),
549 helper.element.accessors, 554 same(getterElement)
550 unorderedMatches([ 555 ]);
551 same(newFieldElement.getter),
552 same(newFieldElement.setter),
553 same(getterElement)
554 ]));
555 // verify delta 556 // verify delta
556 expect(helper.delta.addedConstructors, isEmpty); 557 expect(helper.delta.addedConstructors, isEmpty);
557 expect(helper.delta.removedConstructors, isEmpty); 558 expect(helper.delta.removedConstructors, isEmpty);
558 expect(helper.delta.addedAccessors, 559 expect(helper.delta.addedAccessors,
559 unorderedEquals([newFieldElement.getter, newFieldElement.setter])); 560 unorderedEquals([newFieldElement.getter, newFieldElement.setter]));
560 expect(helper.delta.removedAccessors, 561 expect(helper.delta.removedAccessors,
561 [oldFieldElement.getter, oldFieldElement.setter]); 562 [oldFieldElement.getter, oldFieldElement.setter]);
562 expect(helper.delta.addedMethods, isEmpty); 563 expect(helper.delta.addedMethods, isEmpty);
563 expect(helper.delta.removedMethods, isEmpty); 564 expect(helper.delta.removedMethods, isEmpty);
564 } 565 }
(...skipping 17 matching lines...) Expand all
582 MethodDeclaration nodeA = helper.oldMembers[0]; 583 MethodDeclaration nodeA = helper.oldMembers[0];
583 MethodDeclaration newNodeB = helper.newMembers[1]; 584 MethodDeclaration newNodeB = helper.newMembers[1];
584 expect(nodeA, same(helper.oldMembers[0])); 585 expect(nodeA, same(helper.oldMembers[0]));
585 // elements 586 // elements
586 PropertyAccessorElement elementA = nodeA.element; 587 PropertyAccessorElement elementA = nodeA.element;
587 PropertyAccessorElement newElementB = newNodeB.element; 588 PropertyAccessorElement newElementB = newNodeB.element;
588 expect(elementA, isNotNull); 589 expect(elementA, isNotNull);
589 expect(elementA.name, 'aaa'); 590 expect(elementA.name, 'aaa');
590 expect(newElementB, isNotNull); 591 expect(newElementB, isNotNull);
591 expect(newElementB.name, 'bbb'); 592 expect(newElementB.name, 'bbb');
593 expect(helper.element.accessors, [elementA, newElementB]);
592 // verify delta 594 // verify delta
593 expect(helper.delta.addedConstructors, isEmpty); 595 expect(helper.delta.addedConstructors, isEmpty);
594 expect(helper.delta.removedConstructors, isEmpty); 596 expect(helper.delta.removedConstructors, isEmpty);
595 expect(helper.delta.addedAccessors, unorderedEquals([newElementB])); 597 expect(helper.delta.addedAccessors, unorderedEquals([newElementB]));
596 expect(helper.delta.removedAccessors, isEmpty); 598 expect(helper.delta.removedAccessors, isEmpty);
597 expect(helper.delta.addedMethods, isEmpty); 599 expect(helper.delta.addedMethods, isEmpty);
598 expect(helper.delta.removedMethods, isEmpty); 600 expect(helper.delta.removedMethods, isEmpty);
599 } 601 }
600 602
601 test_classDelta_getter_remove() { 603 test_classDelta_getter_remove() {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 ClassMember nodeA = helper.oldMembers[0]; 652 ClassMember nodeA = helper.oldMembers[0];
651 ClassMember newNodeB = helper.newMembers[1]; 653 ClassMember newNodeB = helper.newMembers[1];
652 expect(nodeA, same(helper.oldMembers[0])); 654 expect(nodeA, same(helper.oldMembers[0]));
653 // elements 655 // elements
654 MethodElement elementA = nodeA.element; 656 MethodElement elementA = nodeA.element;
655 MethodElement newElementB = newNodeB.element; 657 MethodElement newElementB = newNodeB.element;
656 expect(elementA, isNotNull); 658 expect(elementA, isNotNull);
657 expect(elementA.name, 'aaa'); 659 expect(elementA.name, 'aaa');
658 expect(newElementB, isNotNull); 660 expect(newElementB, isNotNull);
659 expect(newElementB.name, 'bbb'); 661 expect(newElementB.name, 'bbb');
662 expect(helper.element.methods, [elementA, newElementB]);
660 // verify delta 663 // verify delta
661 expect(helper.delta.addedConstructors, isEmpty); 664 expect(helper.delta.addedConstructors, isEmpty);
662 expect(helper.delta.removedConstructors, isEmpty); 665 expect(helper.delta.removedConstructors, isEmpty);
663 expect(helper.delta.addedAccessors, isEmpty); 666 expect(helper.delta.addedAccessors, isEmpty);
664 expect(helper.delta.removedAccessors, isEmpty); 667 expect(helper.delta.removedAccessors, isEmpty);
665 expect(helper.delta.addedMethods, unorderedEquals([newElementB])); 668 expect(helper.delta.addedMethods, unorderedEquals([newElementB]));
666 expect(helper.delta.removedMethods, isEmpty); 669 expect(helper.delta.removedMethods, isEmpty);
667 } 670 }
668 671
669 test_classDelta_method_addParameter() { 672 test_classDelta_method_addParameter() {
(...skipping 21 matching lines...) Expand all
691 // elements 694 // elements
692 MethodElement oldElementA = oldNodeA.element; 695 MethodElement oldElementA = oldNodeA.element;
693 MethodElement newElementA = newNodeA.element; 696 MethodElement newElementA = newNodeA.element;
694 MethodElement elementB = nodeB.element; 697 MethodElement elementB = nodeB.element;
695 expect(newElementA, isNotNull); 698 expect(newElementA, isNotNull);
696 expect(newElementA.name, 'aaa'); 699 expect(newElementA.name, 'aaa');
697 expect(oldElementA.parameters, hasLength(0)); 700 expect(oldElementA.parameters, hasLength(0));
698 expect(newElementA.parameters, hasLength(1)); 701 expect(newElementA.parameters, hasLength(1));
699 expect(elementB, isNotNull); 702 expect(elementB, isNotNull);
700 expect(elementB.name, 'bbb'); 703 expect(elementB.name, 'bbb');
704 expect(helper.element.methods, [newElementA, elementB]);
701 // verify delta 705 // verify delta
702 expect(helper.delta.addedConstructors, isEmpty); 706 expect(helper.delta.addedConstructors, isEmpty);
703 expect(helper.delta.removedConstructors, isEmpty); 707 expect(helper.delta.removedConstructors, isEmpty);
704 expect(helper.delta.addedAccessors, isEmpty); 708 expect(helper.delta.addedAccessors, isEmpty);
705 expect(helper.delta.removedAccessors, isEmpty); 709 expect(helper.delta.removedAccessors, isEmpty);
706 expect(helper.delta.addedMethods, unorderedEquals([newElementA])); 710 expect(helper.delta.addedMethods, unorderedEquals([newElementA]));
707 expect(helper.delta.removedMethods, unorderedEquals([oldElementA])); 711 expect(helper.delta.removedMethods, unorderedEquals([oldElementA]));
708 } 712 }
709 713
710 test_classDelta_method_changeName() { 714 test_classDelta_method_changeName() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ClassMember nodeB = helper.newMembers[1]; 747 ClassMember nodeB = helper.newMembers[1];
744 expect(nodeB, same(helper.oldMembers[1])); 748 expect(nodeB, same(helper.oldMembers[1]));
745 // elements 749 // elements
746 MethodElement oldElementA = oldNodeA.element; 750 MethodElement oldElementA = oldNodeA.element;
747 MethodElement newElementA = newNodeA.element; 751 MethodElement newElementA = newNodeA.element;
748 MethodElement elementB = nodeB.element; 752 MethodElement elementB = nodeB.element;
749 expect(newElementA, isNotNull); 753 expect(newElementA, isNotNull);
750 expect(newElementA.name, 'aaa2'); 754 expect(newElementA.name, 'aaa2');
751 expect(elementB, isNotNull); 755 expect(elementB, isNotNull);
752 expect(elementB.name, 'bbb'); 756 expect(elementB.name, 'bbb');
757 expect(helper.element.methods, [newElementA, elementB]);
753 // verify delta 758 // verify delta
754 expect(helper.delta.addedConstructors, isEmpty); 759 expect(helper.delta.addedConstructors, isEmpty);
755 expect(helper.delta.removedConstructors, isEmpty); 760 expect(helper.delta.removedConstructors, isEmpty);
756 expect(helper.delta.addedAccessors, isEmpty); 761 expect(helper.delta.addedAccessors, isEmpty);
757 expect(helper.delta.removedAccessors, isEmpty); 762 expect(helper.delta.removedAccessors, isEmpty);
758 expect(helper.delta.addedMethods, unorderedEquals([newElementA])); 763 expect(helper.delta.addedMethods, unorderedEquals([newElementA]));
759 expect(helper.delta.removedMethods, unorderedEquals([oldElementA])); 764 expect(helper.delta.removedMethods, unorderedEquals([oldElementA]));
760 } 765 }
761 766
762 test_classDelta_method_remove() { 767 test_classDelta_method_remove() {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 // elements 822 // elements
818 MethodElement oldElementA = oldNodeA.element; 823 MethodElement oldElementA = oldNodeA.element;
819 MethodElement newElementA = newNodeA.element; 824 MethodElement newElementA = newNodeA.element;
820 MethodElement elementB = nodeB.element; 825 MethodElement elementB = nodeB.element;
821 expect(newElementA, isNotNull); 826 expect(newElementA, isNotNull);
822 expect(newElementA.name, 'aaa'); 827 expect(newElementA.name, 'aaa');
823 expect(oldElementA.parameters, hasLength(1)); 828 expect(oldElementA.parameters, hasLength(1));
824 expect(newElementA.parameters, hasLength(0)); 829 expect(newElementA.parameters, hasLength(0));
825 expect(elementB, isNotNull); 830 expect(elementB, isNotNull);
826 expect(elementB.name, 'bbb'); 831 expect(elementB.name, 'bbb');
832 expect(helper.element.methods, [newElementA, elementB]);
827 // verify delta 833 // verify delta
828 expect(helper.delta.addedConstructors, isEmpty); 834 expect(helper.delta.addedConstructors, isEmpty);
829 expect(helper.delta.removedConstructors, isEmpty); 835 expect(helper.delta.removedConstructors, isEmpty);
830 expect(helper.delta.addedAccessors, isEmpty); 836 expect(helper.delta.addedAccessors, isEmpty);
831 expect(helper.delta.removedAccessors, isEmpty); 837 expect(helper.delta.removedAccessors, isEmpty);
832 expect(helper.delta.addedMethods, unorderedEquals([newElementA])); 838 expect(helper.delta.addedMethods, unorderedEquals([newElementA]));
833 expect(helper.delta.removedMethods, unorderedEquals([oldElementA])); 839 expect(helper.delta.removedMethods, unorderedEquals([oldElementA]));
834 } 840 }
835 841
842 test_classDelta_newOrder() {
843 var helper = new _ClassDeltaHelper('A');
844 _buildOldUnit(r'''
845 class A {
846 bbb() {}
847 }
848 ''');
849 helper.initOld(oldUnit);
850 _buildNewUnit(r'''
851 class A {
852 aaa() {}
853 bbb() {}
854 ccc() {}
855 }
856 ''');
857 helper.initNew(newUnit, unitDelta);
858 // nodes
859 ClassMember newNodeA = helper.newMembers[0];
860 ClassMember nodeB = helper.oldMembers[0];
861 ClassMember newNodeC = helper.newMembers[2];
862 expect(nodeB, same(helper.oldMembers[0]));
863 // elements
864 MethodElement newElementA = newNodeA.element;
865 MethodElement elementB = nodeB.element;
866 MethodElement newElementC = newNodeC.element;
867 expect(newElementA, isNotNull);
868 expect(newElementA.name, 'aaa');
869 expect(elementB, isNotNull);
870 expect(elementB.name, 'bbb');
871 expect(newElementC, isNotNull);
872 expect(newElementC.name, 'ccc');
873 expect(helper.element.methods, [newElementA, elementB, newElementC]);
874 // verify delta
875 expect(helper.delta.addedConstructors, isEmpty);
876 expect(helper.delta.removedConstructors, isEmpty);
877 expect(helper.delta.addedAccessors, isEmpty);
878 expect(helper.delta.removedAccessors, isEmpty);
879 expect(
880 helper.delta.addedMethods, unorderedEquals([newElementA, newElementC]));
881 expect(helper.delta.removedMethods, isEmpty);
882 }
883
836 test_classDelta_null_abstractKeyword_add() { 884 test_classDelta_null_abstractKeyword_add() {
837 _verifyNoClassDeltaForTheLast( 885 _verifyNoClassDeltaForTheLast(
838 r''' 886 r'''
839 class A {} 887 class A {}
840 ''', 888 ''',
841 r''' 889 r'''
842 abstract class A {} 890 abstract class A {}
843 '''); 891 ''');
844 } 892 }
845 893
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 MethodDeclaration nodeA = helper.oldMembers[0]; 1068 MethodDeclaration nodeA = helper.oldMembers[0];
1021 MethodDeclaration newNodeB = helper.newMembers[1]; 1069 MethodDeclaration newNodeB = helper.newMembers[1];
1022 expect(nodeA, same(helper.oldMembers[0])); 1070 expect(nodeA, same(helper.oldMembers[0]));
1023 // elements 1071 // elements
1024 PropertyAccessorElement elementA = nodeA.element; 1072 PropertyAccessorElement elementA = nodeA.element;
1025 PropertyAccessorElement newElementB = newNodeB.element; 1073 PropertyAccessorElement newElementB = newNodeB.element;
1026 expect(elementA, isNotNull); 1074 expect(elementA, isNotNull);
1027 expect(elementA.name, 'aaa='); 1075 expect(elementA.name, 'aaa=');
1028 expect(newElementB, isNotNull); 1076 expect(newElementB, isNotNull);
1029 expect(newElementB.name, 'bbb='); 1077 expect(newElementB.name, 'bbb=');
1078 expect(helper.element.accessors, [elementA, newElementB]);
1030 // verify delta 1079 // verify delta
1031 expect(helper.delta.addedConstructors, isEmpty); 1080 expect(helper.delta.addedConstructors, isEmpty);
1032 expect(helper.delta.removedConstructors, isEmpty); 1081 expect(helper.delta.removedConstructors, isEmpty);
1033 expect(helper.delta.addedAccessors, unorderedEquals([newElementB])); 1082 expect(helper.delta.addedAccessors, unorderedEquals([newElementB]));
1034 expect(helper.delta.removedAccessors, isEmpty); 1083 expect(helper.delta.removedAccessors, isEmpty);
1035 expect(helper.delta.addedMethods, isEmpty); 1084 expect(helper.delta.addedMethods, isEmpty);
1036 expect(helper.delta.removedMethods, isEmpty); 1085 expect(helper.delta.removedMethods, isEmpty);
1037 } 1086 }
1038 1087
1039 test_classDelta_setter_remove() { 1088 test_classDelta_setter_remove() {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 FunctionDeclaration node2 = newNodes[1]; 1416 FunctionDeclaration node2 = newNodes[1];
1368 expect(node1, same(oldNodes[0])); 1417 expect(node1, same(oldNodes[0]));
1369 // elements 1418 // elements
1370 PropertyAccessorElement elementA = node1.element; 1419 PropertyAccessorElement elementA = node1.element;
1371 PropertyAccessorElement elementB = node2.element; 1420 PropertyAccessorElement elementB = node2.element;
1372 expect(elementA, isNotNull); 1421 expect(elementA, isNotNull);
1373 expect(elementB, isNotNull); 1422 expect(elementB, isNotNull);
1374 expect(elementA.name, 'a'); 1423 expect(elementA.name, 'a');
1375 expect(elementB.name, 'b'); 1424 expect(elementB.name, 'b');
1376 // unit.types 1425 // unit.types
1377 expect(unitElement.topLevelVariables, 1426 expect(
1378 unorderedEquals([elementA.variable, elementB.variable])); 1427 unitElement.topLevelVariables, [elementA.variable, elementB.variable]);
1379 expect(unitElement.accessors, unorderedEquals([elementA, elementB])); 1428 expect(unitElement.accessors, [elementA, elementB]);
1380 } 1429 }
1381 1430
1382 test_unitMembers_class_add() { 1431 test_unitMembers_class_add() {
1383 _buildOldUnit(r''' 1432 _buildOldUnit(r'''
1384 class A {} 1433 class A {}
1385 '''); 1434 ''');
1386 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); 1435 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1387 _buildNewUnit(r''' 1436 _buildNewUnit(r'''
1388 class A {} 1437 class A {}
1389 class B {} 1438 class B {}
1390 '''); 1439 ''');
1391 List<CompilationUnitMember> newNodes = newUnit.declarations; 1440 List<CompilationUnitMember> newNodes = newUnit.declarations;
1392 // nodes 1441 // nodes
1393 CompilationUnitMember nodeA = newNodes[0]; 1442 CompilationUnitMember nodeA = newNodes[0];
1394 CompilationUnitMember nodeB = newNodes[1]; 1443 CompilationUnitMember nodeB = newNodes[1];
1395 expect(nodeA, same(oldNodes[0])); 1444 expect(nodeA, same(oldNodes[0]));
1396 // elements 1445 // elements
1397 ClassElement elementA = nodeA.element; 1446 ClassElement elementA = nodeA.element;
1398 ClassElement elementB = nodeB.element; 1447 ClassElement elementB = nodeB.element;
1399 expect(elementA, isNotNull); 1448 expect(elementA, isNotNull);
1400 expect(elementB, isNotNull); 1449 expect(elementB, isNotNull);
1401 expect(elementA.name, 'A'); 1450 expect(elementA.name, 'A');
1402 expect(elementB.name, 'B'); 1451 expect(elementB.name, 'B');
1403 // unit.types 1452 // unit.types
1404 expect(unitElement.types, unorderedEquals([elementA, elementB])); 1453 expect(unitElement.types, [elementA, elementB]);
1405 // verify delta 1454 // verify delta
1406 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); 1455 expect(unitDelta.addedDeclarations, unorderedEquals([elementB]));
1407 expect(unitDelta.removedDeclarations, unorderedEquals([])); 1456 expect(unitDelta.removedDeclarations, unorderedEquals([]));
1408 } 1457 }
1409 1458
1410 test_unitMembers_class_comments() { 1459 test_unitMembers_class_comments() {
1411 _buildOldUnit(r''' 1460 _buildOldUnit(r'''
1412 /// reference [bool] type. 1461 /// reference [bool] type.
1413 class A {} 1462 class A {}
1414 /// reference [int] type. 1463 /// reference [int] type.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 CompilationUnitMember nodeB = oldNodes[1]; 1554 CompilationUnitMember nodeB = oldNodes[1];
1506 expect(nodeA, same(oldNodes[0])); 1555 expect(nodeA, same(oldNodes[0]));
1507 // elements 1556 // elements
1508 ClassElement elementA = nodeA.element; 1557 ClassElement elementA = nodeA.element;
1509 ClassElement elementB = nodeB.element; 1558 ClassElement elementB = nodeB.element;
1510 expect(elementA, isNotNull); 1559 expect(elementA, isNotNull);
1511 expect(elementB, isNotNull); 1560 expect(elementB, isNotNull);
1512 expect(elementA.name, 'A'); 1561 expect(elementA.name, 'A');
1513 expect(elementB.name, 'B'); 1562 expect(elementB.name, 'B');
1514 // unit.types 1563 // unit.types
1515 expect(unitElement.types, unorderedEquals([elementA])); 1564 expect(unitElement.types, [elementA]);
1516 // verify delta 1565 // verify delta
1517 expect(unitDelta.addedDeclarations, unorderedEquals([])); 1566 expect(unitDelta.addedDeclarations, unorderedEquals([]));
1518 expect(unitDelta.removedDeclarations, unorderedEquals([elementB])); 1567 expect(unitDelta.removedDeclarations, unorderedEquals([elementB]));
1519 } 1568 }
1520 1569
1521 test_unitMembers_class_reorder() { 1570 test_unitMembers_class_reorder() {
1522 _buildOldUnit(r''' 1571 _buildOldUnit(r'''
1523 class A {} 1572 class A {}
1524 class B {} 1573 class B {}
1525 class C {} 1574 class C {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1586 expect(elementB.name, 'B'); 1635 expect(elementB.name, 'B');
1587 expect(elementA.fields.map((f) => f.name), 1636 expect(elementA.fields.map((f) => f.name),
1588 unorderedEquals(['index', 'values', 'A1', 'A2'])); 1637 unorderedEquals(['index', 'values', 'A1', 'A2']));
1589 expect(elementA.accessors.map((a) => a.name), 1638 expect(elementA.accessors.map((a) => a.name),
1590 unorderedEquals(['index', 'values', 'A1', 'A2'])); 1639 unorderedEquals(['index', 'values', 'A1', 'A2']));
1591 expect(elementB.fields.map((f) => f.name), 1640 expect(elementB.fields.map((f) => f.name),
1592 unorderedEquals(['index', 'values', 'B1', 'B2'])); 1641 unorderedEquals(['index', 'values', 'B1', 'B2']));
1593 expect(elementB.accessors.map((a) => a.name), 1642 expect(elementB.accessors.map((a) => a.name),
1594 unorderedEquals(['index', 'values', 'B1', 'B2'])); 1643 unorderedEquals(['index', 'values', 'B1', 'B2']));
1595 // unit.types 1644 // unit.types
1596 expect(unitElement.enums, unorderedEquals([elementA, elementB])); 1645 expect(unitElement.enums, [elementA, elementB]);
1597 // verify delta 1646 // verify delta
1598 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); 1647 expect(unitDelta.addedDeclarations, unorderedEquals([elementB]));
1599 expect(unitDelta.removedDeclarations, unorderedEquals([])); 1648 expect(unitDelta.removedDeclarations, unorderedEquals([]));
1600 } 1649 }
1601 1650
1602 test_unitMembers_function_add() { 1651 test_unitMembers_function_add() {
1603 _buildOldUnit(r''' 1652 _buildOldUnit(r'''
1604 a() {} 1653 a() {}
1605 '''); 1654 ''');
1606 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); 1655 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1607 _buildNewUnit(r''' 1656 _buildNewUnit(r'''
1608 a() {} 1657 a() {}
1609 b() {} 1658 b() {}
1610 '''); 1659 ''');
1611 List<CompilationUnitMember> newNodes = newUnit.declarations; 1660 List<CompilationUnitMember> newNodes = newUnit.declarations;
1612 // nodes 1661 // nodes
1613 CompilationUnitMember nodeA = newNodes[0]; 1662 CompilationUnitMember nodeA = newNodes[0];
1614 CompilationUnitMember nodeB = newNodes[1]; 1663 CompilationUnitMember nodeB = newNodes[1];
1615 expect(nodeA, same(oldNodes[0])); 1664 expect(nodeA, same(oldNodes[0]));
1616 // elements 1665 // elements
1617 FunctionElement elementA = nodeA.element; 1666 FunctionElement elementA = nodeA.element;
1618 FunctionElement elementB = nodeB.element; 1667 FunctionElement elementB = nodeB.element;
1619 expect(elementA, isNotNull); 1668 expect(elementA, isNotNull);
1620 expect(elementB, isNotNull); 1669 expect(elementB, isNotNull);
1621 expect(elementA.name, 'a'); 1670 expect(elementA.name, 'a');
1622 expect(elementB.name, 'b'); 1671 expect(elementB.name, 'b');
1623 // unit.types 1672 // unit.types
1624 expect(unitElement.functions, unorderedEquals([elementA, elementB])); 1673 expect(unitElement.functions, [elementA, elementB]);
1625 // verify delta 1674 // verify delta
1626 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); 1675 expect(unitDelta.addedDeclarations, unorderedEquals([elementB]));
1627 expect(unitDelta.removedDeclarations, unorderedEquals([])); 1676 expect(unitDelta.removedDeclarations, unorderedEquals([]));
1628 } 1677 }
1629 1678
1630 test_unitMembers_functionTypeAlias_add() { 1679 test_unitMembers_functionTypeAlias_add() {
1631 _buildOldUnit(r''' 1680 _buildOldUnit(r'''
1632 typedef A(); 1681 typedef A();
1633 '''); 1682 ''');
1634 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); 1683 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1635 _buildNewUnit(r''' 1684 _buildNewUnit(r'''
1636 typedef A(); 1685 typedef A();
1637 typedef B(); 1686 typedef B();
1638 '''); 1687 ''');
1639 List<CompilationUnitMember> newNodes = newUnit.declarations; 1688 List<CompilationUnitMember> newNodes = newUnit.declarations;
1640 // nodes 1689 // nodes
1641 CompilationUnitMember nodeA = newNodes[0]; 1690 CompilationUnitMember nodeA = newNodes[0];
1642 CompilationUnitMember nodeB = newNodes[1]; 1691 CompilationUnitMember nodeB = newNodes[1];
1643 expect(nodeA, same(oldNodes[0])); 1692 expect(nodeA, same(oldNodes[0]));
1644 // elements 1693 // elements
1645 FunctionTypeAliasElement elementA = nodeA.element; 1694 FunctionTypeAliasElement elementA = nodeA.element;
1646 FunctionTypeAliasElement elementB = nodeB.element; 1695 FunctionTypeAliasElement elementB = nodeB.element;
1647 expect(elementA, isNotNull); 1696 expect(elementA, isNotNull);
1648 expect(elementB, isNotNull); 1697 expect(elementB, isNotNull);
1649 expect(elementA.name, 'A'); 1698 expect(elementA.name, 'A');
1650 expect(elementB.name, 'B'); 1699 expect(elementB.name, 'B');
1651 // unit.types 1700 // unit.types
1652 expect( 1701 expect(unitElement.functionTypeAliases, [elementA, elementB]);
1653 unitElement.functionTypeAliases, unorderedEquals([elementA, elementB]));
1654 // verify delta 1702 // verify delta
1655 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); 1703 expect(unitDelta.addedDeclarations, unorderedEquals([elementB]));
1656 expect(unitDelta.removedDeclarations, unorderedEquals([])); 1704 expect(unitDelta.removedDeclarations, unorderedEquals([]));
1657 } 1705 }
1658 1706
1707 test_unitMembers_newOrder() {
1708 _buildOldUnit(r'''
1709 int b;
1710 ''');
1711 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1712 _buildNewUnit(r'''
1713 int a;
1714 int b;
1715 int c;
1716 ''');
1717 List<CompilationUnitMember> newNodes = newUnit.declarations;
1718 // nodes
1719 TopLevelVariableDeclaration node1 = newNodes[0];
1720 TopLevelVariableDeclaration node2 = newNodes[1];
1721 TopLevelVariableDeclaration node3 = newNodes[2];
1722 expect(node2, same(oldNodes[0]));
1723 // elements
1724 TopLevelVariableElement elementA = node1.variables.variables[0].element;
1725 TopLevelVariableElement elementB = node2.variables.variables[0].element;
1726 TopLevelVariableElement elementC = node3.variables.variables[0].element;
1727 expect(elementA, isNotNull);
1728 expect(elementB, isNotNull);
1729 expect(elementC, isNotNull);
1730 expect(elementA.name, 'a');
1731 expect(elementB.name, 'b');
1732 expect(elementC.name, 'c');
1733 // unit.types
1734 expect(unitElement.topLevelVariables, [elementA, elementB, elementC]);
1735 expect(unitElement.accessors, [
1736 elementA.getter,
1737 elementA.setter,
1738 elementB.getter,
1739 elementB.setter,
1740 elementC.getter,
1741 elementC.setter,
1742 ]);
1743 }
1744
1659 test_unitMembers_topLevelVariable() { 1745 test_unitMembers_topLevelVariable() {
1660 _buildOldUnit(r''' 1746 _buildOldUnit(r'''
1661 bool a = 1, b = 2; 1747 bool a = 1, b = 2;
1662 int c = 3; 1748 int c = 3;
1663 '''); 1749 ''');
1664 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); 1750 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1665 _buildNewUnit(r''' 1751 _buildNewUnit(r'''
1666 int c = 3; 1752 int c = 3;
1667 1753
1668 bool a =1, b = 2; 1754 bool a =1, b = 2;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 expect(elementA, isNotNull); 1812 expect(elementA, isNotNull);
1727 expect(elementB, isNotNull); 1813 expect(elementB, isNotNull);
1728 expect(elementC, isNotNull); 1814 expect(elementC, isNotNull);
1729 expect(elementD, isNotNull); 1815 expect(elementD, isNotNull);
1730 expect(elementA.name, 'a'); 1816 expect(elementA.name, 'a');
1731 expect(elementB.name, 'b'); 1817 expect(elementB.name, 'b');
1732 expect(elementC.name, 'c'); 1818 expect(elementC.name, 'c');
1733 expect(elementD.name, 'd'); 1819 expect(elementD.name, 'd');
1734 // unit.types 1820 // unit.types
1735 expect(unitElement.topLevelVariables, 1821 expect(unitElement.topLevelVariables,
1736 unorderedEquals([elementA, elementB, elementC, elementD])); 1822 [elementA, elementB, elementC, elementD]);
1737 expect( 1823 expect(unitElement.accessors, [
1738 unitElement.accessors, 1824 elementA.getter,
1739 unorderedEquals([ 1825 elementA.setter,
1740 elementA.getter, 1826 elementB.getter,
1741 elementA.setter, 1827 elementB.setter,
1742 elementB.getter, 1828 elementC.getter,
1743 elementB.setter, 1829 elementC.setter,
1744 elementC.getter, 1830 elementD.getter,
1745 elementC.setter, 1831 elementD.setter
1746 elementD.getter, 1832 ]);
1747 elementD.setter
1748 ]));
1749 } 1833 }
1750 1834
1751 test_unitMembers_topLevelVariable_final() { 1835 test_unitMembers_topLevelVariable_final() {
1752 _buildOldUnit(r''' 1836 _buildOldUnit(r'''
1753 final int a = 1; 1837 final int a = 1;
1754 '''); 1838 ''');
1755 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); 1839 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList();
1756 _buildNewUnit(r''' 1840 _buildNewUnit(r'''
1757 final int a = 1; 1841 final int a = 1;
1758 '''); 1842 ''');
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
2219 unitMember is ClassDeclaration && unitMember.name.name == name); 2303 unitMember is ClassDeclaration && unitMember.name.name == name);
2220 } 2304 }
2221 2305
2222 class _MaterializeLazyElementsVisitor extends GeneralizingElementVisitor { 2306 class _MaterializeLazyElementsVisitor extends GeneralizingElementVisitor {
2223 @override 2307 @override
2224 visitExecutableElement(ExecutableElement element) { 2308 visitExecutableElement(ExecutableElement element) {
2225 element.parameters; 2309 element.parameters;
2226 super.visitExecutableElement(element); 2310 super.visitExecutableElement(element);
2227 } 2311 }
2228 } 2312 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698