File tree Expand file tree Collapse file tree 3 files changed +57
-5
lines changed
lib/src/services/correction
test/src/services/correction/fix/data_driven Expand file tree Collapse file tree 3 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -126,7 +126,9 @@ class ModifyParameters extends Change<_Data> {
126
126
// that the parameter was absent.
127
127
var index = reference is PositionalFormalParameterReference
128
128
? reference.index
129
- : remainingArguments.last + 1 ;
129
+ : remainingArguments.isNotEmpty
130
+ ? remainingArguments.last + 1
131
+ : 0 ;
130
132
remainingArguments.add (index);
131
133
indexToNewArgumentMap[index] = modification;
132
134
argumentsToInsert.add (index);
@@ -229,11 +231,13 @@ class ModifyParameters extends Change<_Data> {
229
231
offset = arguments[remainingIndex - 1 ].end;
230
232
needsInitialComma = true ;
231
233
} else {
232
- offset = arguments[remainingIndex].offset;
234
+ offset = arguments.isNotEmpty
235
+ ? arguments[remainingIndex].offset
236
+ : argumentList.leftParenthesis.end;
233
237
}
234
238
builder.addInsertion (offset, (builder) {
235
239
writeInsertionRange (builder, insertionRange, needsInitialComma);
236
- if (insertionIndex == 0 ) {
240
+ if (insertionIndex == 0 && arguments.isNotEmpty ) {
237
241
builder.write (', ' );
238
242
}
239
243
});
Original file line number Diff line number Diff line change @@ -855,6 +855,9 @@ class FixProcessor extends BaseProcessor {
855
855
CompileTimeErrorCode .INVALID_OVERRIDE_SETTER : [
856
856
DataDriven .new ,
857
857
],
858
+ CompileTimeErrorCode .MISSING_REQUIRED_ARGUMENT : [
859
+ DataDriven .new ,
860
+ ],
858
861
CompileTimeErrorCode .MIXIN_OF_NON_CLASS : [
859
862
DataDriven .new ,
860
863
ImportLibrary .forType,
Original file line number Diff line number Diff line change @@ -2321,6 +2321,51 @@ void f() {
2321
2321
Future <void >
2322
2322
test_services_ClipboardData_changeParameterNonNullAbsent () async {
2323
2323
setPackageContent ('''
2324
+ class ClipboardData {
2325
+ const ClipboardData({required String this.text});
2326
+
2327
+ final String? text;
2328
+ }
2329
+ ''' );
2330
+
2331
+ addPackageDataFile ('''
2332
+ version: 1
2333
+ transforms:
2334
+ - title: "Migrate to empty 'text' string"
2335
+ date: 2023-04-19
2336
+ element:
2337
+ uris: ['$importUri ']
2338
+ constructor: ''
2339
+ inClass: 'ClipboardData'
2340
+ changes:
2341
+ - kind: 'changeParameterType'
2342
+ name: 'text'
2343
+ nullability: non_null
2344
+ argumentValue:
2345
+ expression: "''"
2346
+ ''' );
2347
+
2348
+ await resolveTestCode ('''
2349
+ import '$importUri ';
2350
+
2351
+ void f() {
2352
+ var c = ClipboardData();
2353
+ print(c);
2354
+ }
2355
+ ''' );
2356
+ await assertHasFix ('''
2357
+ import '$importUri ';
2358
+
2359
+ void f() {
2360
+ var c = ClipboardData(text: '');
2361
+ print(c);
2362
+ }
2363
+ ''' );
2364
+ }
2365
+
2366
+ Future <void >
2367
+ test_services_ClipboardData_changeParameterNonNullAdditional () async {
2368
+ setPackageContent ('''
2324
2369
class ClipboardData {
2325
2370
const ClipboardData({required String this.text, String? this.p});
2326
2371
@@ -2350,15 +2395,15 @@ transforms:
2350
2395
import '$importUri ';
2351
2396
2352
2397
void f() {
2353
- var c = ClipboardData(p: 'hello', text: null );
2398
+ var c = ClipboardData(text: null, p: 'hello' );
2354
2399
print(c);
2355
2400
}
2356
2401
''' );
2357
2402
await assertHasFix ('''
2358
2403
import '$importUri ';
2359
2404
2360
2405
void f() {
2361
- var c = ClipboardData(p : 'hello ', text : '');
2406
+ var c = ClipboardData(text : '', p : 'hello ');
2362
2407
print(c);
2363
2408
}
2364
2409
''' );
You can’t perform that action at this time.
0 commit comments