Add when branches: remove unnecessary blank line
#KT-30426 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
c1984d92ff
commit
cbdc79fcda
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
+13
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user