| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.dart.ast.utilities_test; | 5 library analyzer.test.src.dart.ast.utilities_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/dart/ast/utilities.dart'; | 11 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 12 import 'package:analyzer/src/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 13 import 'package:analyzer/src/generated/java_core.dart'; |
| 11 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; | 14 import 'package:analyzer/src/generated/java_engine.dart' show Predicate; |
| 12 import 'package:analyzer/src/generated/java_engine.dart'; | 15 import 'package:analyzer/src/generated/java_engine.dart'; |
| 13 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 16 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 17 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 14 import 'package:analyzer/src/generated/testing/token_factory.dart'; | 18 import 'package:analyzer/src/generated/testing/token_factory.dart'; |
| 15 import 'package:unittest/unittest.dart'; | 19 import 'package:unittest/unittest.dart'; |
| 16 | 20 |
| 17 import '../../../generated/parser_test.dart' show ParserTestCase; | 21 import '../../../generated/parser_test.dart' show ParserTestCase; |
| 18 import '../../../generated/test_support.dart'; | 22 import '../../../generated/test_support.dart'; |
| 19 import '../../../reflective_tests.dart'; | 23 import '../../../reflective_tests.dart'; |
| 20 import '../../../utils.dart'; | 24 import '../../../utils.dart'; |
| 21 | 25 |
| 22 main() { | 26 main() { |
| 23 initializeTestEnvironment(); | 27 initializeTestEnvironment(); |
| 24 runReflectiveTests(ConstantEvaluatorTest); | 28 runReflectiveTests(ConstantEvaluatorTest); |
| 25 runReflectiveTests(NodeLocatorTest); | 29 runReflectiveTests(NodeLocatorTest); |
| 26 runReflectiveTests(NodeLocator2Test); | 30 runReflectiveTests(NodeLocator2Test); |
| 31 runReflectiveTests(ResolutionCopierTest); |
| 27 runReflectiveTests(ToSourceVisitorTest); | 32 runReflectiveTests(ToSourceVisitorTest); |
| 28 } | 33 } |
| 29 | 34 |
| 30 @reflectiveTest | 35 @reflectiveTest |
| 31 class ConstantEvaluatorTest extends ParserTestCase { | 36 class ConstantEvaluatorTest extends ParserTestCase { |
| 32 void fail_constructor() { | 37 void fail_constructor() { |
| 33 Object value = _getConstantValue("?"); | 38 Object value = _getConstantValue("?"); |
| 34 expect(value, null); | 39 expect(value, null); |
| 35 } | 40 } |
| 36 | 41 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 expect(node, isNotNull); | 426 expect(node, isNotNull); |
| 422 expect(locator.foundNode, same(node)); | 427 expect(locator.foundNode, same(node)); |
| 423 expect(node.offset <= start, isTrue, reason: "Node starts after range"); | 428 expect(node.offset <= start, isTrue, reason: "Node starts after range"); |
| 424 expect(node.offset + node.length > end, isTrue, | 429 expect(node.offset + node.length > end, isTrue, |
| 425 reason: "Node ends before range"); | 430 reason: "Node ends before range"); |
| 426 EngineTestCase.assertInstanceOf(predicate, expectedClass, node); | 431 EngineTestCase.assertInstanceOf(predicate, expectedClass, node); |
| 427 } | 432 } |
| 428 } | 433 } |
| 429 | 434 |
| 430 @reflectiveTest | 435 @reflectiveTest |
| 436 class ResolutionCopierTest extends EngineTestCase { |
| 437 void test_visitAdjacentStrings() { |
| 438 AdjacentStrings createNode() => new AdjacentStrings([ |
| 439 new SimpleStringLiteral(null, 'hello'), |
| 440 new SimpleStringLiteral(null, 'world') |
| 441 ]); |
| 442 |
| 443 AdjacentStrings fromNode = createNode(); |
| 444 DartType propagatedType = ElementFactory.classElement2("A").type; |
| 445 fromNode.propagatedType = propagatedType; |
| 446 DartType staticType = ElementFactory.classElement2("B").type; |
| 447 fromNode.staticType = staticType; |
| 448 |
| 449 AdjacentStrings toNode = createNode(); |
| 450 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 451 expect(toNode.propagatedType, same(propagatedType)); |
| 452 expect(toNode.staticType, same(staticType)); |
| 453 } |
| 454 |
| 455 void test_visitAnnotation() { |
| 456 String annotationName = "proxy"; |
| 457 Annotation fromNode = |
| 458 AstFactory.annotation(AstFactory.identifier3(annotationName)); |
| 459 Element element = ElementFactory.topLevelVariableElement2(annotationName); |
| 460 fromNode.element = element; |
| 461 Annotation toNode = |
| 462 AstFactory.annotation(AstFactory.identifier3(annotationName)); |
| 463 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 464 expect(toNode.element, same(element)); |
| 465 } |
| 466 |
| 467 void test_visitAsExpression() { |
| 468 AsExpression fromNode = AstFactory.asExpression( |
| 469 AstFactory.identifier3("x"), AstFactory.typeName4("A")); |
| 470 DartType propagatedType = ElementFactory.classElement2("A").type; |
| 471 fromNode.propagatedType = propagatedType; |
| 472 DartType staticType = ElementFactory.classElement2("B").type; |
| 473 fromNode.staticType = staticType; |
| 474 AsExpression toNode = AstFactory.asExpression( |
| 475 AstFactory.identifier3("x"), AstFactory.typeName4("A")); |
| 476 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 477 expect(toNode.propagatedType, same(propagatedType)); |
| 478 expect(toNode.staticType, same(staticType)); |
| 479 } |
| 480 |
| 481 void test_visitAssignmentExpression() { |
| 482 AssignmentExpression fromNode = AstFactory.assignmentExpression( |
| 483 AstFactory.identifier3("a"), |
| 484 TokenType.PLUS_EQ, |
| 485 AstFactory.identifier3("b")); |
| 486 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 487 MethodElement propagatedElement = |
| 488 ElementFactory.methodElement("+", propagatedType); |
| 489 fromNode.propagatedElement = propagatedElement; |
| 490 fromNode.propagatedType = propagatedType; |
| 491 DartType staticType = ElementFactory.classElement2("C").type; |
| 492 MethodElement staticElement = ElementFactory.methodElement("+", staticType); |
| 493 fromNode.staticElement = staticElement; |
| 494 fromNode.staticType = staticType; |
| 495 AssignmentExpression toNode = AstFactory.assignmentExpression( |
| 496 AstFactory.identifier3("a"), |
| 497 TokenType.PLUS_EQ, |
| 498 AstFactory.identifier3("b")); |
| 499 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 500 expect(toNode.propagatedElement, same(propagatedElement)); |
| 501 expect(toNode.propagatedType, same(propagatedType)); |
| 502 expect(toNode.staticElement, same(staticElement)); |
| 503 expect(toNode.staticType, same(staticType)); |
| 504 } |
| 505 |
| 506 void test_visitBinaryExpression() { |
| 507 BinaryExpression fromNode = AstFactory.binaryExpression( |
| 508 AstFactory.identifier3("a"), |
| 509 TokenType.PLUS, |
| 510 AstFactory.identifier3("b")); |
| 511 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 512 MethodElement propagatedElement = |
| 513 ElementFactory.methodElement("+", propagatedType); |
| 514 fromNode.propagatedElement = propagatedElement; |
| 515 fromNode.propagatedType = propagatedType; |
| 516 DartType staticType = ElementFactory.classElement2("C").type; |
| 517 MethodElement staticElement = ElementFactory.methodElement("+", staticType); |
| 518 fromNode.staticElement = staticElement; |
| 519 fromNode.staticType = staticType; |
| 520 BinaryExpression toNode = AstFactory.binaryExpression( |
| 521 AstFactory.identifier3("a"), |
| 522 TokenType.PLUS, |
| 523 AstFactory.identifier3("b")); |
| 524 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 525 expect(toNode.propagatedElement, same(propagatedElement)); |
| 526 expect(toNode.propagatedType, same(propagatedType)); |
| 527 expect(toNode.staticElement, same(staticElement)); |
| 528 expect(toNode.staticType, same(staticType)); |
| 529 } |
| 530 |
| 531 void test_visitBooleanLiteral() { |
| 532 BooleanLiteral fromNode = AstFactory.booleanLiteral(true); |
| 533 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 534 fromNode.propagatedType = propagatedType; |
| 535 DartType staticType = ElementFactory.classElement2("C").type; |
| 536 fromNode.staticType = staticType; |
| 537 BooleanLiteral toNode = AstFactory.booleanLiteral(true); |
| 538 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 539 expect(toNode.propagatedType, same(propagatedType)); |
| 540 expect(toNode.staticType, same(staticType)); |
| 541 } |
| 542 |
| 543 void test_visitCascadeExpression() { |
| 544 CascadeExpression fromNode = AstFactory.cascadeExpression( |
| 545 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); |
| 546 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 547 fromNode.propagatedType = propagatedType; |
| 548 DartType staticType = ElementFactory.classElement2("C").type; |
| 549 fromNode.staticType = staticType; |
| 550 CascadeExpression toNode = AstFactory.cascadeExpression( |
| 551 AstFactory.identifier3("a"), [AstFactory.identifier3("b")]); |
| 552 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 553 expect(toNode.propagatedType, same(propagatedType)); |
| 554 expect(toNode.staticType, same(staticType)); |
| 555 } |
| 556 |
| 557 void test_visitCompilationUnit() { |
| 558 CompilationUnit fromNode = AstFactory.compilationUnit(); |
| 559 CompilationUnitElement element = |
| 560 new CompilationUnitElementImpl("test.dart"); |
| 561 fromNode.element = element; |
| 562 CompilationUnit toNode = AstFactory.compilationUnit(); |
| 563 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 564 expect(toNode.element, same(element)); |
| 565 } |
| 566 |
| 567 void test_visitConditionalExpression() { |
| 568 ConditionalExpression fromNode = AstFactory.conditionalExpression( |
| 569 AstFactory.identifier3("c"), |
| 570 AstFactory.identifier3("a"), |
| 571 AstFactory.identifier3("b")); |
| 572 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 573 fromNode.propagatedType = propagatedType; |
| 574 DartType staticType = ElementFactory.classElement2("C").type; |
| 575 fromNode.staticType = staticType; |
| 576 ConditionalExpression toNode = AstFactory.conditionalExpression( |
| 577 AstFactory.identifier3("c"), |
| 578 AstFactory.identifier3("a"), |
| 579 AstFactory.identifier3("b")); |
| 580 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 581 expect(toNode.propagatedType, same(propagatedType)); |
| 582 expect(toNode.staticType, same(staticType)); |
| 583 } |
| 584 |
| 585 void test_visitConstructorDeclaration() { |
| 586 String className = "A"; |
| 587 String constructorName = "c"; |
| 588 ConstructorDeclaration fromNode = AstFactory.constructorDeclaration( |
| 589 AstFactory.identifier3(className), |
| 590 constructorName, |
| 591 AstFactory.formalParameterList(), |
| 592 null); |
| 593 ConstructorElement element = ElementFactory.constructorElement2( |
| 594 ElementFactory.classElement2(className), constructorName); |
| 595 fromNode.element = element; |
| 596 ConstructorDeclaration toNode = AstFactory.constructorDeclaration( |
| 597 AstFactory.identifier3(className), |
| 598 constructorName, |
| 599 AstFactory.formalParameterList(), |
| 600 null); |
| 601 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 602 expect(toNode.element, same(element)); |
| 603 } |
| 604 |
| 605 void test_visitConstructorName() { |
| 606 ConstructorName fromNode = |
| 607 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); |
| 608 ConstructorElement staticElement = ElementFactory.constructorElement2( |
| 609 ElementFactory.classElement2("A"), "c"); |
| 610 fromNode.staticElement = staticElement; |
| 611 ConstructorName toNode = |
| 612 AstFactory.constructorName(AstFactory.typeName4("A"), "c"); |
| 613 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 614 expect(toNode.staticElement, same(staticElement)); |
| 615 } |
| 616 |
| 617 void test_visitDoubleLiteral() { |
| 618 DoubleLiteral fromNode = AstFactory.doubleLiteral(1.0); |
| 619 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 620 fromNode.propagatedType = propagatedType; |
| 621 DartType staticType = ElementFactory.classElement2("C").type; |
| 622 fromNode.staticType = staticType; |
| 623 DoubleLiteral toNode = AstFactory.doubleLiteral(1.0); |
| 624 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 625 expect(toNode.propagatedType, same(propagatedType)); |
| 626 expect(toNode.staticType, same(staticType)); |
| 627 } |
| 628 |
| 629 void test_visitExportDirective() { |
| 630 ExportDirective fromNode = AstFactory.exportDirective2("dart:uri"); |
| 631 ExportElement element = new ExportElementImpl(-1); |
| 632 fromNode.element = element; |
| 633 ExportDirective toNode = AstFactory.exportDirective2("dart:uri"); |
| 634 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 635 expect(toNode.element, same(element)); |
| 636 } |
| 637 |
| 638 void test_visitFunctionExpression() { |
| 639 FunctionExpression fromNode = AstFactory.functionExpression2( |
| 640 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); |
| 641 MethodElement element = ElementFactory.methodElement( |
| 642 "m", ElementFactory.classElement2("C").type); |
| 643 fromNode.element = element; |
| 644 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 645 fromNode.propagatedType = propagatedType; |
| 646 DartType staticType = ElementFactory.classElement2("C").type; |
| 647 fromNode.staticType = staticType; |
| 648 FunctionExpression toNode = AstFactory.functionExpression2( |
| 649 AstFactory.formalParameterList(), AstFactory.emptyFunctionBody()); |
| 650 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 651 expect(toNode.element, same(element)); |
| 652 expect(toNode.propagatedType, same(propagatedType)); |
| 653 expect(toNode.staticType, same(staticType)); |
| 654 } |
| 655 |
| 656 void test_visitFunctionExpressionInvocation() { |
| 657 FunctionExpressionInvocation fromNode = |
| 658 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); |
| 659 MethodElement propagatedElement = ElementFactory.methodElement( |
| 660 "m", ElementFactory.classElement2("C").type); |
| 661 fromNode.propagatedElement = propagatedElement; |
| 662 MethodElement staticElement = ElementFactory.methodElement( |
| 663 "m", ElementFactory.classElement2("C").type); |
| 664 fromNode.staticElement = staticElement; |
| 665 FunctionExpressionInvocation toNode = |
| 666 AstFactory.functionExpressionInvocation(AstFactory.identifier3("f")); |
| 667 |
| 668 _copyAndVerifyInvocation(fromNode, toNode); |
| 669 |
| 670 expect(toNode.propagatedElement, same(propagatedElement)); |
| 671 expect(toNode.staticElement, same(staticElement)); |
| 672 } |
| 673 |
| 674 void test_visitImportDirective() { |
| 675 ImportDirective fromNode = AstFactory.importDirective3("dart:uri", null); |
| 676 ImportElement element = new ImportElementImpl(0); |
| 677 fromNode.element = element; |
| 678 ImportDirective toNode = AstFactory.importDirective3("dart:uri", null); |
| 679 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 680 expect(toNode.element, same(element)); |
| 681 } |
| 682 |
| 683 void test_visitIndexExpression() { |
| 684 IndexExpression fromNode = AstFactory.indexExpression( |
| 685 AstFactory.identifier3("a"), AstFactory.integer(0)); |
| 686 MethodElement propagatedElement = ElementFactory.methodElement( |
| 687 "m", ElementFactory.classElement2("C").type); |
| 688 MethodElement staticElement = ElementFactory.methodElement( |
| 689 "m", ElementFactory.classElement2("C").type); |
| 690 AuxiliaryElements auxiliaryElements = |
| 691 new AuxiliaryElements(staticElement, propagatedElement); |
| 692 fromNode.auxiliaryElements = auxiliaryElements; |
| 693 fromNode.propagatedElement = propagatedElement; |
| 694 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 695 fromNode.propagatedType = propagatedType; |
| 696 fromNode.staticElement = staticElement; |
| 697 DartType staticType = ElementFactory.classElement2("C").type; |
| 698 fromNode.staticType = staticType; |
| 699 IndexExpression toNode = AstFactory.indexExpression( |
| 700 AstFactory.identifier3("a"), AstFactory.integer(0)); |
| 701 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 702 expect(toNode.auxiliaryElements, same(auxiliaryElements)); |
| 703 expect(toNode.propagatedElement, same(propagatedElement)); |
| 704 expect(toNode.propagatedType, same(propagatedType)); |
| 705 expect(toNode.staticElement, same(staticElement)); |
| 706 expect(toNode.staticType, same(staticType)); |
| 707 } |
| 708 |
| 709 void test_visitInstanceCreationExpression() { |
| 710 InstanceCreationExpression fromNode = AstFactory |
| 711 .instanceCreationExpression2(Keyword.NEW, AstFactory.typeName4("C")); |
| 712 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 713 fromNode.propagatedType = propagatedType; |
| 714 ConstructorElement staticElement = ElementFactory.constructorElement2( |
| 715 ElementFactory.classElement2("C"), null); |
| 716 fromNode.staticElement = staticElement; |
| 717 DartType staticType = ElementFactory.classElement2("C").type; |
| 718 fromNode.staticType = staticType; |
| 719 InstanceCreationExpression toNode = AstFactory.instanceCreationExpression2( |
| 720 Keyword.NEW, AstFactory.typeName4("C")); |
| 721 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 722 expect(toNode.propagatedType, same(propagatedType)); |
| 723 expect(toNode.staticElement, same(staticElement)); |
| 724 expect(toNode.staticType, same(staticType)); |
| 725 } |
| 726 |
| 727 void test_visitIntegerLiteral() { |
| 728 IntegerLiteral fromNode = AstFactory.integer(2); |
| 729 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 730 fromNode.propagatedType = propagatedType; |
| 731 DartType staticType = ElementFactory.classElement2("C").type; |
| 732 fromNode.staticType = staticType; |
| 733 IntegerLiteral toNode = AstFactory.integer(2); |
| 734 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 735 expect(toNode.propagatedType, same(propagatedType)); |
| 736 expect(toNode.staticType, same(staticType)); |
| 737 } |
| 738 |
| 739 void test_visitIsExpression() { |
| 740 IsExpression fromNode = AstFactory.isExpression( |
| 741 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); |
| 742 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 743 fromNode.propagatedType = propagatedType; |
| 744 DartType staticType = ElementFactory.classElement2("C").type; |
| 745 fromNode.staticType = staticType; |
| 746 IsExpression toNode = AstFactory.isExpression( |
| 747 AstFactory.identifier3("x"), false, AstFactory.typeName4("A")); |
| 748 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 749 expect(toNode.propagatedType, same(propagatedType)); |
| 750 expect(toNode.staticType, same(staticType)); |
| 751 } |
| 752 |
| 753 void test_visitLibraryIdentifier() { |
| 754 LibraryIdentifier fromNode = |
| 755 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); |
| 756 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 757 fromNode.propagatedType = propagatedType; |
| 758 DartType staticType = ElementFactory.classElement2("C").type; |
| 759 fromNode.staticType = staticType; |
| 760 LibraryIdentifier toNode = |
| 761 AstFactory.libraryIdentifier([AstFactory.identifier3("lib")]); |
| 762 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 763 expect(toNode.propagatedType, same(propagatedType)); |
| 764 expect(toNode.staticType, same(staticType)); |
| 765 } |
| 766 |
| 767 void test_visitListLiteral() { |
| 768 ListLiteral fromNode = AstFactory.listLiteral(); |
| 769 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 770 fromNode.propagatedType = propagatedType; |
| 771 DartType staticType = ElementFactory.classElement2("C").type; |
| 772 fromNode.staticType = staticType; |
| 773 ListLiteral toNode = AstFactory.listLiteral(); |
| 774 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 775 expect(toNode.propagatedType, same(propagatedType)); |
| 776 expect(toNode.staticType, same(staticType)); |
| 777 } |
| 778 |
| 779 void test_visitMapLiteral() { |
| 780 MapLiteral fromNode = AstFactory.mapLiteral2(); |
| 781 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 782 fromNode.propagatedType = propagatedType; |
| 783 DartType staticType = ElementFactory.classElement2("C").type; |
| 784 fromNode.staticType = staticType; |
| 785 MapLiteral toNode = AstFactory.mapLiteral2(); |
| 786 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 787 expect(toNode.propagatedType, same(propagatedType)); |
| 788 expect(toNode.staticType, same(staticType)); |
| 789 } |
| 790 |
| 791 void test_visitMethodInvocation() { |
| 792 MethodInvocation fromNode = AstFactory.methodInvocation2("m"); |
| 793 MethodInvocation toNode = AstFactory.methodInvocation2("m"); |
| 794 _copyAndVerifyInvocation(fromNode, toNode); |
| 795 } |
| 796 |
| 797 void test_visitNamedExpression() { |
| 798 NamedExpression fromNode = |
| 799 AstFactory.namedExpression2("n", AstFactory.integer(0)); |
| 800 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 801 fromNode.propagatedType = propagatedType; |
| 802 DartType staticType = ElementFactory.classElement2("C").type; |
| 803 fromNode.staticType = staticType; |
| 804 NamedExpression toNode = |
| 805 AstFactory.namedExpression2("n", AstFactory.integer(0)); |
| 806 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 807 expect(toNode.propagatedType, same(propagatedType)); |
| 808 expect(toNode.staticType, same(staticType)); |
| 809 } |
| 810 |
| 811 void test_visitNullLiteral() { |
| 812 NullLiteral fromNode = AstFactory.nullLiteral(); |
| 813 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 814 fromNode.propagatedType = propagatedType; |
| 815 DartType staticType = ElementFactory.classElement2("C").type; |
| 816 fromNode.staticType = staticType; |
| 817 NullLiteral toNode = AstFactory.nullLiteral(); |
| 818 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 819 expect(toNode.propagatedType, same(propagatedType)); |
| 820 expect(toNode.staticType, same(staticType)); |
| 821 } |
| 822 |
| 823 void test_visitParenthesizedExpression() { |
| 824 ParenthesizedExpression fromNode = |
| 825 AstFactory.parenthesizedExpression(AstFactory.integer(0)); |
| 826 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 827 fromNode.propagatedType = propagatedType; |
| 828 DartType staticType = ElementFactory.classElement2("C").type; |
| 829 fromNode.staticType = staticType; |
| 830 ParenthesizedExpression toNode = |
| 831 AstFactory.parenthesizedExpression(AstFactory.integer(0)); |
| 832 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 833 expect(toNode.propagatedType, same(propagatedType)); |
| 834 expect(toNode.staticType, same(staticType)); |
| 835 } |
| 836 |
| 837 void test_visitPartDirective() { |
| 838 PartDirective fromNode = AstFactory.partDirective2("part.dart"); |
| 839 LibraryElement element = new LibraryElementImpl.forNode( |
| 840 null, AstFactory.libraryIdentifier2(["lib"])); |
| 841 fromNode.element = element; |
| 842 PartDirective toNode = AstFactory.partDirective2("part.dart"); |
| 843 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 844 expect(toNode.element, same(element)); |
| 845 } |
| 846 |
| 847 void test_visitPartOfDirective() { |
| 848 PartOfDirective fromNode = |
| 849 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); |
| 850 LibraryElement element = new LibraryElementImpl.forNode( |
| 851 null, AstFactory.libraryIdentifier2(["lib"])); |
| 852 fromNode.element = element; |
| 853 PartOfDirective toNode = |
| 854 AstFactory.partOfDirective(AstFactory.libraryIdentifier2(["lib"])); |
| 855 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 856 expect(toNode.element, same(element)); |
| 857 } |
| 858 |
| 859 void test_visitPostfixExpression() { |
| 860 String variableName = "x"; |
| 861 PostfixExpression fromNode = AstFactory.postfixExpression( |
| 862 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); |
| 863 MethodElement propagatedElement = ElementFactory.methodElement( |
| 864 "+", ElementFactory.classElement2("C").type); |
| 865 fromNode.propagatedElement = propagatedElement; |
| 866 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 867 fromNode.propagatedType = propagatedType; |
| 868 MethodElement staticElement = ElementFactory.methodElement( |
| 869 "+", ElementFactory.classElement2("C").type); |
| 870 fromNode.staticElement = staticElement; |
| 871 DartType staticType = ElementFactory.classElement2("C").type; |
| 872 fromNode.staticType = staticType; |
| 873 PostfixExpression toNode = AstFactory.postfixExpression( |
| 874 AstFactory.identifier3(variableName), TokenType.PLUS_PLUS); |
| 875 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 876 expect(toNode.propagatedElement, same(propagatedElement)); |
| 877 expect(toNode.propagatedType, same(propagatedType)); |
| 878 expect(toNode.staticElement, same(staticElement)); |
| 879 expect(toNode.staticType, same(staticType)); |
| 880 } |
| 881 |
| 882 void test_visitPrefixedIdentifier() { |
| 883 PrefixedIdentifier fromNode = AstFactory.identifier5("p", "f"); |
| 884 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 885 fromNode.propagatedType = propagatedType; |
| 886 DartType staticType = ElementFactory.classElement2("C").type; |
| 887 fromNode.staticType = staticType; |
| 888 PrefixedIdentifier toNode = AstFactory.identifier5("p", "f"); |
| 889 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 890 expect(toNode.propagatedType, same(propagatedType)); |
| 891 expect(toNode.staticType, same(staticType)); |
| 892 } |
| 893 |
| 894 void test_visitPrefixExpression() { |
| 895 PrefixExpression fromNode = AstFactory.prefixExpression( |
| 896 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); |
| 897 MethodElement propagatedElement = ElementFactory.methodElement( |
| 898 "+", ElementFactory.classElement2("C").type); |
| 899 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 900 fromNode.propagatedElement = propagatedElement; |
| 901 fromNode.propagatedType = propagatedType; |
| 902 DartType staticType = ElementFactory.classElement2("C").type; |
| 903 MethodElement staticElement = ElementFactory.methodElement( |
| 904 "+", ElementFactory.classElement2("C").type); |
| 905 fromNode.staticElement = staticElement; |
| 906 fromNode.staticType = staticType; |
| 907 PrefixExpression toNode = AstFactory.prefixExpression( |
| 908 TokenType.PLUS_PLUS, AstFactory.identifier3("x")); |
| 909 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 910 expect(toNode.propagatedElement, same(propagatedElement)); |
| 911 expect(toNode.propagatedType, same(propagatedType)); |
| 912 expect(toNode.staticElement, same(staticElement)); |
| 913 expect(toNode.staticType, same(staticType)); |
| 914 } |
| 915 |
| 916 void test_visitPropertyAccess() { |
| 917 PropertyAccess fromNode = |
| 918 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); |
| 919 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 920 fromNode.propagatedType = propagatedType; |
| 921 DartType staticType = ElementFactory.classElement2("C").type; |
| 922 fromNode.staticType = staticType; |
| 923 PropertyAccess toNode = |
| 924 AstFactory.propertyAccess2(AstFactory.identifier3("x"), "y"); |
| 925 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 926 expect(toNode.propagatedType, same(propagatedType)); |
| 927 expect(toNode.staticType, same(staticType)); |
| 928 } |
| 929 |
| 930 void test_visitRedirectingConstructorInvocation() { |
| 931 RedirectingConstructorInvocation fromNode = |
| 932 AstFactory.redirectingConstructorInvocation(); |
| 933 ConstructorElement staticElement = ElementFactory.constructorElement2( |
| 934 ElementFactory.classElement2("C"), null); |
| 935 fromNode.staticElement = staticElement; |
| 936 RedirectingConstructorInvocation toNode = |
| 937 AstFactory.redirectingConstructorInvocation(); |
| 938 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 939 expect(toNode.staticElement, same(staticElement)); |
| 940 } |
| 941 |
| 942 void test_visitRethrowExpression() { |
| 943 RethrowExpression fromNode = AstFactory.rethrowExpression(); |
| 944 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 945 fromNode.propagatedType = propagatedType; |
| 946 DartType staticType = ElementFactory.classElement2("C").type; |
| 947 fromNode.staticType = staticType; |
| 948 RethrowExpression toNode = AstFactory.rethrowExpression(); |
| 949 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 950 expect(toNode.propagatedType, same(propagatedType)); |
| 951 expect(toNode.staticType, same(staticType)); |
| 952 } |
| 953 |
| 954 void test_visitSimpleIdentifier() { |
| 955 SimpleIdentifier fromNode = AstFactory.identifier3("x"); |
| 956 MethodElement propagatedElement = ElementFactory.methodElement( |
| 957 "m", ElementFactory.classElement2("C").type); |
| 958 MethodElement staticElement = ElementFactory.methodElement( |
| 959 "m", ElementFactory.classElement2("C").type); |
| 960 AuxiliaryElements auxiliaryElements = |
| 961 new AuxiliaryElements(staticElement, propagatedElement); |
| 962 fromNode.auxiliaryElements = auxiliaryElements; |
| 963 fromNode.propagatedElement = propagatedElement; |
| 964 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 965 fromNode.propagatedType = propagatedType; |
| 966 fromNode.staticElement = staticElement; |
| 967 DartType staticType = ElementFactory.classElement2("C").type; |
| 968 fromNode.staticType = staticType; |
| 969 SimpleIdentifier toNode = AstFactory.identifier3("x"); |
| 970 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 971 expect(toNode.auxiliaryElements, same(auxiliaryElements)); |
| 972 expect(toNode.propagatedElement, same(propagatedElement)); |
| 973 expect(toNode.propagatedType, same(propagatedType)); |
| 974 expect(toNode.staticElement, same(staticElement)); |
| 975 expect(toNode.staticType, same(staticType)); |
| 976 } |
| 977 |
| 978 void test_visitSimpleStringLiteral() { |
| 979 SimpleStringLiteral fromNode = AstFactory.string2("abc"); |
| 980 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 981 fromNode.propagatedType = propagatedType; |
| 982 DartType staticType = ElementFactory.classElement2("C").type; |
| 983 fromNode.staticType = staticType; |
| 984 SimpleStringLiteral toNode = AstFactory.string2("abc"); |
| 985 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 986 expect(toNode.propagatedType, same(propagatedType)); |
| 987 expect(toNode.staticType, same(staticType)); |
| 988 } |
| 989 |
| 990 void test_visitStringInterpolation() { |
| 991 StringInterpolation fromNode = |
| 992 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); |
| 993 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 994 fromNode.propagatedType = propagatedType; |
| 995 DartType staticType = ElementFactory.classElement2("C").type; |
| 996 fromNode.staticType = staticType; |
| 997 StringInterpolation toNode = |
| 998 AstFactory.string([AstFactory.interpolationString("a", "'a'")]); |
| 999 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1000 expect(toNode.propagatedType, same(propagatedType)); |
| 1001 expect(toNode.staticType, same(staticType)); |
| 1002 } |
| 1003 |
| 1004 void test_visitSuperConstructorInvocation() { |
| 1005 SuperConstructorInvocation fromNode = |
| 1006 AstFactory.superConstructorInvocation(); |
| 1007 ConstructorElement staticElement = ElementFactory.constructorElement2( |
| 1008 ElementFactory.classElement2("C"), null); |
| 1009 fromNode.staticElement = staticElement; |
| 1010 SuperConstructorInvocation toNode = AstFactory.superConstructorInvocation(); |
| 1011 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1012 expect(toNode.staticElement, same(staticElement)); |
| 1013 } |
| 1014 |
| 1015 void test_visitSuperExpression() { |
| 1016 SuperExpression fromNode = AstFactory.superExpression(); |
| 1017 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 1018 fromNode.propagatedType = propagatedType; |
| 1019 DartType staticType = ElementFactory.classElement2("C").type; |
| 1020 fromNode.staticType = staticType; |
| 1021 SuperExpression toNode = AstFactory.superExpression(); |
| 1022 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1023 expect(toNode.propagatedType, same(propagatedType)); |
| 1024 expect(toNode.staticType, same(staticType)); |
| 1025 } |
| 1026 |
| 1027 void test_visitSymbolLiteral() { |
| 1028 SymbolLiteral fromNode = AstFactory.symbolLiteral(["s"]); |
| 1029 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 1030 fromNode.propagatedType = propagatedType; |
| 1031 DartType staticType = ElementFactory.classElement2("C").type; |
| 1032 fromNode.staticType = staticType; |
| 1033 SymbolLiteral toNode = AstFactory.symbolLiteral(["s"]); |
| 1034 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1035 expect(toNode.propagatedType, same(propagatedType)); |
| 1036 expect(toNode.staticType, same(staticType)); |
| 1037 } |
| 1038 |
| 1039 void test_visitThisExpression() { |
| 1040 ThisExpression fromNode = AstFactory.thisExpression(); |
| 1041 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 1042 fromNode.propagatedType = propagatedType; |
| 1043 DartType staticType = ElementFactory.classElement2("C").type; |
| 1044 fromNode.staticType = staticType; |
| 1045 ThisExpression toNode = AstFactory.thisExpression(); |
| 1046 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1047 expect(toNode.propagatedType, same(propagatedType)); |
| 1048 expect(toNode.staticType, same(staticType)); |
| 1049 } |
| 1050 |
| 1051 void test_visitThrowExpression() { |
| 1052 ThrowExpression fromNode = AstFactory.throwExpression(); |
| 1053 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 1054 fromNode.propagatedType = propagatedType; |
| 1055 DartType staticType = ElementFactory.classElement2("C").type; |
| 1056 fromNode.staticType = staticType; |
| 1057 ThrowExpression toNode = AstFactory.throwExpression(); |
| 1058 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1059 expect(toNode.propagatedType, same(propagatedType)); |
| 1060 expect(toNode.staticType, same(staticType)); |
| 1061 } |
| 1062 |
| 1063 void test_visitTypeName() { |
| 1064 TypeName fromNode = AstFactory.typeName4("C"); |
| 1065 DartType type = ElementFactory.classElement2("C").type; |
| 1066 fromNode.type = type; |
| 1067 TypeName toNode = AstFactory.typeName4("C"); |
| 1068 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1069 expect(toNode.type, same(type)); |
| 1070 } |
| 1071 |
| 1072 void _copyAndVerifyInvocation( |
| 1073 InvocationExpression fromNode, InvocationExpression toNode) { |
| 1074 DartType propagatedType = ElementFactory.classElement2("C").type; |
| 1075 fromNode.propagatedType = propagatedType; |
| 1076 DartType staticType = ElementFactory.classElement2("C").type; |
| 1077 fromNode.staticType = staticType; |
| 1078 |
| 1079 DartType propagatedInvokeType = ElementFactory.classElement2("C").type; |
| 1080 fromNode.propagatedInvokeType = propagatedInvokeType; |
| 1081 DartType staticInvokeType = ElementFactory.classElement2("C").type; |
| 1082 fromNode.staticInvokeType = staticInvokeType; |
| 1083 |
| 1084 ResolutionCopier.copyResolutionData(fromNode, toNode); |
| 1085 expect(toNode.propagatedType, same(propagatedType)); |
| 1086 expect(toNode.staticType, same(staticType)); |
| 1087 expect(toNode.propagatedInvokeType, same(propagatedInvokeType)); |
| 1088 expect(toNode.staticInvokeType, same(staticInvokeType)); |
| 1089 } |
| 1090 } |
| 1091 |
| 1092 @reflectiveTest |
| 431 class ToSourceVisitorTest extends EngineTestCase { | 1093 class ToSourceVisitorTest extends EngineTestCase { |
| 432 void test_visitAdjacentStrings() { | 1094 void test_visitAdjacentStrings() { |
| 433 _assertSource( | 1095 _assertSource( |
| 434 "'a' 'b'", | 1096 "'a' 'b'", |
| 435 AstFactory.adjacentStrings( | 1097 AstFactory.adjacentStrings( |
| 436 [AstFactory.string2("a"), AstFactory.string2("b")])); | 1098 [AstFactory.string2("a"), AstFactory.string2("b")])); |
| 437 } | 1099 } |
| 438 | 1100 |
| 439 void test_visitAnnotation_constant() { | 1101 void test_visitAnnotation_constant() { |
| 440 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); | 1102 _assertSource("@A", AstFactory.annotation(AstFactory.identifier3("A"))); |
| (...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2658 * @param expectedSource the source string that the visitor is expected to pro
duce | 3320 * @param expectedSource the source string that the visitor is expected to pro
duce |
| 2659 * @param node the AST node being visited to produce the actual source | 3321 * @param node the AST node being visited to produce the actual source |
| 2660 * @throws AFE if the visitor does not produce the expected source for the giv
en node | 3322 * @throws AFE if the visitor does not produce the expected source for the giv
en node |
| 2661 */ | 3323 */ |
| 2662 void _assertSource(String expectedSource, AstNode node) { | 3324 void _assertSource(String expectedSource, AstNode node) { |
| 2663 PrintStringWriter writer = new PrintStringWriter(); | 3325 PrintStringWriter writer = new PrintStringWriter(); |
| 2664 node.accept(new ToSourceVisitor(writer)); | 3326 node.accept(new ToSourceVisitor(writer)); |
| 2665 expect(writer.toString(), expectedSource); | 3327 expect(writer.toString(), expectedSource); |
| 2666 } | 3328 } |
| 2667 } | 3329 } |
| OLD | NEW |