From 300601da54a837b02ca5ca48789cea7ec7f2404a Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 6 Dec 2016 20:10:47 +0300 Subject: [PATCH] Indent () in if, when, while and do-while with continuation indent (KT-5897) #KT-5897 Fixed --- .../kotlin/idea/formatter/KotlinCommonBlock.kt | 5 +++++ .../InBinaryExpressionUnfinishedInIf.after.inv.kt | 6 ++++++ .../InBinaryExpressionUnfinishedInIf.after.kt | 6 ++++++ .../InBinaryExpressionUnfinishedInIf.kt | 5 +++++ .../TypingIndentationTestBaseGenerated.java | 12 ++++++++++++ 5 files changed, 34 insertions(+) create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.inv.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.kt create mode 100644 idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.kt diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index 7426904880b..e29f21dcad8 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -368,6 +368,11 @@ private val INDENT_RULES = arrayOf( .`in`(KtNodeTypes.PARENTHESIZED) .set(Indent.getContinuationWithoutFirstIndent(false)), + strategy("Round Brackets around conditions") + .forType(LPAR, RPAR) + .`in`(KtNodeTypes.IF, KtNodeTypes.WHEN_ENTRY, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE) + .set(Indent.getContinuationWithoutFirstIndent(true)), + strategy("KDoc comment indent") .`in`(KDOC_CONTENT) .forType(KDocTokens.LEADING_ASTERISK, KDocTokens.END) diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.inv.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.inv.kt new file mode 100644 index 00000000000..e51996dd936 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.inv.kt @@ -0,0 +1,6 @@ +fun test() { + if (true && + ) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.kt new file mode 100644 index 00000000000..e51996dd936 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.kt @@ -0,0 +1,6 @@ +fun test() { + if (true && + ) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.kt b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.kt new file mode 100644 index 00000000000..f061a239155 --- /dev/null +++ b/idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.kt @@ -0,0 +1,5 @@ +fun test() { + if (true &&) +} + +// SET_TRUE: ALIGN_MULTILINE_BINARY_OPERATION \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java index b1c20d4792a..73489d5c7db 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/TypingIndentationTestBaseGenerated.java @@ -146,6 +146,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio doNewlineTest(fileName); } + @TestMetadata("InBinaryExpressionUnfinishedInIf.after.kt") + public void testInBinaryExpressionUnfinishedInIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.kt"); + doNewlineTest(fileName); + } + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.kt") public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.kt"); @@ -374,6 +380,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio doNewlineTestWithInvert(fileName); } + @TestMetadata("InBinaryExpressionUnfinishedInIf.after.inv.kt") + public void testInBinaryExpressionUnfinishedInIf() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/InBinaryExpressionUnfinishedInIf.after.inv.kt"); + doNewlineTestWithInvert(fileName); + } + @TestMetadata("InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt") public void testInBinaryExpressionsBeforeCloseParenthesis() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/InBinaryExpressionsBeforeCloseParenthesis.after.inv.kt");