Options for blank lines between 'when' branches

#KT-18607 Fixed
This commit is contained in:
Dmitry Jemerov
2017-06-22 14:59:09 +02:00
parent 8fe2858c6a
commit 6a96ade02c
8 changed files with 72 additions and 12 deletions
@@ -43,6 +43,7 @@ public class KotlinCodeStyleSettings extends CustomCodeStyleSettings {
public boolean CONTINUATION_INDENT_IN_PARAMETER_LISTS = true;
public boolean CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = true;
public boolean CONTINUATION_INDENT_FOR_CHAINED_CALLS = true;
public int BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES = 0;
public KotlinCodeStyleSettings(CodeStyleSettings container) {
super("JetCodeStyleSettings", container);
@@ -31,10 +31,7 @@ import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings
import org.jetbrains.kotlin.idea.formatter.KotlinSpacingBuilder.CustomSpacingBuilder
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.*
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtFunction
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.textRangeWithoutComments
val MODIFIERS_LIST_ENTRIES = TokenSet.orSet(TokenSet.create(ANNOTATION_ENTRY, ANNOTATION), MODIFIER_KEYWORDS)
@@ -256,8 +253,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
betweenInside(REFERENCE_EXPRESSION, LAMBDA_ARGUMENT, CALL_EXPRESSION).spaces(1)
betweenInside(TYPE_ARGUMENT_LIST, LAMBDA_ARGUMENT, CALL_EXPRESSION).spaces(1)
between(WHEN_ENTRY, WHEN_ENTRY).lineBreakInCode()
around(COLONCOLON).spaces(0)
around(BY_KEYWORD).spaces(1)
@@ -373,6 +368,17 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
inPosition(right = CLASS_BODY).customRule(leftBraceRule(blockType = CLASS_BODY))
inPosition(left = WHEN_ENTRY, right = WHEN_ENTRY).customRule { _, left, right ->
val leftEntry = left.node.psi as KtWhenEntry
val rightEntry = right.node.psi as KtWhenEntry
val blankLines = if (leftEntry.expression is KtBlockExpression || rightEntry.expression is KtBlockExpression)
settings.kotlinSettings.BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES
else
0
createSpacing(0, minLineFeeds = blankLines + 1)
}
inPosition(parent = WHEN_ENTRY, right = BLOCK).customRule(leftBraceRule())
inPosition(parent = WHEN, right = LBRACE).customRule {
parent, _, _ ->