diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java index fbb9959baa63..32b0d1631ec6 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovyIndentProcessor.java @@ -272,6 +272,9 @@ public class GroovyIndentProcessor extends GroovyElementVisitor { if (myChildType == PARAMETERS_LIST) { myResult = Indent.getContinuationIndent(); } + else if (myChildType == THROW_CLAUSE) { + myResult = getGroovySettings(method).ALIGN_THROWS_KEYWORD ? Indent.getNoneIndent() : Indent.getContinuationIndent(); + } } @Override 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 d64e5857b677..f042ebb83634 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 @@ -397,7 +397,12 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { createSpaceInCode(mySettings.SPACE_WITHIN_METHOD_PARENTHESES); } else if (myType1 == mRPAREN && myType2 == THROW_CLAUSE) { - createSpaceInCode(true); + if (mySettings.THROWS_KEYWORD_WRAP == CommonCodeStyleSettings.WRAP_ALWAYS) { + createLF(); + } + else { + createSpaceInCode(true); + } } else if (isOpenBlock(myType2)) { PsiElement methodName = method.getNameIdentifier(); @@ -713,7 +718,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { } else if (mySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE) { myResult = Spacing.createDependentLFSpacing(1, 1, myParent.getTextRange(), false, mySettings.KEEP_BLANK_LINES_IN_CODE); } else { - myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE); + createLF(); } } else if (myType1 == mRPAREN) { @@ -837,10 +842,14 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { mySettings.KEEP_BLANK_LINES_IN_CODE); } else { - myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE); + createLF(); } } + private void createLF() { + myResult = Spacing.createSpacing(0, 0, 1, false, mySettings.KEEP_BLANK_LINES_IN_CODE); + } + private Spacing createNonLFSpace(int spaces, @Nullable final TextRange dependantRange, final boolean keepLineBreaks) { final ASTNode prev = getPrevElementType(myChild2); if (prev != null && prev.getElementType() == mSL_COMMENT) { 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 5bd71489bc98..aa258ec47e41 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 @@ -43,7 +43,11 @@ public class FormatterTest extends GroovyFormatterTestCase { public void testArg2() throws Throwable { doTest(); } public void testBin1() throws Throwable { doTest(); } public void testBin2() throws Throwable { doTest(); } - public void testBlockExpr1() throws Throwable { doTest(); } + public void testBlockExpr1() throws Throwable { + //groovySettings.KEEP_CONTROL_STATEMENT_IN_ONE_LINE = false + groovySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false + doTest(); + } public void testClass1() throws Throwable { doTest(); } public void testClo1() throws Throwable { doTest(); } public void testClo2() throws Throwable { doTest(); } @@ -109,7 +113,10 @@ public class FormatterTest extends GroovyFormatterTestCase { public void testWhileCStyle() throws Throwable { doTest(); } public void testFields() throws Throwable { doTest(); } - public void testClosureAfterLineComment() throws Throwable { doTest(); } + public void testClosureAfterLineComment() throws Throwable { + groovySettings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false + doTest(); + } public void testAnnotationOnSeparateLine() throws Throwable { doTest(); } public void testAlignMultipleVariables() throws Throwable { doTest(); } @@ -350,6 +357,17 @@ for (; abc;) } + void testWrapThrows() { + groovySettings.THROWS_KEYWORD_WRAP = CommonCodeStyleSettings.WRAP_ALWAYS + + checkFormatting('''\ +def foo() throws X {} +''', '''\ +def foo() + throws X {} +''') + } + private void doGeeseTest() { GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class); boolean oldvalue = customSettings.USE_FLYING_GEESE_BRACES;