Indent content of when (KT-14066)
#KT-14066 Fixed
This commit is contained in:
@@ -660,8 +660,9 @@ private val INDENT_RULES = arrayOf(
|
|||||||
.within(KtNodeTypes.BODY).notForType(KtNodeTypes.BLOCK)
|
.within(KtNodeTypes.BODY).notForType(KtNodeTypes.BLOCK)
|
||||||
.set(Indent.getNormalIndent()),
|
.set(Indent.getNormalIndent()),
|
||||||
|
|
||||||
strategy("For the entry in when")
|
strategy("For WHEN content")
|
||||||
.forType(KtNodeTypes.WHEN_ENTRY)
|
.within(KtNodeTypes.WHEN)
|
||||||
|
.notForType(RBRACE, LBRACE, WHEN_KEYWORD)
|
||||||
.set(Indent.getNormalIndent()),
|
.set(Indent.getNormalIndent()),
|
||||||
|
|
||||||
strategy("For single statement in THEN and ELSE")
|
strategy("For single statement in THEN and ELSE")
|
||||||
|
|||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
fun foo(i: Int) {
|
||||||
|
when {
|
||||||
|
// line
|
||||||
|
1 -> 2
|
||||||
|
|
||||||
|
// One line before
|
||||||
|
|
||||||
|
2 -> 3
|
||||||
|
|
||||||
|
// Many lines before
|
||||||
|
|
||||||
|
|
||||||
|
3 -> 4
|
||||||
|
|
||||||
|
|
||||||
|
/* Block */
|
||||||
|
4 -> 5
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Block multiline
|
||||||
|
*/
|
||||||
|
5 -> 6
|
||||||
|
|
||||||
|
/** Doc */
|
||||||
|
6 -> 7
|
||||||
|
}
|
||||||
|
|
||||||
|
when { // Assigned to entry
|
||||||
|
1 -> 2
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
// Line
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
/* Block */
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
/**
|
||||||
|
* Doc
|
||||||
|
*/
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
1 ->
|
||||||
|
2 // Two
|
||||||
|
else ->
|
||||||
|
43 // 42
|
||||||
|
}
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
fun foo(i: Int) {
|
||||||
|
when {
|
||||||
|
// line
|
||||||
|
1 -> 2
|
||||||
|
|
||||||
|
// One line before
|
||||||
|
|
||||||
|
2 -> 3
|
||||||
|
|
||||||
|
// Many lines before
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
3 -> 4
|
||||||
|
|
||||||
|
|
||||||
|
/* Block */
|
||||||
|
4 -> 5
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Block multiline
|
||||||
|
*/
|
||||||
|
5 -> 6
|
||||||
|
|
||||||
|
/** Doc */
|
||||||
|
6 -> 7
|
||||||
|
}
|
||||||
|
|
||||||
|
when { // Assigned to entry
|
||||||
|
1 -> 2
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
// Line
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
/* Block */
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
/**
|
||||||
|
* Doc
|
||||||
|
*/
|
||||||
|
else -> 8
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
1 ->
|
||||||
|
2 // Two
|
||||||
|
else ->
|
||||||
|
43 // 42
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -741,6 +741,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
|||||||
runTest("idea/testData/formatter/WhenBlockBlankLines.after.kt");
|
runTest("idea/testData/formatter/WhenBlockBlankLines.after.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("WhenComment.after.kt")
|
||||||
|
public void testWhenComment() throws Exception {
|
||||||
|
runTest("idea/testData/formatter/WhenComment.after.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("WhenEntryExpr.after.kt")
|
@TestMetadata("WhenEntryExpr.after.kt")
|
||||||
public void testWhenEntryExpr() throws Exception {
|
public void testWhenEntryExpr() throws Exception {
|
||||||
runTest("idea/testData/formatter/WhenEntryExpr.after.kt");
|
runTest("idea/testData/formatter/WhenEntryExpr.after.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user