diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenRemainingBranchesFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenRemainingBranchesFix.kt index b5751b5757d..99763e93c81 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenRemainingBranchesFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenRemainingBranchesFix.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project +import com.intellij.psi.PsiWhiteSpace import org.jetbrains.kotlin.cfg.* import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassKind @@ -78,7 +79,7 @@ class AddWhenRemainingBranchesFix( val whenCloseBrace = element.closeBrace ?: throw AssertionError("isAvailable should check if close brace exist") val elseBranch = element.entries.find { it.isElse } val psiFactory = KtPsiFactory(element) - + (whenCloseBrace.prevSibling as? PsiWhiteSpace)?.replace(psiFactory.createNewLine()) for (case in missingCases) { val branchConditionText = when (case) { UnknownMissingCase, NullMissingCase, is BooleanMissingCase -> diff --git a/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt b/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt new file mode 100644 index 00000000000..1e2aa5103a7 --- /dev/null +++ b/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt @@ -0,0 +1,11 @@ +// "Add remaining branches" "true" +// WITH_RUNTIME + +sealed class A +class B : A() + +fun test(a: A) { + val r = when (a) { + + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt.after b/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt.after new file mode 100644 index 00000000000..24224cf3fb7 --- /dev/null +++ b/idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt.after @@ -0,0 +1,11 @@ +// "Add remaining branches" "true" +// WITH_RUNTIME + +sealed class A +class B : A() + +fun test(a: A) { + val r = when (a) { + is B -> TODO() + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt b/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt new file mode 100644 index 00000000000..56ed09eb019 --- /dev/null +++ b/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt @@ -0,0 +1,13 @@ +// "Add remaining branches" "true" +// WITH_RUNTIME + +sealed class A +class B : A() + +fun test(a: A) { + val r = when (a) { + + // comment + + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt.after b/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt.after new file mode 100644 index 00000000000..f235164b968 --- /dev/null +++ b/idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt.after @@ -0,0 +1,13 @@ +// "Add remaining branches" "true" +// WITH_RUNTIME + +sealed class A +class B : A() + +fun test(a: A) { + val r = when (a) { + + // comment + is B -> TODO() + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 98aab500f96..23cf26b68ae 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -13775,6 +13775,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/when/addElseBranchEnumStatement.kt"); } + @TestMetadata("addRemainingBranchesBlankLine.kt") + public void testAddRemainingBranchesBlankLine() throws Exception { + runTest("idea/testData/quickfix/when/addRemainingBranchesBlankLine.kt"); + } + + @TestMetadata("addRemainingBranchesBlankLineWithComment.kt") + public void testAddRemainingBranchesBlankLineWithComment() throws Exception { + runTest("idea/testData/quickfix/when/addRemainingBranchesBlankLineWithComment.kt"); + } + @TestMetadata("addRemainingBranchesBoolean.kt") public void testAddRemainingBranchesBoolean() throws Exception { runTest("idea/testData/quickfix/when/addRemainingBranchesBoolean.kt");