Fix bug in convertIntoBlockBody
I ran across this bug while testing to see what work was already done.
I didn't take the time to create an issue.
The bug is that an assist was being offered for `class C ^{}` to
convert the class body into a block. The result, for an empty block,
was just to add an extra space before the block body. For a non-empty
block, the result was to delete everything inside the block.
Change-Id: I0342b681ef67b5e659a00126a998d63d593223fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508702
Reviewed-by: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
@@ -82,10 +82,12 @@ class ConvertIntoBlockBody extends ResolvedCorrectionProducer {
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
var bodyRange = body.sourceRange;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(bodyRange, ' {}');
|
||||
});
|
||||
if (body is EmptyClassBody || body is EmptyEnumBody) {
|
||||
var bodyRange = body.sourceRange;
|
||||
await builder.addDartFileEdit(file, (builder) {
|
||||
builder.addSimpleReplacement(bodyRange, ' {}');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _computeMissingFunctionBody(
|
||||
|
||||
+38
@@ -80,6 +80,13 @@ class C {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_container_class_block() async {
|
||||
await resolveTestCode('''
|
||||
class C ^{}
|
||||
''');
|
||||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_container_enum() async {
|
||||
await resolveTestCode(
|
||||
'''
|
||||
@@ -92,6 +99,16 @@ enum E {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_container_enum_block() async {
|
||||
await resolveTestCode(
|
||||
'''
|
||||
enum E ^{}
|
||||
''',
|
||||
ignore: [diag.enumWithoutConstants],
|
||||
);
|
||||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_container_extension() async {
|
||||
await resolveTestCode('''
|
||||
extension E on int^;
|
||||
@@ -101,6 +118,13 @@ extension E on int {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_container_extension_block() async {
|
||||
await resolveTestCode('''
|
||||
extension E on int ^{}
|
||||
''');
|
||||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_container_extensionType() async {
|
||||
await resolveTestCode('''
|
||||
extension type ^E(int i);
|
||||
@@ -110,6 +134,13 @@ extension type E(int i) {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_container_extensionType_block() async {
|
||||
await resolveTestCode('''
|
||||
extension type E(int i) ^{}
|
||||
''');
|
||||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_container_mixin() async {
|
||||
await resolveTestCode('''
|
||||
mixin M^;
|
||||
@@ -119,6 +150,13 @@ mixin M {}
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_container_mixin_block() async {
|
||||
await resolveTestCode('''
|
||||
mixin M ^{}
|
||||
''');
|
||||
await assertNoAssist();
|
||||
}
|
||||
|
||||
Future<void> test_inExpression() async {
|
||||
await resolveTestCode('''
|
||||
void f() => ^123;
|
||||
|
||||
Reference in New Issue
Block a user