Indent content of when (KT-14066)

#KT-14066 Fixed
This commit is contained in:
Nikolay Krasko
2018-06-21 15:58:00 +03:00
parent dc8a3ab534
commit 1973860e70
8 changed files with 130 additions and 10 deletions
@@ -660,8 +660,9 @@ private val INDENT_RULES = arrayOf(
.within(KtNodeTypes.BODY).notForType(KtNodeTypes.BLOCK)
.set(Indent.getNormalIndent()),
strategy("For the entry in when")
.forType(KtNodeTypes.WHEN_ENTRY)
strategy("For WHEN content")
.within(KtNodeTypes.WHEN)
.notForType(RBRACE, LBRACE, WHEN_KEYWORD)
.set(Indent.getNormalIndent()),
strategy("For single statement in THEN and ELSE")
+2 -2
View File
@@ -22,14 +22,14 @@ fun some(x: Any) {
}
when
(true) {
(true) {
}
when
(true) {
(true) {
}
+2 -2
View File
@@ -22,14 +22,14 @@ fun some(x: Any) {
}
when
(true) {
(true) {
}
when
(true) {
(true) {
}
+56
View File
@@ -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
View File
@@ -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
}
}
@@ -4,10 +4,10 @@ fun test(obj: Any): String {
return when (obj) {
is String -> "string" // return "string"
// it's an Int
// it's an Int
is Int -> "int"
// otherwise
// otherwise
else -> "unknown"
}
}
@@ -4,10 +4,10 @@ fun test(obj: Any): String {
return when {
obj is String -> "string" // return "string"
// it's an Int
// it's an Int
obj is Int -> "int"
// otherwise
// otherwise
else -> "unknown"
}
}
@@ -741,6 +741,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
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")
public void testWhenEntryExpr() throws Exception {
runTest("idea/testData/formatter/WhenEntryExpr.after.kt");