Skip to content

Commit 8a92058

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Support omitted name args; fix as-expressions, refactor tests
Fixes #38919 Change-Id: Ia302e7d56aa20ebd1d9b7afa8ceda249ba31015b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/122021 Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
1 parent 45358c5 commit 8a92058

File tree

2 files changed

+129
-175
lines changed

2 files changed

+129
-175
lines changed

pkg/analysis_server/lib/src/edit/nnbd_migration/info_builder.dart

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ class InfoBuilder {
7777
return units;
7878
}
7979

80-
/// Return details for a fix built from the given [edge], or `null` if the
81-
/// edge does not have an origin.
82-
String _baseDescriptionForOrigin(AstNode node) {
80+
/// Return detail text for a fix built from an edge with [node] as a
81+
/// destination.
82+
String _baseDescriptionForOrigin(EdgeOriginInfo origin) {
83+
AstNode node = origin.node;
84+
AstNode parent = node.parent;
85+
8386
if (node is DefaultFormalParameter) {
8487
Expression defaultValue = node.defaultValue;
8588
if (defaultValue == null) {
@@ -104,10 +107,11 @@ class InfoBuilder {
104107
}
105108
return "This field is initialized by a field formal parameter and a "
106109
"nullable value is passed as an argument";
110+
} else if (parent is AsExpression) {
111+
return "The value of the expression is nullable";
107112
}
108113
String nullableValue =
109114
node is NullLiteral ? "an explicit 'null'" : "a nullable value";
110-
AstNode parent = node.parent;
111115
if (parent is ArgumentList) {
112116
return capitalize("$nullableValue is passed as an argument");
113117
}
@@ -161,20 +165,21 @@ class InfoBuilder {
161165
return "This $mapOrSet is initialized with $nullableValue on line "
162166
"$lineNumber";
163167
}
168+
} else if (node is InvocationExpression &&
169+
origin.kind == EdgeOriginKind.namedParameterNotSupplied) {
170+
return "This named parameter was omitted in a call to this function";
164171
} else if (parent is VariableDeclaration) {
165172
AstNode grandparent = parent.parent?.parent;
166173
if (grandparent is FieldDeclaration) {
167174
return "This field is initialized to $nullableValue";
168175
}
169176
return "This variable is initialized to $nullableValue";
170-
} else if (parent is AsExpression) {
171-
return "The value of the expression is nullable";
172177
}
173178
return capitalize("$nullableValue is assigned");
174179
}
175180

176-
/// Return details for a fix built from the given [edge], or `null` if the
177-
/// edge does not have an origin.
181+
/// Return detail text for a fix built from an edge with [node] as a
182+
/// destination.
178183
String _buildDescriptionForDestination(AstNode node) {
179184
// Other found types:
180185
// - ConstructorDeclaration
@@ -186,9 +191,9 @@ class InfoBuilder {
186191
}
187192

188193
/// Return a description of the given [origin].
189-
String _buildDescriptionForOrigin(AstNode origin) {
194+
String _buildDescriptionForOrigin(EdgeOriginInfo origin) {
190195
String description = _baseDescriptionForOrigin(origin);
191-
if (_inTestCode(origin)) {
196+
if (_inTestCode(origin.node)) {
192197
// TODO(brianwilkerson) Don't add this if the graph node with which the
193198
// origin is associated is also in test code.
194199
description += " in test code";
@@ -225,7 +230,7 @@ class InfoBuilder {
225230
}
226231
target = _targetForNode(origin.source.fullName, node);
227232
}
228-
return RegionDetail(_buildDescriptionForOrigin(node), target);
233+
return RegionDetail(_buildDescriptionForOrigin(origin), target);
229234
}
230235

231236
/// Compute the details for the fix with the given [fixInfo].

0 commit comments

Comments
 (0)