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 ccc339094d32..a7b367619761 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 @@ -480,8 +480,24 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { if (myType2 == mLPAREN) { createSpaceInCode(mySettings.SPACE_BEFORE_METHOD_PARENTHESES); } - else if (myType1 == mLPAREN || myType2 == mRPAREN) { - createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES); + else if (myType1 == mLPAREN && myType2 == mRPAREN) { + createSpaceInCode(mySettings.SPACE_WITHIN_EMPTY_METHOD_PARENTHESES); + } + else if (myType1 == mLPAREN) { + if (mySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE) { + createDependentLFSpacing(mySettings.SPACE_WITHIN_METHOD_PARENTHESES, method.getParameterList().getTextRange()); + } + else { + createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES); + } + } + else if (myType2 == mRPAREN) { + if (mySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE) { + createDependentLFSpacing(mySettings.SPACE_WITHIN_METHOD_PARENTHESES, method.getParameterList().getTextRange()); + } + else { + createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES); + } } else if (myType1 == mRPAREN && myType2 == THROW_CLAUSE) { if (mySettings.THROWS_KEYWORD_WRAP == CommonCodeStyleSettings.WRAP_ALWAYS) { @@ -509,6 +525,11 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { } } + private void createDependentLFSpacing(boolean space, @NotNull TextRange range) { + myResult = Spacing + .createDependentLFSpacing(space ? 1 : 0, space ? 1 : 0, range, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + private void manageSpaceBeforeTypeParameters() { createSpaceInCode(false); } 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 422c165d0467..e649c315aedc 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 @@ -478,6 +478,57 @@ def cl = { ''') } + void testLineFeedsInMethodParams0() { + groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true + checkFormatting('''\ +def foo(String s, +int x) {} +''', '''\ +def foo( + String s, + int x) {} +''') + } + + void testLineFeedsInMethodParams1() { + groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true + checkFormatting('''\ +def foo(String s, +int x) {} +''', '''\ +def foo(String s, + int x +) {} +''') + } + + void testLineFeedsInMethodParams2() { + groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true + groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true + checkFormatting('''\ +def foo(String s, +int x) {} +''', '''\ +def foo( + String s, + int x +) {} +''') + } + + void testLineFeedsInMethodParams3() { + groovySettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true + groovySettings.METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = true + groovySettings.SPACE_WITHIN_METHOD_PARENTHESES = true + checkFormatting('''\ +def foo(String s, int x) {} +''', '''\ +def foo( String s, int x ) {} +''') + } + + + private void doGeeseTest() { GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class); boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;