REMOVE_UNNECESSARY_CAST to be in bulk.

Fixes #47156

Change-Id: Id285c38b01124f8c404185a58c6b98bda87cefe1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212823
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Ahmed Ashour 2021-09-29 17:01:50 +00:00 committed by commit-bot@chromium.org
parent 7b4714d355
commit 65db608726
2 changed files with 26 additions and 3 deletions

View file

@ -11,7 +11,7 @@ import 'package:analyzer_plugin/utilities/range_factory.dart';
class RemoveUnnecessaryCast extends CorrectionProducer {
@override
bool get canBeAppliedInBulk => false;
bool get canBeAppliedInBulk => true;
@override
bool get canBeAppliedToFile => true;

View file

@ -11,11 +11,34 @@ import 'fix_processor.dart';
void main() {
defineReflectiveSuite(() {
defineReflectiveTests(RemoveUnnecessaryCastBulkTest);
defineReflectiveTests(RemoveUnnecessaryCastMultiTest);
defineReflectiveTests(RemoveUnnecessaryCastTest);
});
}
@reflectiveTest
class RemoveUnnecessaryCastBulkTest extends BulkFixProcessorTest {
Future<void> test_assignment() async {
await resolveTestCode('''
void f(Object p) {
if (p is String) {
var v = (p as String) as String;
print(v);
}
}
''');
await assertHasFix('''
void f(Object p) {
if (p is String) {
var v = p;
print(v);
}
}
''');
}
}
@reflectiveTest
class RemoveUnnecessaryCastMultiTest extends FixProcessorTest {
@override
@ -25,7 +48,7 @@ class RemoveUnnecessaryCastMultiTest extends FixProcessorTest {
await resolveTestCode('''
void f(Object p, Object q) {
if (p is String) {
String v = ((p as String));
var v = (p as String) as String;
print(v);
}
if (q is int) {
@ -37,7 +60,7 @@ void f(Object p, Object q) {
await assertHasFixAllFix(HintCode.UNNECESSARY_CAST, '''
void f(Object p, Object q) {
if (p is String) {
String v = p;
var v = p;
print(v);
}
if (q is int) {