diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt index c21cf5b92fe..d964fcf5f46 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt +++ b/idea/src/org/jetbrains/jet/plugin/formatter/KotlinSpacingBuilder.kt @@ -67,11 +67,12 @@ class KotlinSpacingBuilder(val codeStyleSettings: CodeStyleSettings) { return this } - fun lineBreakIfLineBreakInParent(numSpacesOtherwise: Int) { + fun lineBreakIfLineBreakInParent(numSpacesOtherwise: Int, allowBlankLines: Boolean = true) { newRule { p, l, r -> Spacing.createDependentLFSpacing(numSpacesOtherwise, numSpacesOtherwise, p.getTextRange(), - codeStyleSettings.KEEP_LINE_BREAKS, codeStyleSettings.KEEP_BLANK_LINES_IN_CODE) + codeStyleSettings.KEEP_LINE_BREAKS, + if (allowBlankLines) codeStyleSettings.KEEP_BLANK_LINES_IN_CODE else 0) } } @@ -191,7 +192,7 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { fun CustomSpacingBuilder.ruleForKeywordOnNewLine(shouldBeOnNewLine: Boolean, keyword: IElementType, parent: IElementType) { if (shouldBeOnNewLine) { inPosition(parent = parent, right = keyword) - .lineBreakIfLineBreakInParent(numSpacesOtherwise = 1) + .lineBreakIfLineBreakInParent(numSpacesOtherwise = 1, allowBlankLines = false) } else { inPosition(parent = parent, right = keyword).customRule { diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt b/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt index cfb992229c6..17c081566a7 100644 --- a/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt +++ b/idea/testData/formatter/CatchFinallyOnNewLine.after.inv.kt @@ -8,6 +8,11 @@ fun f() { } catch (e: E) { } finally { } + + try { + } catch (e: E) { + } finally { + } } // SET_TRUE: CATCH_ON_NEW_LINE diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.after.kt b/idea/testData/formatter/CatchFinallyOnNewLine.after.kt index b1e18121c0a..8cb1f5aff53 100644 --- a/idea/testData/formatter/CatchFinallyOnNewLine.after.kt +++ b/idea/testData/formatter/CatchFinallyOnNewLine.after.kt @@ -12,6 +12,13 @@ fun f() { } finally { } + + try { + } + catch (e: E) { + } + finally { + } } // SET_TRUE: CATCH_ON_NEW_LINE diff --git a/idea/testData/formatter/CatchFinallyOnNewLine.kt b/idea/testData/formatter/CatchFinallyOnNewLine.kt index 34539aec936..9cdd58681e6 100644 --- a/idea/testData/formatter/CatchFinallyOnNewLine.kt +++ b/idea/testData/formatter/CatchFinallyOnNewLine.kt @@ -10,6 +10,15 @@ fun f() { } catch (e: E) { } finally { } + + try { + } + + catch (e: E) { + } + + finally { + } } // SET_TRUE: CATCH_ON_NEW_LINE diff --git a/idea/testData/formatter/ElseOnNewLine.after.inv.kt b/idea/testData/formatter/ElseOnNewLine.after.inv.kt index ca818120398..1ca5bb29fa8 100644 --- a/idea/testData/formatter/ElseOnNewLine.after.inv.kt +++ b/idea/testData/formatter/ElseOnNewLine.after.inv.kt @@ -5,6 +5,11 @@ fun f() { } + if (true) { + } else if (true) { + } else { + } + if (true) { } else if (true) { } else { diff --git a/idea/testData/formatter/ElseOnNewLine.after.kt b/idea/testData/formatter/ElseOnNewLine.after.kt index d2d7b24c5d0..b825764c755 100644 --- a/idea/testData/formatter/ElseOnNewLine.after.kt +++ b/idea/testData/formatter/ElseOnNewLine.after.kt @@ -7,6 +7,13 @@ fun f() { } + if (true) { + } + else if (true) { + } + else { + } + if (true) { } else if (true) { diff --git a/idea/testData/formatter/ElseOnNewLine.kt b/idea/testData/formatter/ElseOnNewLine.kt index 3efd2786fbf..ec198f5bde3 100644 --- a/idea/testData/formatter/ElseOnNewLine.kt +++ b/idea/testData/formatter/ElseOnNewLine.kt @@ -12,6 +12,15 @@ fun f() { } else { } + if (true) { + } + + else if (true) { + } + + else { + } + if (a) 3 else 4 if (a) 5 diff --git a/idea/testData/formatter/WhileOnNewLine.after.inv.kt b/idea/testData/formatter/WhileOnNewLine.after.inv.kt index 4c9863a3243..e49bacb4d85 100644 --- a/idea/testData/formatter/WhileOnNewLine.after.inv.kt +++ b/idea/testData/formatter/WhileOnNewLine.after.inv.kt @@ -7,6 +7,10 @@ fun f() { } while (true) + do { + + } while (true) + do a += 1 while (true) do a += 1 diff --git a/idea/testData/formatter/WhileOnNewLine.after.kt b/idea/testData/formatter/WhileOnNewLine.after.kt index d8413603c1b..afe58fad538 100644 --- a/idea/testData/formatter/WhileOnNewLine.after.kt +++ b/idea/testData/formatter/WhileOnNewLine.after.kt @@ -9,6 +9,11 @@ fun f() { } while (true) + do { + + } + while (true) + do a += 1 while (true) do a += 1 diff --git a/idea/testData/formatter/WhileOnNewLine.kt b/idea/testData/formatter/WhileOnNewLine.kt index 90fc6f22dfe..b50abd03a39 100644 --- a/idea/testData/formatter/WhileOnNewLine.kt +++ b/idea/testData/formatter/WhileOnNewLine.kt @@ -8,6 +8,12 @@ fun f() { } while (true) + do { + + } + + while (true) + do a += 1 while (true) do a += 1