Add when branches: remove unnecessary blank line

#KT-30426 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-03-20 10:07:32 +09:00
committed by Mikhail Glukhikh
parent c1984d92ff
commit cbdc79fcda
6 changed files with 60 additions and 1 deletions
@@ -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 ->
@@ -0,0 +1,11 @@
// "Add remaining branches" "true"
// WITH_RUNTIME
sealed class A
class B : A()
fun test(a: A) {
val r = <caret>when (a) {
}
}
@@ -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()
}
}
@@ -0,0 +1,13 @@
// "Add remaining branches" "true"
// WITH_RUNTIME
sealed class A
class B : A()
fun test(a: A) {
val r = <caret>when (a) {
// comment
}
}
@@ -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()
}
}
@@ -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");