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

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

Issue 2676183002: Don't use Element.computeNode() in resolver tests. (Closed)
Patch Set: Created 3 years, 10 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) 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/standard_resolution_map.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
11 import 'package:analyzer/dart/element/type.dart'; 11 import 'package:analyzer/dart/element/type.dart';
12 import 'package:analyzer/exception/exception.dart'; 12 import 'package:analyzer/exception/exception.dart';
13 import 'package:analyzer/src/error/codes.dart'; 13 import 'package:analyzer/src/error/codes.dart';
14 import 'package:analyzer/src/generated/engine.dart'; 14 import 'package:analyzer/src/generated/engine.dart';
15 import 'package:analyzer/src/generated/source_io.dart'; 15 import 'package:analyzer/src/generated/source_io.dart';
16 import 'package:test/test.dart'; 16 import 'package:test/test.dart';
17 import 'package:test_reflective_loader/test_reflective_loader.dart'; 17 import 'package:test_reflective_loader/test_reflective_loader.dart';
18 18
19 import '../utils.dart';
19 import 'resolver_test_case.dart'; 20 import 'resolver_test_case.dart';
20 import 'test_support.dart'; 21 import 'test_support.dart';
21 22
22 main() { 23 main() {
23 defineReflectiveSuite(() { 24 defineReflectiveSuite(() {
24 defineReflectiveTests(SimpleResolverTest); 25 defineReflectiveTests(SimpleResolverTest);
25 }); 26 });
26 } 27 }
27 28
28 @reflectiveTest 29 @reflectiveTest
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 class A { 121 class A {
121 void f() { 122 void f() {
122 g(1, 2, 3, 4); 123 g(1, 2, 3, 4);
123 } 124 }
124 void g(a, b, [c]) {} 125 void g(a, b, [c]) {}
125 }'''); 126 }''');
126 _validateArgumentResolution(source, [0, 1, 2, -1]); 127 _validateArgumentResolution(source, [0, 1, 2, -1]);
127 } 128 }
128 129
129 test_argumentResolution_setter_propagated() async { 130 test_argumentResolution_setter_propagated() async {
130 Source source = addSource(r''' 131 CompilationUnit unit = await resolveSource(r'''
131 main() { 132 main() {
132 var a = new A(); 133 var a = new A();
133 a.sss = 0; 134 a.sss = 0;
134 } 135 }
135 class A { 136 class A {
136 set sss(x) {} 137 set sss(x) {}
137 }'''); 138 }''');
138 LibraryElement library = resolve2(source);
139 CompilationUnitElement unit = library.definingCompilationUnit;
140 // find "a.sss = 0" 139 // find "a.sss = 0"
141 AssignmentExpression assignment; 140 AssignmentExpression assignment;
142 { 141 {
143 FunctionElement mainElement = unit.functions[0]; 142 var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');
144 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; 143 var statement = statements[1] as ExpressionStatement;
145 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; 144 assignment = statement.expression as AssignmentExpression;
146 ExpressionStatement expressionStatement =
147 statement as ExpressionStatement;
148 assignment = expressionStatement.expression as AssignmentExpression;
149 } 145 }
150 // get parameter 146 // get parameter
151 Expression rhs = assignment.rightHandSide; 147 Expression rhs = assignment.rightHandSide;
152 expect(rhs.staticParameterElement, isNull); 148 expect(rhs.staticParameterElement, isNull);
153 ParameterElement parameter = rhs.propagatedParameterElement; 149 ParameterElement parameter = rhs.propagatedParameterElement;
154 expect(parameter, isNotNull); 150 expect(parameter, isNotNull);
155 expect(parameter.displayName, "x"); 151 expect(parameter.displayName, "x");
156 // validate 152 // validate
157 ClassElement classA = unit.types[0]; 153 ClassElement classA = unit.element.types[0];
158 PropertyAccessorElement setter = classA.accessors[0]; 154 PropertyAccessorElement setter = classA.accessors[0];
159 expect(setter.parameters[0], same(parameter)); 155 expect(setter.parameters[0], same(parameter));
160 } 156 }
161 157
162 test_argumentResolution_setter_propagated_propertyAccess() async { 158 test_argumentResolution_setter_propagated_propertyAccess() async {
163 Source source = addSource(r''' 159 CompilationUnit unit = await resolveSource(r'''
164 main() { 160 main() {
165 var a = new A(); 161 var a = new A();
166 a.b.sss = 0; 162 a.b.sss = 0;
167 } 163 }
168 class A { 164 class A {
169 B b = new B(); 165 B b = new B();
170 } 166 }
171 class B { 167 class B {
172 set sss(x) {} 168 set sss(x) {}
173 }'''); 169 }''');
174 LibraryElement library = resolve2(source);
175 CompilationUnitElement unit = library.definingCompilationUnit;
176 // find "a.b.sss = 0" 170 // find "a.b.sss = 0"
177 AssignmentExpression assignment; 171 AssignmentExpression assignment;
178 { 172 {
179 FunctionElement mainElement = unit.functions[0]; 173 var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');
180 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; 174 var statement = statements[1] as ExpressionStatement;
181 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; 175 assignment = statement.expression as AssignmentExpression;
182 ExpressionStatement expressionStatement =
183 statement as ExpressionStatement;
184 assignment = expressionStatement.expression as AssignmentExpression;
185 } 176 }
186 // get parameter 177 // get parameter
187 Expression rhs = assignment.rightHandSide; 178 Expression rhs = assignment.rightHandSide;
188 expect(rhs.staticParameterElement, isNull); 179 expect(rhs.staticParameterElement, isNull);
189 ParameterElement parameter = rhs.propagatedParameterElement; 180 ParameterElement parameter = rhs.propagatedParameterElement;
190 expect(parameter, isNotNull); 181 expect(parameter, isNotNull);
191 expect(parameter.displayName, "x"); 182 expect(parameter.displayName, "x");
192 // validate 183 // validate
193 ClassElement classB = unit.types[1]; 184 ClassElement classB = unit.element.types[1];
194 PropertyAccessorElement setter = classB.accessors[0]; 185 PropertyAccessorElement setter = classB.accessors[0];
195 expect(setter.parameters[0], same(parameter)); 186 expect(setter.parameters[0], same(parameter));
196 } 187 }
197 188
198 test_argumentResolution_setter_static() async { 189 test_argumentResolution_setter_static() async {
199 Source source = addSource(r''' 190 CompilationUnit unit = await resolveSource(r'''
200 main() { 191 main() {
201 A a = new A(); 192 A a = new A();
202 a.sss = 0; 193 a.sss = 0;
203 } 194 }
204 class A { 195 class A {
205 set sss(x) {} 196 set sss(x) {}
206 }'''); 197 }''');
207 LibraryElement library = resolve2(source);
208 CompilationUnitElement unit = library.definingCompilationUnit;
209 // find "a.sss = 0" 198 // find "a.sss = 0"
210 AssignmentExpression assignment; 199 AssignmentExpression assignment;
211 { 200 {
212 FunctionElement mainElement = unit.functions[0]; 201 var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');
213 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; 202 var statement = statements[1] as ExpressionStatement;
214 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; 203 assignment = statement.expression as AssignmentExpression;
215 ExpressionStatement expressionStatement =
216 statement as ExpressionStatement;
217 assignment = expressionStatement.expression as AssignmentExpression;
218 } 204 }
219 // get parameter 205 // get parameter
220 Expression rhs = assignment.rightHandSide; 206 Expression rhs = assignment.rightHandSide;
221 ParameterElement parameter = rhs.staticParameterElement; 207 ParameterElement parameter = rhs.staticParameterElement;
222 expect(parameter, isNotNull); 208 expect(parameter, isNotNull);
223 expect(parameter.displayName, "x"); 209 expect(parameter.displayName, "x");
224 // validate 210 // validate
225 ClassElement classA = unit.types[0]; 211 ClassElement classA = unit.element.types[0];
226 PropertyAccessorElement setter = classA.accessors[0]; 212 PropertyAccessorElement setter = classA.accessors[0];
227 expect(setter.parameters[0], same(parameter)); 213 expect(setter.parameters[0], same(parameter));
228 } 214 }
229 215
230 test_argumentResolution_setter_static_propertyAccess() async { 216 test_argumentResolution_setter_static_propertyAccess() async {
231 Source source = addSource(r''' 217 CompilationUnit unit = await resolveSource(r'''
232 main() { 218 main() {
233 A a = new A(); 219 A a = new A();
234 a.b.sss = 0; 220 a.b.sss = 0;
235 } 221 }
236 class A { 222 class A {
237 B b = new B(); 223 B b = new B();
238 } 224 }
239 class B { 225 class B {
240 set sss(x) {} 226 set sss(x) {}
241 }'''); 227 }''');
242 LibraryElement library = resolve2(source);
243 CompilationUnitElement unit = library.definingCompilationUnit;
244 // find "a.b.sss = 0" 228 // find "a.b.sss = 0"
245 AssignmentExpression assignment; 229 AssignmentExpression assignment;
246 { 230 {
247 FunctionElement mainElement = unit.functions[0]; 231 var statements = AstFinder.getStatementsInTopLevelFunction(unit, 'main');
248 FunctionBody mainBody = mainElement.computeNode().functionExpression.body; 232 var statement = statements[1] as ExpressionStatement;
249 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; 233 assignment = statement.expression as AssignmentExpression;
250 ExpressionStatement expressionStatement =
251 statement as ExpressionStatement;
252 assignment = expressionStatement.expression as AssignmentExpression;
253 } 234 }
254 // get parameter 235 // get parameter
255 Expression rhs = assignment.rightHandSide; 236 Expression rhs = assignment.rightHandSide;
256 ParameterElement parameter = rhs.staticParameterElement; 237 ParameterElement parameter = rhs.staticParameterElement;
257 expect(parameter, isNotNull); 238 expect(parameter, isNotNull);
258 expect(parameter.displayName, "x"); 239 expect(parameter.displayName, "x");
259 // validate 240 // validate
260 ClassElement classB = unit.types[1]; 241 ClassElement classB = unit.element.types[1];
261 PropertyAccessorElement setter = classB.accessors[0]; 242 PropertyAccessorElement setter = classB.accessors[0];
262 expect(setter.parameters[0], same(parameter)); 243 expect(setter.parameters[0], same(parameter));
263 } 244 }
264 245
265 test_breakTarget_labeled() async { 246 test_breakTarget_labeled() async {
266 // Verify that the target of the label is correctly found and is recorded 247 // Verify that the target of the label is correctly found and is recorded
267 // as the unlabeled portion of the statement. 248 // as the unlabeled portion of the statement.
268 String text = r''' 249 String text = r'''
269 void f() { 250 void f() {
270 loop1: while (true) { 251 loop1: while (true) {
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 class M2 { 715 class M2 {
735 get x => null; 716 get x => null;
736 set x(value) {} 717 set x(value) {}
737 } 718 }
738 class C extends B with M1, M2 { 719 class C extends B with M1, M2 {
739 void f() { 720 void f() {
740 x += 1; 721 x += 1;
741 } 722 }
742 } 723 }
743 '''); 724 ''');
744 LibraryElement library = resolve2(source); 725 var analysisResult = await computeAnalysisResult(source);
745 await computeAnalysisResult(source);
746 assertNoErrors(source); 726 assertNoErrors(source);
747 verify([source]); 727 verify([source]);
748 // Verify that both the getter and setter for "x" in C.f() refer to the 728 // Verify that both the getter and setter for "x" in C.f() refer to the
749 // accessors defined in M2. 729 // accessors defined in M2.
750 ClassElement classC = library.definingCompilationUnit.types[3]; 730 List<Statement> statements =
751 MethodDeclaration f = classC.getMethod('f').computeNode(); 731 AstFinder.getStatementsInMethod(analysisResult.unit, 'C', 'f');
752 BlockFunctionBody body = f.body; 732 var statement = statements[0] as ExpressionStatement;
753 ExpressionStatement stmt = body.block.statements[0]; 733 AssignmentExpression assignment = statement.expression;
754 AssignmentExpression assignment = stmt.expression;
755 SimpleIdentifier leftHandSide = assignment.leftHandSide; 734 SimpleIdentifier leftHandSide = assignment.leftHandSide;
756 expect( 735 expect(
757 resolutionMap 736 resolutionMap
758 .staticElementForIdentifier(leftHandSide) 737 .staticElementForIdentifier(leftHandSide)
759 .enclosingElement 738 .enclosingElement
760 .name, 739 .name,
761 'M2'); 740 'M2');
762 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name, 741 expect(leftHandSide.auxiliaryElements.staticElement.enclosingElement.name,
763 'M2'); 742 'M2');
764 } 743 }
765 744
766 @failingTest 745 @failingTest
767 test_getter_and_setter_fromMixins_property_access() async { 746 test_getter_and_setter_fromMixins_property_access() async {
768 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on 747 // TODO(paulberry): it appears that auxiliaryElements isn't properly set on
769 // a SimpleIdentifier that's inside a property access. This bug should be 748 // a SimpleIdentifier that's inside a property access. This bug should be
770 // fixed. 749 // fixed.
771 Source source = addSource(''' 750 Source source = addSource(r'''
772 class B {} 751 class B {}
773 class M1 { 752 class M1 {
774 get x => null; 753 get x => null;
775 set x(value) {} 754 set x(value) {}
776 } 755 }
777 class M2 { 756 class M2 {
778 get x => null; 757 get x => null;
779 set x(value) {} 758 set x(value) {}
780 } 759 }
781 class C extends B with M1, M2 {} 760 class C extends B with M1, M2 {}
782 void main() { 761 void main() {
783 new C().x += 1; 762 new C().x += 1;
784 } 763 }
785 '''); 764 ''');
786 LibraryElement library = resolve2(source); 765 var analysisResult = await computeAnalysisResult(source);
787 await computeAnalysisResult(source);
788 assertNoErrors(source); 766 assertNoErrors(source);
789 verify([source]); 767 verify([source]);
790 // Verify that both the getter and setter for "x" in "new C().x" refer to 768 // Verify that both the getter and setter for "x" in "new C().x" refer to
791 // the accessors defined in M2. 769 // the accessors defined in M2.
792 FunctionDeclaration main = 770 List<Statement> statements =
793 library.definingCompilationUnit.functions[0].computeNode(); 771 AstFinder.getStatementsInTopLevelFunction(analysisResult.unit, 'main');
794 BlockFunctionBody body = main.functionExpression.body; 772 var statement = statements[0] as ExpressionStatement;
795 ExpressionStatement stmt = body.block.statements[0]; 773 AssignmentExpression assignment = statement.expression;
796 AssignmentExpression assignment = stmt.expression;
797 PropertyAccess propertyAccess = assignment.leftHandSide; 774 PropertyAccess propertyAccess = assignment.leftHandSide;
798 expect( 775 expect(
799 resolutionMap 776 resolutionMap
800 .staticElementForIdentifier(propertyAccess.propertyName) 777 .staticElementForIdentifier(propertyAccess.propertyName)
801 .enclosingElement 778 .enclosingElement
802 .name, 779 .name,
803 'M2'); 780 'M2');
804 expect( 781 expect(
805 propertyAccess 782 propertyAccess
806 .propertyName.auxiliaryElements.staticElement.enclosingElement.name, 783 .propertyName.auxiliaryElements.staticElement.enclosingElement.name,
807 'M2'); 784 'M2');
808 } 785 }
809 786
810 test_getter_fromMixins_bare_identifier() async { 787 test_getter_fromMixins_bare_identifier() async {
811 Source source = addSource(''' 788 Source source = addSource('''
812 class B {} 789 class B {}
813 class M1 { 790 class M1 {
814 get x => null; 791 get x => null;
815 } 792 }
816 class M2 { 793 class M2 {
817 get x => null; 794 get x => null;
818 } 795 }
819 class C extends B with M1, M2 { 796 class C extends B with M1, M2 {
820 f() { 797 f() {
821 return x; 798 return x;
822 } 799 }
823 } 800 }
824 '''); 801 ''');
825 LibraryElement library = resolve2(source); 802 var analysisResult = await computeAnalysisResult(source);
826 await computeAnalysisResult(source);
827 assertNoErrors(source); 803 assertNoErrors(source);
828 verify([source]); 804 verify([source]);
829 // Verify that the getter for "x" in C.f() refers to the getter defined in 805 // Verify that the getter for "x" in C.f() refers to the getter defined in
830 // M2. 806 // M2.
831 ClassElement classC = library.definingCompilationUnit.types[3]; 807 var statements =
832 MethodDeclaration f = classC.getMethod('f').computeNode(); 808 AstFinder.getStatementsInMethod(analysisResult.unit, 'C', 'f');
833 BlockFunctionBody body = f.body; 809 var statement = statements[0] as ReturnStatement;
834 ReturnStatement stmt = body.block.statements[0]; 810 SimpleIdentifier x = statement.expression;
835 SimpleIdentifier x = stmt.expression;
836 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name, 811 expect(resolutionMap.staticElementForIdentifier(x).enclosingElement.name,
837 'M2'); 812 'M2');
838 } 813 }
839 814
840 test_getter_fromMixins_property_access() async { 815 test_getter_fromMixins_property_access() async {
841 Source source = addSource(''' 816 Source source = addSource('''
842 class B {} 817 class B {}
843 class M1 { 818 class M1 {
844 get x => null; 819 get x => null;
845 } 820 }
846 class M2 { 821 class M2 {
847 get x => null; 822 get x => null;
848 } 823 }
849 class C extends B with M1, M2 {} 824 class C extends B with M1, M2 {}
850 void main() { 825 void main() {
851 var y = new C().x; 826 var y = new C().x;
852 } 827 }
853 '''); 828 ''');
854 LibraryElement library = resolve2(source); 829 var analysisResult = await computeAnalysisResult(source);
855 await computeAnalysisResult(source);
856 assertNoErrors(source); 830 assertNoErrors(source);
857 verify([source]); 831 verify([source]);
858 // Verify that the getter for "x" in "new C().x" refers to the getter 832 // Verify that the getter for "x" in "new C().x" refers to the getter
859 // defined in M2. 833 // defined in M2.
860 FunctionDeclaration main = 834 List<Statement> statements =
861 library.definingCompilationUnit.functions[0].computeNode(); 835 AstFinder.getStatementsInTopLevelFunction(analysisResult.unit, 'main');
862 BlockFunctionBody body = main.functionExpression.body; 836 var statement = statements[0] as VariableDeclarationStatement;
863 VariableDeclarationStatement stmt = body.block.statements[0]; 837 PropertyAccess propertyAccess =
864 PropertyAccess propertyAccess = stmt.variables.variables[0].initializer; 838 statement.variables.variables[0].initializer;
865 expect( 839 expect(
866 resolutionMap 840 resolutionMap
867 .staticElementForIdentifier(propertyAccess.propertyName) 841 .staticElementForIdentifier(propertyAccess.propertyName)
868 .enclosingElement 842 .enclosingElement
869 .name, 843 .name,
870 'M2'); 844 'M2');
871 } 845 }
872 846
873 test_getterAndSetterWithDifferentTypes() async { 847 test_getterAndSetterWithDifferentTypes() async {
874 Source source = addSource(r''' 848 Source source = addSource(r'''
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 void f() {} 1538 void f() {}
1565 } 1539 }
1566 class M2 { 1540 class M2 {
1567 void f() {} 1541 void f() {}
1568 } 1542 }
1569 class C extends B with M1, M2 {} 1543 class C extends B with M1, M2 {}
1570 void main() { 1544 void main() {
1571 new C().f(); 1545 new C().f();
1572 } 1546 }
1573 '''); 1547 ''');
1574 LibraryElement library = resolve2(source); 1548 var analysisResult = await computeAnalysisResult(source);
1575 await computeAnalysisResult(source);
1576 assertNoErrors(source); 1549 assertNoErrors(source);
1577 verify([source]); 1550 verify([source]);
1578 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2. 1551 // Verify that the "f" in "new C().f()" refers to the "f" defined in M2.
1579 FunctionDeclaration main = 1552 List<Statement> statements =
1580 library.definingCompilationUnit.functions[0].computeNode(); 1553 AstFinder.getStatementsInTopLevelFunction(analysisResult.unit, 'main');
1581 BlockFunctionBody body = main.functionExpression.body; 1554 var statement = statements[0] as ExpressionStatement;
1582 ExpressionStatement stmt = body.block.statements[0]; 1555 MethodInvocation expr = statement.expression;
1583 MethodInvocation expr = stmt.expression;
1584 expect( 1556 expect(
1585 resolutionMap 1557 resolutionMap
1586 .staticElementForIdentifier(expr.methodName) 1558 .staticElementForIdentifier(expr.methodName)
1587 .enclosingElement 1559 .enclosingElement
1588 .name, 1560 .name,
1589 'M2'); 1561 'M2');
1590 } 1562 }
1591 1563
1592 test_method_fromMixins_bare_identifier() async { 1564 test_method_fromMixins_bare_identifier() async {
1593 Source source = addSource(''' 1565 Source source = addSource('''
1594 class B {} 1566 class B {}
1595 class M1 { 1567 class M1 {
1596 void f() {} 1568 void f() {}
1597 } 1569 }
1598 class M2 { 1570 class M2 {
1599 void f() {} 1571 void f() {}
1600 } 1572 }
1601 class C extends B with M1, M2 { 1573 class C extends B with M1, M2 {
1602 void g() { 1574 void g() {
1603 f(); 1575 f();
1604 } 1576 }
1605 } 1577 }
1606 '''); 1578 ''');
1607 LibraryElement library = resolve2(source); 1579 var analysisResult = await computeAnalysisResult(source);
1608 await computeAnalysisResult(source);
1609 assertNoErrors(source); 1580 assertNoErrors(source);
1610 verify([source]); 1581 verify([source]);
1611 // Verify that the call to f() in C.g() refers to the method defined in M2. 1582 // Verify that the call to f() in C.g() refers to the method defined in M2.
1612 ClassElement classC = library.definingCompilationUnit.types[3]; 1583 List<Statement> statements =
1613 MethodDeclaration g = classC.getMethod('g').computeNode(); 1584 AstFinder.getStatementsInMethod(analysisResult.unit, 'C', 'g');
1614 BlockFunctionBody body = g.body; 1585 var statement = statements[0] as ExpressionStatement;
1615 ExpressionStatement stmt = body.block.statements[0]; 1586 MethodInvocation invocation = statement.expression;
1616 MethodInvocation invocation = stmt.expression;
1617 SimpleIdentifier methodName = invocation.methodName; 1587 SimpleIdentifier methodName = invocation.methodName;
1618 expect( 1588 expect(
1619 resolutionMap 1589 resolutionMap
1620 .staticElementForIdentifier(methodName) 1590 .staticElementForIdentifier(methodName)
1621 .enclosingElement 1591 .enclosingElement
1622 .name, 1592 .name,
1623 'M2'); 1593 'M2');
1624 } 1594 }
1625 1595
1626 test_method_fromMixins_invked_from_outside_class() async { 1596 test_method_fromMixins_invoked_from_outside_class() async {
1627 Source source = addSource(''' 1597 Source source = addSource('''
1628 class B {} 1598 class B {}
1629 class M1 { 1599 class M1 {
1630 void f() {} 1600 void f() {}
1631 } 1601 }
1632 class M2 { 1602 class M2 {
1633 void f() {} 1603 void f() {}
1634 } 1604 }
1635 class C extends B with M1, M2 {} 1605 class C extends B with M1, M2 {}
1636 void main() { 1606 void main() {
1637 new C().f(); 1607 new C().f();
1638 } 1608 }
1639 '''); 1609 ''');
1640 LibraryElement library = resolve2(source); 1610 var analysisResult = await computeAnalysisResult(source);
1641 await computeAnalysisResult(source);
1642 assertNoErrors(source); 1611 assertNoErrors(source);
1643 verify([source]); 1612 verify([source]);
1644 // Verify that the call to f() in "new C().f()" refers to the method 1613 // Verify that the call to f() in "new C().f()" refers to the method
1645 // defined in M2. 1614 // defined in M2.
1646 FunctionDeclaration main = 1615 List<Statement> statements =
1647 library.definingCompilationUnit.functions[0].computeNode(); 1616 AstFinder.getStatementsInTopLevelFunction(analysisResult.unit, 'main');
1648 BlockFunctionBody body = main.functionExpression.body; 1617 var statement = statements[0] as ExpressionStatement;
1649 ExpressionStatement stmt = body.block.statements[0]; 1618 MethodInvocation invocation = statement.expression;
1650 MethodInvocation invocation = stmt.expression;
1651 expect( 1619 expect(
1652 resolutionMap 1620 resolutionMap
1653 .staticElementForIdentifier(invocation.methodName) 1621 .staticElementForIdentifier(invocation.methodName)
1654 .enclosingElement 1622 .enclosingElement
1655 .name, 1623 .name,
1656 'M2'); 1624 'M2');
1657 } 1625 }
1658 1626
1659 test_method_fromSuperclassMixin() async { 1627 test_method_fromSuperclassMixin() async {
1660 Source source = addSource(r''' 1628 Source source = addSource(r'''
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 } 1693 }
1726 class M2 { 1694 class M2 {
1727 set x(value) {} 1695 set x(value) {}
1728 } 1696 }
1729 class C extends B with M1, M2 { 1697 class C extends B with M1, M2 {
1730 void f() { 1698 void f() {
1731 x = 1; 1699 x = 1;
1732 } 1700 }
1733 } 1701 }
1734 '''); 1702 ''');
1735 LibraryElement library = resolve2(source); 1703 var analysisResult = await computeAnalysisResult(source);
1736 await computeAnalysisResult(source);
1737 assertNoErrors(source); 1704 assertNoErrors(source);
1738 verify([source]); 1705 verify([source]);
1739 // Verify that the setter for "x" in C.f() refers to the setter defined in 1706 // Verify that the setter for "x" in C.f() refers to the setter defined in
1740 // M2. 1707 // M2.
1741 ClassElement classC = library.definingCompilationUnit.types[3]; 1708 List<Statement> statements =
1742 MethodDeclaration f = classC.getMethod('f').computeNode(); 1709 AstFinder.getStatementsInMethod(analysisResult.unit, 'C', 'f');
1743 BlockFunctionBody body = f.body; 1710 var statement = statements[0] as ExpressionStatement;
1744 ExpressionStatement stmt = body.block.statements[0]; 1711 AssignmentExpression assignment = statement.expression;
1745 AssignmentExpression assignment = stmt.expression;
1746 SimpleIdentifier leftHandSide = assignment.leftHandSide; 1712 SimpleIdentifier leftHandSide = assignment.leftHandSide;
1747 expect( 1713 expect(
1748 resolutionMap 1714 resolutionMap
1749 .staticElementForIdentifier(leftHandSide) 1715 .staticElementForIdentifier(leftHandSide)
1750 .enclosingElement 1716 .enclosingElement
1751 .name, 1717 .name,
1752 'M2'); 1718 'M2');
1753 } 1719 }
1754 1720
1755 test_setter_fromMixins_property_access() async { 1721 test_setter_fromMixins_property_access() async {
1756 Source source = addSource(''' 1722 Source source = addSource('''
1757 class B {} 1723 class B {}
1758 class M1 { 1724 class M1 {
1759 set x(value) {} 1725 set x(value) {}
1760 } 1726 }
1761 class M2 { 1727 class M2 {
1762 set x(value) {} 1728 set x(value) {}
1763 } 1729 }
1764 class C extends B with M1, M2 {} 1730 class C extends B with M1, M2 {}
1765 void main() { 1731 void main() {
1766 new C().x = 1; 1732 new C().x = 1;
1767 } 1733 }
1768 '''); 1734 ''');
1769 LibraryElement library = resolve2(source); 1735 var analysisResult = await computeAnalysisResult(source);
1770 await computeAnalysisResult(source);
1771 assertNoErrors(source); 1736 assertNoErrors(source);
1772 verify([source]); 1737 verify([source]);
1773 // 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
1774 // defined in M2. 1739 // defined in M2.
1775 FunctionDeclaration main = 1740 List<Statement> statements =
1776 library.definingCompilationUnit.functions[0].computeNode(); 1741 AstFinder.getStatementsInTopLevelFunction(analysisResult.unit, 'main');
1777 BlockFunctionBody body = main.functionExpression.body; 1742 var statement = statements[0] as ExpressionStatement;
1778 ExpressionStatement stmt = body.block.statements[0]; 1743 AssignmentExpression assignment = statement.expression;
1779 AssignmentExpression assignment = stmt.expression;
1780 PropertyAccess propertyAccess = assignment.leftHandSide; 1744 PropertyAccess propertyAccess = assignment.leftHandSide;
1781 expect( 1745 expect(
1782 resolutionMap 1746 resolutionMap
1783 .staticElementForIdentifier(propertyAccess.propertyName) 1747 .staticElementForIdentifier(propertyAccess.propertyName)
1784 .enclosingElement 1748 .enclosingElement
1785 .name, 1749 .name,
1786 'M2'); 1750 'M2');
1787 } 1751 }
1788 1752
1789 test_setter_inherited() async { 1753 test_setter_inherited() async {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 // check propagated type 1868 // check propagated type
1905 FunctionType propagatedType = node.propagatedType as FunctionType; 1869 FunctionType propagatedType = node.propagatedType as FunctionType;
1906 expect(propagatedType.returnType, test.typeProvider.stringType); 1870 expect(propagatedType.returnType, test.typeProvider.stringType);
1907 } on AnalysisException catch (e, stackTrace) { 1871 } on AnalysisException catch (e, stackTrace) {
1908 thrownException[0] = new CaughtException(e, stackTrace); 1872 thrownException[0] = new CaughtException(e, stackTrace);
1909 } 1873 }
1910 } 1874 }
1911 return null; 1875 return null;
1912 } 1876 }
1913 } 1877 }
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