Updates to prepare for analyzer 'name' breaking changes.

Change-Id: I0ef4226d30f923996a29af0d8f22c59c0e52f3a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254464
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Konstantin Shcheglov 2022-08-10 20:17:31 +00:00 committed by Commit Bot
parent 10bf1cfe58
commit 67f33caa5f
3 changed files with 49 additions and 48 deletions

View file

@ -3170,8 +3170,8 @@ class C {
var x = f();
}
''');
var xType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var xType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
assertEdge(decoratedTypeAnnotation('int').node, xType.node, hard: false);
}
@ -4675,8 +4675,8 @@ main() {
var x = f();
}
''');
var xType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var xType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
assertEdge(decoratedTypeAnnotation('int').node, xType.node, hard: false);
}
@ -8026,8 +8026,8 @@ double get myPi => pi;
int f() => 1;
var x = f();
''');
var xType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var xType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
assertEdge(decoratedTypeAnnotation('int').node, xType.node, hard: false);
}

View file

@ -727,7 +727,7 @@ enum E {
C
}
''');
var enumConstant = findNode.simple('B').parent!;
var enumConstant = findNode.enumConstantDeclaration('B');
var changes = checkPlan(planner!.removeNode(enumConstant), '''
enum E {
A,
@ -743,7 +743,7 @@ class C {
int? x, y, z;
}
''');
var declaration = findNode.simple('y').parent!;
var declaration = findNode.variableDeclaration('y');
var changes = checkPlan(planner!.removeNode(declaration), '''
class C {
int? x, z;
@ -923,7 +923,7 @@ class C {
Future<void> test_remove_parameter() async {
await analyze('f(int x, int y, int z) => null;');
var parameter = findNode.simple('y').parent!;
var parameter = findNode.simpleFormalParameter('y');
var changes =
checkPlan(planner!.removeNode(parameter), 'f(int x, int z) => null;');
expect(changes.keys, [parameter.offset]);
@ -1229,14 +1229,14 @@ C<int, String>? c;
Future<void> test_remove_type_parameter() async {
await analyze('class C<T, U, V> {}');
var parameter = findNode.simple('U').parent!;
var parameter = findNode.typeParameter('U');
var changes = checkPlan(planner!.removeNode(parameter), 'class C<T, V> {}');
expect(changes.keys, [parameter.offset]);
}
Future<void> test_remove_variable_declaration() async {
await analyze('int? x, y, z;');
var declaration = findNode.simple('y').parent!;
var declaration = findNode.variableDeclaration('y');
var changes = checkPlan(planner!.removeNode(declaration), 'int? x, z;');
expect(changes.keys, [declaration.offset]);
}

View file

@ -36,11 +36,11 @@ void f() {
try {} on String catch (ex, st) {}
}
''');
var exceptionType =
variables.decoratedElementType(findNode.simple('ex').staticElement!);
var exceptionType = variables.decoratedElementType(
findNode.catchClauseParameter('ex').declaredElement!);
expect(exceptionType.node, TypeMatcher<NullabilityNodeMutable>());
var stackTraceType =
variables.decoratedElementType(findNode.simple('st').staticElement!);
var stackTraceType = variables.decoratedElementType(
findNode.catchClauseParameter('st').declaredElement!);
assertEdge(stackTraceType.node, never, hard: true, checkable: false);
}
@ -50,11 +50,11 @@ void f() {
try {} catch (ex, st) {}
}
''');
var exceptionType =
variables.decoratedElementType(findNode.simple('ex').staticElement!);
var exceptionType = variables.decoratedElementType(
findNode.catchClauseParameter('ex').declaredElement!);
expect(exceptionType.node!.isImmutable, false);
var stackTraceType =
variables.decoratedElementType(findNode.simple('st').staticElement!);
var stackTraceType = variables.decoratedElementType(
findNode.catchClauseParameter('st').declaredElement!);
assertEdge(stackTraceType.node, never, hard: true, checkable: false);
}
@ -74,8 +74,8 @@ void f() {
try {} on String catch (ex) {}
}
''');
var exceptionType =
variables.decoratedElementType(findNode.simple('ex').staticElement!);
var exceptionType = variables.decoratedElementType(
findNode.catchClauseParameter('ex').declaredElement!);
expect(exceptionType.node, TypeMatcher<NullabilityNodeMutable>());
}
@ -85,8 +85,8 @@ void f() {
try {} catch (ex) {}
}
''');
var exceptionType =
variables.decoratedElementType(findNode.simple('ex').staticElement!);
var exceptionType = variables.decoratedElementType(
findNode.catchClauseParameter('ex').declaredElement!);
expect(exceptionType.node!.isImmutable, false);
}
@ -483,7 +483,8 @@ f(void Function() g) {
''');
expect(
variables
.decoratedElementType(findNode.simple('e)').staticElement!)
.decoratedElementType(
findNode.catchClauseParameter('e)').declaredElement!)
.node!
.displayName,
'f.e (test.dart:4:5)');
@ -683,8 +684,8 @@ class C {
var x;
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}
@ -694,8 +695,8 @@ class C {
var x = 1;
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
}
@ -706,8 +707,8 @@ class C {
var x = f();
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}
@ -1546,8 +1547,8 @@ main() {
var x;
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}
@ -1557,8 +1558,8 @@ main() {
var x = 1;
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
}
@ -1569,8 +1570,8 @@ main() {
var x = f();
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}
@ -1580,8 +1581,8 @@ main() {
var x = () => 1;
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.returnType!.node!.displayName,
'return type of main.x (test.dart:2:7)');
}
@ -1592,8 +1593,8 @@ main() {
var x = {1: 2};
}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.typeArguments[0]!.node!.displayName,
'type argument 0 of main.x (test.dart:2:7)');
expect(decoratedType.typeArguments[1]!.node!.displayName,
@ -1803,8 +1804,8 @@ void foo({List<int> values}) {
await analyze('''
void f(x) {}
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.simpleFormalParameter('x').declaredElement!);
expect(decoratedFunctionType('f').positionalParameters![0],
same(decoratedType));
expect(decoratedType.type!.isDynamic, isTrue);
@ -1913,8 +1914,8 @@ int f() => 0;
await analyze('''
var x;
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}
@ -1922,8 +1923,8 @@ var x;
await analyze('''
var x = 1;
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node, TypeMatcher<NullabilityNodeMutable>());
}
@ -1932,8 +1933,8 @@ var x = 1;
dynamic f() {}
var x = f();
''');
var decoratedType =
variables.decoratedElementType(findNode.simple('x').staticElement!);
var decoratedType = variables.decoratedElementType(
findNode.variableDeclaration('x').declaredElement2!);
expect(decoratedType.node!.isImmutable, false);
}