Add formatting rule "new line between { and when entry"
This commit is contained in:
@@ -469,6 +469,10 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
|||||||
spacingForLeftBrace(block = parent.requireNode(), blockType = WHEN)
|
spacingForLeftBrace(block = parent.requireNode(), blockType = WHEN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inPosition(left = LBRACE, right = WHEN_ENTRY).customRule { _, _, _ ->
|
||||||
|
createSpacing(0, minLineFeeds = 1)
|
||||||
|
}
|
||||||
|
|
||||||
val spacesInSimpleFunction = if (kotlinCustomSettings.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD) 1 else 0
|
val spacesInSimpleFunction = if (kotlinCustomSettings.INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD) 1 else 0
|
||||||
inPosition(parent = FUNCTION_LITERAL,
|
inPosition(parent = FUNCTION_LITERAL,
|
||||||
left = LBRACE,
|
left = LBRACE,
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
|||||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||||
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||||
import org.jetbrains.kotlin.idea.intentions.ImportAllMembersIntention
|
import org.jetbrains.kotlin.idea.intentions.ImportAllMembersIntention
|
||||||
import org.jetbrains.kotlin.idea.refactoring.isMultiLine
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
@@ -80,10 +79,6 @@ class AddWhenRemainingBranchesFix(
|
|||||||
val elseBranch = element.entries.find { it.isElse }
|
val elseBranch = element.entries.find { it.isElse }
|
||||||
val psiFactory = KtPsiFactory(element)
|
val psiFactory = KtPsiFactory(element)
|
||||||
|
|
||||||
if (missingCases.isNotEmpty() && !element.isMultiLine()) {
|
|
||||||
element.addBefore(psiFactory.createNewLine(), whenCloseBrace)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (case in missingCases) {
|
for (case in missingCases) {
|
||||||
val branchConditionText = when (case) {
|
val branchConditionText = when (case) {
|
||||||
UnknownMissingCase, NullMissingCase, is BooleanMissingCase ->
|
UnknownMissingCase, NullMissingCase, is BooleanMissingCase ->
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo(x: Int) = when (x) {
|
||||||
|
1 -> 2
|
||||||
|
3 -> 4
|
||||||
|
else -> 6
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo(x: Int) = when(x) { 1 -> 2
|
||||||
|
3 -> 4
|
||||||
|
else -> 6
|
||||||
|
}
|
||||||
@@ -746,6 +746,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
runTest("idea/testData/formatter/WhenBlockBlankLines.after.kt");
|
runTest("idea/testData/formatter/WhenBlockBlankLines.after.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("WhenBraceAndEntry.after.kt")
|
||||||
|
public void testWhenBraceAndEntry() throws Exception {
|
||||||
|
runTest("idea/testData/formatter/WhenBraceAndEntry.after.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("WhenComment.after.kt")
|
@TestMetadata("WhenComment.after.kt")
|
||||||
public void testWhenComment() throws Exception {
|
public void testWhenComment() throws Exception {
|
||||||
runTest("idea/testData/formatter/WhenComment.after.kt");
|
runTest("idea/testData/formatter/WhenComment.after.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user