mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:56:57 +00:00
[analysis_server] Insert "required" keyword in created methods/added named parameters
Fixes https://github.com/Dart-Code/Dart-Code/issues/3770. Change-Id: I954b9bbcac72ffc7a7b6e168214971bf1786872a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228564 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
230bdbd229
commit
32b3e18e92
|
@ -29,11 +29,9 @@ main() {
|
|||
new A(1, b: 2, named: 3.0);
|
||||
}
|
||||
''');
|
||||
// TODO(brianwilkerson) The fix should make added named parameters be
|
||||
// `required`. I'm leaving it as is to match the current behavior.
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
A(int a, {int b = 0, double named}) {}
|
||||
A(int a, {int b = 0, required double named}) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
@ -54,7 +52,7 @@ main() {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
A(int a, {double named}) {}
|
||||
A(int a, {required double named}) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
@ -75,7 +73,7 @@ main() {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
A({int named}) {}
|
||||
A({required int named}) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
@ -96,7 +94,7 @@ main() {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
A.aaa({int named}) {}
|
||||
A.aaa({required int named}) {}
|
||||
}
|
||||
|
||||
main() {
|
||||
|
@ -114,7 +112,7 @@ main() {
|
|||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
test(int a, {int b: 0, double named}) {}
|
||||
test(int a, {int b: 0, required double named}) {}
|
||||
|
||||
main() {
|
||||
test(1, b: 2, named: 3.0);
|
||||
|
@ -131,7 +129,7 @@ main() {
|
|||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
test(int a, {double named}) {}
|
||||
test(int a, {required double named}) {}
|
||||
|
||||
main() {
|
||||
test(1, named: 2.0);
|
||||
|
@ -148,7 +146,7 @@ main() {
|
|||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
test({int named}) {}
|
||||
test({required int named}) {}
|
||||
|
||||
main() {
|
||||
test(named: 42);
|
||||
|
@ -168,7 +166,7 @@ class A {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
test(int a, {int b: 0, double named}) {}
|
||||
test(int a, {int b: 0, required double named}) {}
|
||||
|
||||
main() {
|
||||
test(1, b: 2, named: 3.0);
|
||||
|
@ -202,7 +200,7 @@ class A {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
test(int a, {double named}) {}
|
||||
test(int a, {required double named}) {}
|
||||
|
||||
main() {
|
||||
test(1, named: 2.0);
|
||||
|
@ -223,7 +221,7 @@ class A {
|
|||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
test({int named}) {}
|
||||
test({required int named}) {}
|
||||
|
||||
main() {
|
||||
test(named: 42);
|
||||
|
|
|
@ -415,17 +415,21 @@ class A {
|
|||
await resolveTestCode('''
|
||||
class A {
|
||||
void f() {
|
||||
myUndefinedMethod(0, bbb: 1.0, ccc: '2');
|
||||
var c = '2';
|
||||
int? d;
|
||||
myUndefinedMethod(0, bbb: 1.0, ccc: c, ddd: d);
|
||||
}
|
||||
}
|
||||
''');
|
||||
await assertHasFix('''
|
||||
class A {
|
||||
void f() {
|
||||
myUndefinedMethod(0, bbb: 1.0, ccc: '2');
|
||||
var c = '2';
|
||||
int? d;
|
||||
myUndefinedMethod(0, bbb: 1.0, ccc: c, ddd: d);
|
||||
}
|
||||
|
||||
void myUndefinedMethod(int i, {double bbb, String ccc}) {}
|
||||
void myUndefinedMethod(int i, {required double bbb, required String ccc, int? ddd}) {}
|
||||
}
|
||||
''');
|
||||
// linked positions
|
||||
|
|
|
@ -578,9 +578,15 @@ class DartEditBuilderImpl extends EditBuilderImpl implements DartEditBuilder {
|
|||
Expression argument, int index, Set<String> usedNames) {
|
||||
// append type name
|
||||
var type = argument.staticType;
|
||||
var library = dartFileEditBuilder.resolvedUnit.libraryElement;
|
||||
if (type == null || type.isBottom || type.isDartCoreNull) {
|
||||
type = DynamicTypeImpl.instance;
|
||||
}
|
||||
if (argument is NamedExpression &&
|
||||
library.isNonNullableByDefault &&
|
||||
type.nullabilitySuffix == NullabilitySuffix.none) {
|
||||
write('required ');
|
||||
}
|
||||
if (writeType(type, addSupertypeProposals: true, groupName: 'TYPE$index')) {
|
||||
write(' ');
|
||||
}
|
||||
|
|
|
@ -1145,7 +1145,10 @@ f(int i, String s) {
|
|||
});
|
||||
});
|
||||
var edit = getEdit(builder);
|
||||
expect(edit.replacement, equalsIgnoringWhitespace('String s, {int index}'));
|
||||
var expectedReplacement = this is WithoutNullSafetyMixin
|
||||
? 'String s, {int index}'
|
||||
: 'String s, {required int index}';
|
||||
expect(edit.replacement, equalsIgnoringWhitespace(expectedReplacement));
|
||||
}
|
||||
|
||||
Future<void> test_writeParametersMatchingArguments_required() async {
|
||||
|
|
Loading…
Reference in a new issue