diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java index d197328b06a4..d64e5857b677 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java @@ -302,8 +302,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { public void visitOpenBlock(GrOpenBlock block) { final PsiElement parent = block.getParent(); - boolean keepInOneLine = parent instanceof GrMethod ? - mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE : + boolean keepInOneLine = parent instanceof GrMethod ? mySettings.KEEP_SIMPLE_METHODS_IN_ONE_LINE : mySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE; if (myType1 == mLCURLY && myType2 == mRCURLY) { @@ -717,6 +716,9 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE); } } + else if (myType1 == mRPAREN) { + createSpacingBeforeElementInsideControlStatement(); + } } private static boolean isOpenBlock(IElementType type) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy index 9d90dfc69b78..5bd71489bc98 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy @@ -306,6 +306,46 @@ if (abc) {return 2} if (abc) { return 2 } +''') + } + + void testControlStatementsInOneLine() { + groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true + checkFormatting('''\ +if (abc) return 2 +''', '''\ +if (abc) return 2 +''') + checkFormatting('''\ +while (abc) return 2 +''', '''\ +while (abc) return 2 +''') + checkFormatting('''\ +for (abc) return 2 +''', '''\ +for (abc) return 2 +''') + + groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false + checkFormatting('''\ +if (abc) return 2 +''', '''\ +if (abc) + return 2 +''') + checkFormatting('''\ +while (abc) return 2 +''', '''\ +while (abc) + return 2 +''') + + checkFormatting('''\ +for (;abc;) return 2 +''', '''\ +for (; abc;) + return 2 ''') }