OLD | NEW |
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 test.src.task.incremental_element_builder_test; | 5 library test.src.task.incremental_element_builder_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:analyzer/src/task/incremental_element_builder.dart'; | 10 import 'package:analyzer/src/task/incremental_element_builder.dart'; |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 expect(elementA.name, 'A'); | 536 expect(elementA.name, 'A'); |
537 expect(elementB.name, 'B'); | 537 expect(elementB.name, 'B'); |
538 // unit.types | 538 // unit.types |
539 expect( | 539 expect( |
540 unitElement.functionTypeAliases, unorderedEquals([elementA, elementB])); | 540 unitElement.functionTypeAliases, unorderedEquals([elementA, elementB])); |
541 // verify delta | 541 // verify delta |
542 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); | 542 expect(unitDelta.addedDeclarations, unorderedEquals([elementB])); |
543 expect(unitDelta.removedDeclarations, unorderedEquals([])); | 543 expect(unitDelta.removedDeclarations, unorderedEquals([])); |
544 } | 544 } |
545 | 545 |
| 546 test_unitMembers_topLevelVariable() { |
| 547 _buildOldUnit(r''' |
| 548 bool a = 1, b = 2; |
| 549 int c = 3; |
| 550 '''); |
| 551 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); |
| 552 _buildNewUnit(r''' |
| 553 int c = 3; |
| 554 |
| 555 bool a =1, b = 2; |
| 556 '''); |
| 557 List<CompilationUnitMember> newNodes = newUnit.declarations; |
| 558 { |
| 559 TopLevelVariableDeclaration newNode = newNodes[0]; |
| 560 expect(newNode, same(oldNodes[1])); |
| 561 expect(getNodeText(newNode), 'int c = 3;'); |
| 562 { |
| 563 TopLevelVariableElement element = |
| 564 newNode.variables.variables[0].element; |
| 565 expect(element, isNotNull); |
| 566 expect(element.name, 'c'); |
| 567 expect(element.nameOffset, newCode.indexOf('c = 3')); |
| 568 } |
| 569 } |
| 570 { |
| 571 TopLevelVariableDeclaration newNode = newNodes[1]; |
| 572 expect(newNode, same(oldNodes[0])); |
| 573 expect(getNodeText(newNode), 'bool a =1, b = 2;'); |
| 574 { |
| 575 TopLevelVariableElement element = |
| 576 newNode.variables.variables[0].element; |
| 577 expect(element, isNotNull); |
| 578 expect(element.name, 'a'); |
| 579 expect(element.nameOffset, newCode.indexOf('a =1')); |
| 580 } |
| 581 { |
| 582 TopLevelVariableElement element = |
| 583 newNode.variables.variables[1].element; |
| 584 expect(element, isNotNull); |
| 585 expect(element.name, 'b'); |
| 586 expect(element.nameOffset, newCode.indexOf('b = 2')); |
| 587 } |
| 588 } |
| 589 // verify delta |
| 590 expect(unitDelta.addedDeclarations, unorderedEquals([])); |
| 591 expect(unitDelta.removedDeclarations, unorderedEquals([])); |
| 592 } |
| 593 |
546 test_unitMembers_topLevelVariable_add() { | 594 test_unitMembers_topLevelVariable_add() { |
547 _buildOldUnit(r''' | 595 _buildOldUnit(r''' |
548 int a, b; | 596 int a, b; |
549 '''); | 597 '''); |
550 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); | 598 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); |
551 _buildNewUnit(r''' | 599 _buildNewUnit(r''' |
552 int a, b; | 600 int a, b; |
553 int c, d; | 601 int c, d; |
554 '''); | 602 '''); |
555 List<CompilationUnitMember> newNodes = newUnit.declarations; | 603 List<CompilationUnitMember> newNodes = newUnit.declarations; |
(...skipping 22 matching lines...) Expand all Loading... |
578 elementA.setter, | 626 elementA.setter, |
579 elementB.getter, | 627 elementB.getter, |
580 elementB.setter, | 628 elementB.setter, |
581 elementC.getter, | 629 elementC.getter, |
582 elementC.setter, | 630 elementC.setter, |
583 elementD.getter, | 631 elementD.getter, |
584 elementD.setter | 632 elementD.setter |
585 ])); | 633 ])); |
586 } | 634 } |
587 | 635 |
588 test_unitMembers_topLevelVariableDeclaration() { | 636 test_unitMembers_topLevelVariable_final() { |
589 _buildOldUnit(r''' | 637 _buildOldUnit(r''' |
590 bool a = 1, b = 2; | 638 final int a = 1; |
591 int c = 3; | |
592 '''); | 639 '''); |
593 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); | 640 List<CompilationUnitMember> oldNodes = oldUnit.declarations.toList(); |
594 _buildNewUnit(r''' | 641 _buildNewUnit(r''' |
595 int c = 3; | 642 final int a = 1; |
596 | |
597 bool a =1, b = 2; | |
598 '''); | 643 '''); |
599 List<CompilationUnitMember> newNodes = newUnit.declarations; | 644 List<CompilationUnitMember> newNodes = newUnit.declarations; |
600 { | 645 { |
601 TopLevelVariableDeclaration newNode = newNodes[0]; | 646 TopLevelVariableDeclaration newNode = newNodes[0]; |
602 expect(newNode, same(oldNodes[1])); | |
603 expect(getNodeText(newNode), 'int c = 3;'); | |
604 { | |
605 TopLevelVariableElement element = | |
606 newNode.variables.variables[0].element; | |
607 expect(element, isNotNull); | |
608 expect(element.name, 'c'); | |
609 expect(element.nameOffset, newCode.indexOf('c = 3')); | |
610 } | |
611 } | |
612 { | |
613 TopLevelVariableDeclaration newNode = newNodes[1]; | |
614 expect(newNode, same(oldNodes[0])); | 647 expect(newNode, same(oldNodes[0])); |
615 expect(getNodeText(newNode), 'bool a =1, b = 2;'); | 648 expect(getNodeText(newNode), 'final int a = 1;'); |
616 { | 649 { |
617 TopLevelVariableElement element = | 650 TopLevelVariableElement element = |
618 newNode.variables.variables[0].element; | 651 newNode.variables.variables[0].element; |
619 expect(element, isNotNull); | 652 expect(element, isNotNull); |
620 expect(element.name, 'a'); | 653 expect(element.name, 'a'); |
621 expect(element.nameOffset, newCode.indexOf('a =1')); | 654 expect(element.nameOffset, newCode.indexOf('a = 1')); |
622 } | |
623 { | |
624 TopLevelVariableElement element = | |
625 newNode.variables.variables[1].element; | |
626 expect(element, isNotNull); | |
627 expect(element.name, 'b'); | |
628 expect(element.nameOffset, newCode.indexOf('b = 2')); | |
629 } | 655 } |
630 } | 656 } |
631 // verify delta | 657 // verify delta |
632 expect(unitDelta.addedDeclarations, unorderedEquals([])); | 658 expect(unitDelta.addedDeclarations, unorderedEquals([])); |
633 expect(unitDelta.removedDeclarations, unorderedEquals([])); | 659 expect(unitDelta.removedDeclarations, unorderedEquals([])); |
634 } | 660 } |
635 | 661 |
636 void _buildNewUnit(String newCode) { | 662 void _buildNewUnit(String newCode) { |
637 this.newCode = newCode; | 663 this.newCode = newCode; |
638 context.setContents(source, newCode); | 664 context.setContents(source, newCode); |
639 newUnit = context.parseCompilationUnit(source); | 665 newUnit = context.parseCompilationUnit(source); |
640 IncrementalCompilationUnitElementBuilder builder = | 666 IncrementalCompilationUnitElementBuilder builder = |
641 new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit); | 667 new IncrementalCompilationUnitElementBuilder(oldUnit, newUnit); |
642 builder.build(); | 668 builder.build(); |
643 unitDelta = builder.unitDelta; | 669 unitDelta = builder.unitDelta; |
644 expect(newUnit.element, unitElement); | 670 expect(newUnit.element, unitElement); |
645 } | 671 } |
646 | 672 |
647 void _buildOldUnit(String oldCode, [Source libSource]) { | 673 void _buildOldUnit(String oldCode, [Source libSource]) { |
648 this.oldCode = oldCode; | 674 this.oldCode = oldCode; |
649 source = newSource('/test.dart', oldCode); | 675 source = newSource('/test.dart', oldCode); |
650 if (libSource == null) { | 676 if (libSource == null) { |
651 libSource = source; | 677 libSource = source; |
652 } | 678 } |
653 oldUnit = context.resolveCompilationUnit2(source, libSource); | 679 oldUnit = context.resolveCompilationUnit2(source, libSource); |
654 unitElement = oldUnit.element; | 680 unitElement = oldUnit.element; |
655 expect(unitElement, isNotNull); | 681 expect(unitElement, isNotNull); |
656 } | 682 } |
657 } | 683 } |
OLD | NEW |