Skip to content

Commit 9f59f46

Browse files
committed
Fix an exception in the changeArgumentName quick fix (issue 36440)
Change-Id: Ide70f8535798829e208b482c79c6f97cd414a829 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98438 Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
1 parent 0d0f591 commit 9f59f46

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

pkg/analysis_server/lib/src/services/correction/fix_internal.dart

+8-4
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ class FixProcessor {
11461146
sessionHelper,
11471147
namedExpression.parent.parent,
11481148
);
1149-
return parameters.namedNames;
1149+
return parameters?.namedNames;
11501150
}
11511151
return null;
11521152
}
@@ -4541,11 +4541,15 @@ class _ExecutableParameters {
45414541
factory _ExecutableParameters(
45424542
AnalysisSessionHelper sessionHelper, AstNode invocation) {
45434543
Element element;
4544-
if (invocation is InstanceCreationExpression) {
4544+
// This doesn't handle FunctionExpressionInvocation.
4545+
if (invocation is Annotation) {
4546+
element = invocation.element;
4547+
} else if (invocation is InstanceCreationExpression) {
45454548
element = invocation.staticElement;
4546-
}
4547-
if (invocation is MethodInvocation) {
4549+
} else if (invocation is MethodInvocation) {
45484550
element = invocation.methodName.staticElement;
4551+
} else if (invocation is ConstructorReferenceNode) {
4552+
element = invocation.staticElement;
45494553
}
45504554
if (element is ExecutableElement && !element.isSynthetic) {
45514555
return new _ExecutableParameters._(sessionHelper, element);

pkg/analysis_server/test/src/services/correction/fix/change_argument_name_test.dart

+51
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ class A {
117117
''');
118118
}
119119

120+
test_default_annotation() async {
121+
await resolveTestUnit('''
122+
@A(boot: 2)
123+
f() => null;
124+
class A {
125+
const A({int boat});
126+
}
127+
''');
128+
await assertHasFix('''
129+
@A(boat: 2)
130+
f() => null;
131+
class A {
132+
const A({int boat});
133+
}
134+
''');
135+
}
136+
120137
test_default_constructor() async {
121138
await resolveTestUnit('''
122139
f() => new A(boot: 2);
@@ -166,6 +183,40 @@ class A {
166183
''');
167184
}
168185

186+
test_default_redirectingConstructor() async {
187+
await resolveTestUnit('''
188+
class A {
189+
A.one() : this.two(boot: 3);
190+
A.two({int boat});
191+
}
192+
''');
193+
await assertHasFix('''
194+
class A {
195+
A.one() : this.two(boat: 3);
196+
A.two({int boat});
197+
}
198+
''');
199+
}
200+
201+
test_default_superConstructor() async {
202+
await resolveTestUnit('''
203+
class A {
204+
A.a({int boat});
205+
}
206+
class B extends A {
207+
B.b() : super.a(boot: 3);
208+
}
209+
''');
210+
await assertHasFix('''
211+
class A {
212+
A.a({int boat});
213+
}
214+
class B extends A {
215+
B.b() : super.a(boat: 3);
216+
}
217+
''');
218+
}
219+
169220
test_tooDistant_constructor() async {
170221
await resolveTestUnit('''
171222
f() => new A(bbbbb: 2);

0 commit comments

Comments
 (0)