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

Side by Side Diff: pkg/analyzer/test/generated/simple_resolver_test.dart

Issue 2551023005: Prepare for decoupling analyzer ASTs from element model. (Closed)
Patch Set: Address review comments Created 4 years 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.generated.simple_resolver_test; 5 library analyzer.test.generated.simple_resolver_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/standard_resolution_map.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
11 import 'package:analyzer/exception/exception.dart'; 12 import 'package:analyzer/exception/exception.dart';
12 import 'package:analyzer/src/error/codes.dart'; 13 import 'package:analyzer/src/error/codes.dart';
13 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
14 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
15 import 'package:test/test.dart'; 16 import 'package:test/test.dart';
16 import 'package:test_reflective_loader/test_reflective_loader.dart'; 17 import 'package:test_reflective_loader/test_reflective_loader.dart';
17 18
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 assertNoErrors(source); 742 assertNoErrors(source);
742 verify([source]); 743 verify([source]);
743 // Verify that both the getter and setter for "x" in C.f() refer to the 744 // Verify that both the getter and setter for "x" in C.f() refer to the
744 // accessors defined in M2. 745 // accessors defined in M2.
745 ClassElement classC = library.definingCompilationUnit.types[3]; 746 ClassElement classC = library.definingCompilationUnit.types[3];
746 MethodDeclaration f = classC.getMethod('f').computeNode(); 747 MethodDeclaration f = classC.getMethod('f').computeNode();
747 BlockFunctionBody body = f.body; 748 BlockFunctionBody body = f.body;
748 ExpressionStatement stmt = body.block.statements[0]; 749 ExpressionStatement stmt = body.block.statements[0];
749 AssignmentExpression assignment = stmt.expression; 750 AssignmentExpression assignment = stmt.expression;
750 SimpleIdentifier leftHandSide = assignment.leftHandSide; 751 SimpleIdentifier leftHandSide = assignment.leftHandSide;
751 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); 752 expect(
753 resolutionMap
754 .staticElementForIdentifier(leftHandSide)
755 .enclosingElement
756 .name,
757 'M2');
752 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name, 758 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name,
753 'M2'); 759 'M2');
754 } 760 }
755 761
756 @failingTest 762 @failingTest
757 void test_getter_and_setter_fromMixins_property_access() { 763 void test_getter_and_setter_fromMixins_property_access() {
758 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on 764 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on
759 // a SimpleIdentifier that's inside a property access. This bug should be 765 // a SimpleIdentifier that's inside a property access. This bug should be
760 // fixed. 766 // fixed.
761 Source source = addSource(''' 767 Source source = addSource('''
(...skipping 16 matching lines...) Expand all
778 verify([source]); 784 verify([source]);
779 // Verify that both the getter and setter for "x" in "new C().x" refer to 785 // Verify that both the getter and setter for "x" in "new C().x" refer to
780 // the accessors defined in M2. 786 // the accessors defined in M2.
781 FunctionDeclaration main = 787 FunctionDeclaration main =
782 library.definingCompilationUnit.functions[0].computeNode(); 788 library.definingCompilationUnit.functions[0].computeNode();
783 BlockFunctionBody body = main.functionExpression.body; 789 BlockFunctionBody body = main.functionExpression.body;
784 ExpressionStatement stmt = body.block.statements[0]; 790 ExpressionStatement stmt = body.block.statements[0];
785 AssignmentExpression assignment = stmt.expression; 791 AssignmentExpression assignment = stmt.expression;
786 PropertyAccess propertyAccess = assignment.leftHandSide; 792 PropertyAccess propertyAccess = assignment.leftHandSide;
787 expect( 793 expect(
788 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); 794 resolutionMap
795 .staticElementForIdentifier(propertyAccess.propertyName)
796 .enclosingElement
797 .name,
798 'M2');
789 expect( 799 expect(
790 propertyAccess 800 propertyAccess
791 .propertyName.auxiliaryElements.staticElement.enclosingElement.name, 801 .propertyName.auxiliaryElements.staticElement.enclosingElement.name,
792 'M2'); 802 'M2');
793 } 803 }
794 804
795 void test_getter_fromMixins_bare_identifier() { 805 void test_getter_fromMixins_bare_identifier() {
796 Source source = addSource(''' 806 Source source = addSource('''
797 class B {} 807 class B {}
798 class M1 { 808 class M1 {
(...skipping 11 matching lines...) Expand all
810 LibraryElement library = resolve2(source); 820 LibraryElement library = resolve2(source);
811 assertNoErrors(source); 821 assertNoErrors(source);
812 verify([source]); 822 verify([source]);
813 // Verify that the getter for "x" in C.f() refers to the getter defined in 823 // Verify that the getter for "x" in C.f() refers to the getter defined in
814 // M2. 824 // M2.
815 ClassElement classC = library.definingCompilationUnit.types[3]; 825 ClassElement classC = library.definingCompilationUnit.types[3];
816 MethodDeclaration f = classC.getMethod('f').computeNode(); 826 MethodDeclaration f = classC.getMethod('f').computeNode();
817 BlockFunctionBody body = f.body; 827 BlockFunctionBody body = f.body;
818 ReturnStatement stmt = body.block.statements[0]; 828 ReturnStatement stmt = body.block.statements[0];
819 SimpleIdentifier x = stmt.expression; 829 SimpleIdentifier x = stmt.expression;
820 expect(x.staticElement.enclosingElement.name, 'M2'); 830 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name,
831 'M2');
821 } 832 }
822 833
823 void test_getter_fromMixins_property_access() { 834 void test_getter_fromMixins_property_access() {
824 Source source = addSource(''' 835 Source source = addSource('''
825 class B {} 836 class B {}
826 class M1 { 837 class M1 {
827 get x => null; 838 get x => null;
828 } 839 }
829 class M2 { 840 class M2 {
830 get x => null; 841 get x => null;
831 } 842 }
832 class C extends B with M1, M2 {} 843 class C extends B with M1, M2 {}
833 void main() { 844 void main() {
834 var y = new C().x; 845 var y = new C().x;
835 } 846 }
836 '''); 847 ''');
837 LibraryElement library = resolve2(source); 848 LibraryElement library = resolve2(source);
838 assertNoErrors(source); 849 assertNoErrors(source);
839 verify([source]); 850 verify([source]);
840 // Verify that the getter for "x" in "new C().x" refers to the getter 851 // Verify that the getter for "x" in "new C().x" refers to the getter
841 // defined in M2. 852 // defined in M2.
842 FunctionDeclaration main = 853 FunctionDeclaration main =
843 library.definingCompilationUnit.functions[0].computeNode(); 854 library.definingCompilationUnit.functions[0].computeNode();
844 BlockFunctionBody body = main.functionExpression.body; 855 BlockFunctionBody body = main.functionExpression.body;
845 VariableDeclarationStatement stmt = body.block.statements[0]; 856 VariableDeclarationStatement stmt = body.block.statements[0];
846 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; 857 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer;
847 expect( 858 expect(
848 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); 859 resolutionMap
860 .staticElementForIdentifier(propertyAccess.propertyName)
861 .enclosingElement
862 .name,
863 'M2');
849 } 864 }
850 865
851 void test_getterAndSetterWithDifferentTypes() { 866 void test_getterAndSetterWithDifferentTypes() {
852 Source source = addSource(r''' 867 Source source = addSource(r'''
853 class A { 868 class A {
854 int get f => 0; 869 int get f => 0;
855 void set f(String s) {} 870 void set f(String s) {}
856 } 871 }
857 g (A a) { 872 g (A a) {
858 a.f = a.f.toString(); 873 a.f = a.f.toString();
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 '''); 1543 ''');
1529 LibraryElement library = resolve2(source); 1544 LibraryElement library = resolve2(source);
1530 assertNoErrors(source); 1545 assertNoErrors(source);
1531 verify([source]); 1546 verify([source]);
1532 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. 1547 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2.
1533 FunctionDeclaration main = 1548 FunctionDeclaration main =
1534 library.definingCompilationUnit.functions[0].computeNode(); 1549 library.definingCompilationUnit.functions[0].computeNode();
1535 BlockFunctionBody body = main.functionExpression.body; 1550 BlockFunctionBody body = main.functionExpression.body;
1536 ExpressionStatement stmt = body.block.statements[0]; 1551 ExpressionStatement stmt = body.block.statements[0];
1537 MethodInvocation expr = stmt.expression; 1552 MethodInvocation expr = stmt.expression;
1538 expect(expr.methodName.staticElement.enclosingElement.name, 'M2'); 1553 expect(
1554 resolutionMap
1555 .staticElementForIdentifier(expr.methodName)
1556 .enclosingElement
1557 .name,
1558 'M2');
1539 } 1559 }
1540 1560
1541 void test_method_fromMixins_bare_identifier() { 1561 void test_method_fromMixins_bare_identifier() {
1542 Source source = addSource(''' 1562 Source source = addSource('''
1543 class B {} 1563 class B {}
1544 class M1 { 1564 class M1 {
1545 void f() {} 1565 void f() {}
1546 } 1566 }
1547 class M2 { 1567 class M2 {
1548 void f() {} 1568 void f() {}
1549 } 1569 }
1550 class C extends B with M1, M2 { 1570 class C extends B with M1, M2 {
1551 void g() { 1571 void g() {
1552 f(); 1572 f();
1553 } 1573 }
1554 } 1574 }
1555 '''); 1575 ''');
1556 LibraryElement library = resolve2(source); 1576 LibraryElement library = resolve2(source);
1557 assertNoErrors(source); 1577 assertNoErrors(source);
1558 verify([source]); 1578 verify([source]);
1559 // Verify that the call to f() in C.g() refers to the method defined in M2. 1579 // Verify that the call to f() in C.g() refers to the method defined in M2.
1560 ClassElement classC = library.definingCompilationUnit.types[3]; 1580 ClassElement classC = library.definingCompilationUnit.types[3];
1561 MethodDeclaration g = classC.getMethod('g').computeNode(); 1581 MethodDeclaration g = classC.getMethod('g').computeNode();
1562 BlockFunctionBody body = g.body; 1582 BlockFunctionBody body = g.body;
1563 ExpressionStatement stmt = body.block.statements[0]; 1583 ExpressionStatement stmt = body.block.statements[0];
1564 MethodInvocation invocation = stmt.expression; 1584 MethodInvocation invocation = stmt.expression;
1565 SimpleIdentifier methodName = invocation.methodName; 1585 SimpleIdentifier methodName = invocation.methodName;
1566 expect(methodName.staticElement.enclosingElement.name, 'M2'); 1586 expect(
1587 resolutionMap
1588 .staticElementForIdentifier(methodName)
1589 .enclosingElement
1590 .name,
1591 'M2');
1567 } 1592 }
1568 1593
1569 void test_method_fromMixins_invked_from_outside_class() { 1594 void test_method_fromMixins_invked_from_outside_class() {
1570 Source source = addSource(''' 1595 Source source = addSource('''
1571 class B {} 1596 class B {}
1572 class M1 { 1597 class M1 {
1573 void f() {} 1598 void f() {}
1574 } 1599 }
1575 class M2 { 1600 class M2 {
1576 void f() {} 1601 void f() {}
1577 } 1602 }
1578 class C extends B with M1, M2 {} 1603 class C extends B with M1, M2 {}
1579 void main() { 1604 void main() {
1580 new C().f(); 1605 new C().f();
1581 } 1606 }
1582 '''); 1607 ''');
1583 LibraryElement library = resolve2(source); 1608 LibraryElement library = resolve2(source);
1584 assertNoErrors(source); 1609 assertNoErrors(source);
1585 verify([source]); 1610 verify([source]);
1586 // Verify that the call to f() in "new C().f()" refers to the method 1611 // Verify that the call to f() in "new C().f()" refers to the method
1587 // defined in M2. 1612 // defined in M2.
1588 FunctionDeclaration main = 1613 FunctionDeclaration main =
1589 library.definingCompilationUnit.functions[0].computeNode(); 1614 library.definingCompilationUnit.functions[0].computeNode();
1590 BlockFunctionBody body = main.functionExpression.body; 1615 BlockFunctionBody body = main.functionExpression.body;
1591 ExpressionStatement stmt = body.block.statements[0]; 1616 ExpressionStatement stmt = body.block.statements[0];
1592 MethodInvocation invocation = stmt.expression; 1617 MethodInvocation invocation = stmt.expression;
1593 expect(invocation.methodName.staticElement.enclosingElement.name, 'M2'); 1618 expect(
1619 resolutionMap
1620 .staticElementForIdentifier(invocation.methodName)
1621 .enclosingElement
1622 .name,
1623 'M2');
1594 } 1624 }
1595 1625
1596 void test_method_fromSuperclassMixin() { 1626 void test_method_fromSuperclassMixin() {
1597 Source source = addSource(r''' 1627 Source source = addSource(r'''
1598 class A { 1628 class A {
1599 void m1() {} 1629 void m1() {}
1600 } 1630 }
1601 class B extends Object with A { 1631 class B extends Object with A {
1602 } 1632 }
1603 class C extends B { 1633 class C extends B {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 assertNoErrors(source); 1703 assertNoErrors(source);
1674 verify([source]); 1704 verify([source]);
1675 // Verify that the setter for "x" in C.f() refers to the setter defined in 1705 // Verify that the setter for "x" in C.f() refers to the setter defined in
1676 // M2. 1706 // M2.
1677 ClassElement classC = library.definingCompilationUnit.types[3]; 1707 ClassElement classC = library.definingCompilationUnit.types[3];
1678 MethodDeclaration f = classC.getMethod('f').computeNode(); 1708 MethodDeclaration f = classC.getMethod('f').computeNode();
1679 BlockFunctionBody body = f.body; 1709 BlockFunctionBody body = f.body;
1680 ExpressionStatement stmt = body.block.statements[0]; 1710 ExpressionStatement stmt = body.block.statements[0];
1681 AssignmentExpression assignment = stmt.expression; 1711 AssignmentExpression assignment = stmt.expression;
1682 SimpleIdentifier leftHandSide = assignment.leftHandSide; 1712 SimpleIdentifier leftHandSide = assignment.leftHandSide;
1683 expect(leftHandSide.staticElement.enclosingElement.name, 'M2'); 1713 expect(
1714 resolutionMap
1715 .staticElementForIdentifier(leftHandSide)
1716 .enclosingElement
1717 .name,
1718 'M2');
1684 } 1719 }
1685 1720
1686 void test_setter_fromMixins_property_access() { 1721 void test_setter_fromMixins_property_access() {
1687 Source source = addSource(''' 1722 Source source = addSource('''
1688 class B {} 1723 class B {}
1689 class M1 { 1724 class M1 {
1690 set x(value) {} 1725 set x(value) {}
1691 } 1726 }
1692 class M2 { 1727 class M2 {
1693 set x(value) {} 1728 set x(value) {}
1694 } 1729 }
1695 class C extends B with M1, M2 {} 1730 class C extends B with M1, M2 {}
1696 void main() { 1731 void main() {
1697 new C().x = 1; 1732 new C().x = 1;
1698 } 1733 }
1699 '''); 1734 ''');
1700 LibraryElement library = resolve2(source); 1735 LibraryElement library = resolve2(source);
1701 assertNoErrors(source); 1736 assertNoErrors(source);
1702 verify([source]); 1737 verify([source]);
1703 // Verify that the setter for "x" in "new C().x" refers to the setter 1738 // Verify that the setter for "x" in "new C().x" refers to the setter
1704 // defined in M2. 1739 // defined in M2.
1705 FunctionDeclaration main = 1740 FunctionDeclaration main =
1706 library.definingCompilationUnit.functions[0].computeNode(); 1741 library.definingCompilationUnit.functions[0].computeNode();
1707 BlockFunctionBody body = main.functionExpression.body; 1742 BlockFunctionBody body = main.functionExpression.body;
1708 ExpressionStatement stmt = body.block.statements[0]; 1743 ExpressionStatement stmt = body.block.statements[0];
1709 AssignmentExpression assignment = stmt.expression; 1744 AssignmentExpression assignment = stmt.expression;
1710 PropertyAccess propertyAccess = assignment.leftHandSide; 1745 PropertyAccess propertyAccess = assignment.leftHandSide;
1711 expect( 1746 expect(
1712 propertyAccess.propertyName.staticElement.enclosingElement.name, 'M2'); 1747 resolutionMap
1748 .staticElementForIdentifier(propertyAccess.propertyName)
1749 .enclosingElement
1750 .name,
1751 'M2');
1713 } 1752 }
1714 1753
1715 void test_setter_inherited() { 1754 void test_setter_inherited() {
1716 Source source = addSource(r''' 1755 Source source = addSource(r'''
1717 class A { 1756 class A {
1718 int get x => 0; 1757 int get x => 0;
1719 set x(int p) {} 1758 set x(int p) {}
1720 } 1759 }
1721 class B extends A { 1760 class B extends A {
1722 int get x => super.x == null ? 0 : super.x; 1761 int get x => super.x == null ? 0 : super.x;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 // check propagated type 1869 // check propagated type
1831 FunctionType propagatedType = node.propagatedType as FunctionType; 1870 FunctionType propagatedType = node.propagatedType as FunctionType;
1832 expect(propagatedType.returnType, test.typeProvider.stringType); 1871 expect(propagatedType.returnType, test.typeProvider.stringType);
1833 } on AnalysisException catch (e, stackTrace) { 1872 } on AnalysisException catch (e, stackTrace) {
1834 thrownException[0] = new CaughtException(e, stackTrace); 1873 thrownException[0] = new CaughtException(e, stackTrace);
1835 } 1874 }
1836 } 1875 }
1837 return null; 1876 return null;
1838 } 1877 }
1839 } 1878 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698