-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See: #55917 Change-Id: I2dbe760dd0d123fc4b1bf493c8f7699baaea376c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370503 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
- Loading branch information
Showing
6 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
pkg/analysis_server/lib/src/services/correction/dart/replace_colon_with_in.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analysis_server/src/services/correction/fix.dart'; | ||
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart'; | ||
import 'package:analyzer/src/generated/source.dart'; | ||
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart'; | ||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; | ||
|
||
class ReplaceColonWithIn extends ResolvedCorrectionProducer { | ||
ReplaceColonWithIn({required super.context}); | ||
|
||
@override | ||
CorrectionApplicability get applicability => | ||
CorrectionApplicability.automatically; | ||
|
||
@override | ||
FixKind get fixKind => DartFixKind.REPLACE_COLON_WITH_IN; | ||
|
||
@override | ||
FixKind get multiFixKind => DartFixKind.REPLACE_COLON_WITH_IN_MULTI; | ||
|
||
@override | ||
Future<void> compute(ChangeBuilder builder) async { | ||
var diagnostic = this.diagnostic; | ||
if (diagnostic == null) return; | ||
|
||
await builder.addDartFileEdit(file, (builder) { | ||
builder.addSimpleReplacement( | ||
SourceRange(diagnostic.problemMessage.offset, 1), 'in'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
pkg/analysis_server/test/src/services/correction/fix/replace_colon_with_in_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:analysis_server/src/services/correction/fix.dart'; | ||
import 'package:analyzer_plugin/utilities/fixes/fixes.dart'; | ||
import 'package:test_reflective_loader/test_reflective_loader.dart'; | ||
|
||
import 'fix_processor.dart'; | ||
|
||
void main() { | ||
defineReflectiveSuite(() { | ||
defineReflectiveTests(ReplaceColonWithInTest); | ||
}); | ||
} | ||
|
||
@reflectiveTest | ||
class ReplaceColonWithInTest extends FixProcessorTest { | ||
@override | ||
FixKind get kind => DartFixKind.REPLACE_COLON_WITH_IN; | ||
|
||
Future<void> test_colonInPlaceOfIn() async { | ||
await resolveTestCode(''' | ||
void f() { | ||
for (var _ : []) {} | ||
} | ||
'''); | ||
await assertHasFix(''' | ||
void f() { | ||
for (var _ in []) {} | ||
} | ||
'''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters