Skip to content

Commit e5b70a7

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate StrongModeStaticTypeAnalyzer2Test and related.
Change-Id: I28a9aa2a4ff9e2928d5732cf5265fb483f2d2524 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396385 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 9f0968a commit e5b70a7

File tree

6 files changed

+176
-144
lines changed

6 files changed

+176
-144
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,9 @@ test/generated/elements_types_mixin.dart
176176
test/generated/invalid_code_test.dart
177177
test/generated/issues_test.dart
178178
test/generated/non_error_resolver_test.dart
179-
test/generated/resolver_test.dart
180179
test/generated/resolver_test_case.dart
181180
test/generated/simple_resolver_test.dart
182181
test/generated/static_type_analyzer_test.dart
183-
test/generated/strong_mode_test.dart
184182
test/generated/type_system_test.dart
185183
test/id_tests/assigned_variables_test.dart
186184
test/id_tests/constant_test.dart
@@ -271,4 +269,3 @@ test/src/wolf/ir/ast_to_ir_test.dart
271269
test/util/element_printer.dart
272270
test/util/element_type_matchers.dart
273271
test/util/id_testing_helper.dart
274-
test/utils.dart

pkg/analyzer/lib/src/test_utilities/find_element2.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class FindElement2 extends _FindElementBase {
144144
updateResult(node.declaredElement2!);
145145
},
146146
variableDeclaration: (node) {
147-
updateResult(node.declaredElement2!);
147+
updateResult(node.declaredFragment!.element);
148148
},
149149
));
150150

pkg/analyzer/test/generated/resolver_test.dart

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,22 @@ int f() {
151151
@reflectiveTest
152152
class TypePropagationTest extends PubPackageResolutionTest {
153153
test_assignment_null() async {
154-
String code = r'''
154+
await resolveTestCode(r'''
155155
main() {
156156
int v; // declare
157157
v = null;
158158
return v; // return
159-
}''';
160-
await resolveTestCode(code);
161-
assertType(findElement.localVar('v').type, 'int');
162-
assertType(findNode.simple('v; // return'), 'int');
159+
}
160+
''');
161+
162+
var node = findNode.simple('v; // return');
163+
assertResolvedNodeText(node, r'''
164+
SimpleIdentifier
165+
token: v
166+
staticElement: v@15
167+
element: v@15
168+
staticType: int
169+
''');
163170
}
164171

165172
test_initializer_hasStaticType() async {
@@ -168,8 +175,15 @@ f() {
168175
int v = 0;
169176
return v;
170177
}''');
171-
assertType(findElement.localVar('v').type, 'int');
172-
assertType(findNode.simple('v;'), 'int');
178+
179+
var node = findNode.simple('v;');
180+
assertResolvedNodeText(node, r'''
181+
SimpleIdentifier
182+
token: v
183+
staticElement: v@12
184+
element: v@12
185+
staticType: int
186+
''');
173187
}
174188

175189
test_initializer_hasStaticType_parameterized() async {
@@ -178,8 +192,15 @@ f() {
178192
List<int> v = <int>[];
179193
return v;
180194
}''');
181-
assertType(findElement.localVar('v').type, 'List<int>');
182-
assertType(findNode.simple('v;'), 'List<int>');
195+
196+
var node = findNode.simple('v;');
197+
assertResolvedNodeText(node, r'''
198+
SimpleIdentifier
199+
token: v
200+
staticElement: v@18
201+
element: v@18
202+
staticType: List<int>
203+
''');
183204
}
184205

185206
test_initializer_null() async {
@@ -188,23 +209,36 @@ main() {
188209
int v = null;
189210
return v;
190211
}''');
191-
assertType(findElement.localVar('v').type, 'int');
192-
assertType(findNode.simple('v;'), 'int');
212+
213+
var node = findNode.simple('v;');
214+
assertResolvedNodeText(node, r'''
215+
SimpleIdentifier
216+
token: v
217+
staticElement: v@15
218+
element: v@15
219+
staticType: int
220+
''');
193221
}
194222

195223
test_invocation_target_prefixed() async {
196224
newFile('$testPackageLibPath/a.dart', r'''
197225
int max(int x, int y) => 0;
198226
''');
227+
199228
await resolveTestCode('''
200229
import 'a.dart' as helper;
201230
main() {
202231
helper.max(10, 10); // marker
203232
}''');
204-
assertElement(
205-
findNode.simple('max(10, 10)'),
206-
findElement.importFind('package:test/a.dart').topFunction('max'),
207-
);
233+
234+
var node = findNode.simple('max(10, 10)');
235+
assertResolvedNodeText(node, r'''
236+
SimpleIdentifier
237+
token: max
238+
staticElement: package:test/a.dart::<fragment>::@function::max
239+
element: package:test/a.dart::@function::max
240+
staticType: int Function(int, int)
241+
''');
208242
}
209243

210244
test_is_subclass() async {
@@ -219,10 +253,27 @@ A f(A p) {
219253
}
220254
return p;
221255
}''');
222-
assertElement(
223-
findNode.methodInvocation('p.m()'),
224-
findElement.method('m', of: 'B'),
225-
);
256+
257+
var node = findNode.methodInvocation('p.m()');
258+
assertResolvedNodeText(node, r'''
259+
MethodInvocation
260+
target: SimpleIdentifier
261+
token: p
262+
staticElement: <testLibraryFragment>::@function::f::@parameter::p
263+
element: <testLibraryFragment>::@function::f::@parameter::p#element
264+
staticType: B
265+
operator: .
266+
methodName: SimpleIdentifier
267+
token: m
268+
staticElement: <testLibraryFragment>::@class::B::@method::m
269+
element: <testLibraryFragment>::@class::B::@method::m#element
270+
staticType: B Function()
271+
argumentList: ArgumentList
272+
leftParenthesis: (
273+
rightParenthesis: )
274+
staticInvokeType: B Function()
275+
staticType: B
276+
''');
226277
}
227278

228279
test_mutatedOutsideScope() async {
@@ -296,8 +347,15 @@ main() {
296347
dynamic toString = () => null;
297348
toString(); // marker
298349
}''');
299-
assertTypeDynamic(findElement.localVar('toString').type);
300-
assertTypeDynamic(findNode.simple('toString(); // marker'));
350+
351+
var node = findNode.simple('toString(); // marker');
352+
assertResolvedNodeText(node, r'''
353+
SimpleIdentifier
354+
token: toString
355+
staticElement: toString@19
356+
element: toString@19
357+
staticType: dynamic
358+
''');
301359
}
302360

303361
@failingTest

0 commit comments

Comments
 (0)