diff --git a/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java b/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java index 35aa44340322..631b02079716 100644 --- a/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java +++ b/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java @@ -145,6 +145,7 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett "BRACE_STYLE", "CLASS_BRACE_STYLE", "METHOD_BRACE_STYLE", + "LAMBDA_BRACE_STYLE", "USE_FLYING_GEESE_BRACES", "FLYING_GEESE_BRACES_GAP", "DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS", diff --git a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java index 314e1f352126..45d84b017760 100644 --- a/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java +++ b/java/java-impl/src/com/intellij/psi/formatter/java/JavaSpacePropertyProcessor.java @@ -1301,12 +1301,12 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { } else if (myRole1 == ChildRole.ARROW) { if (myRole2 == ChildRole.LBRACE) { - switch (mySettings.BRACE_STYLE) { + switch (mySettings.LAMBDA_BRACE_STYLE) { case NEXT_LINE: case NEXT_LINE_SHIFTED: case NEXT_LINE_SHIFTED2: int space = spaceAroundArrow ? 1 : 0; - myResult = Spacing.createSpacing(space, space, 1, false, 0); + myResult = Spacing.createSpacing(space, space, 1, mySettings.KEEP_LINE_BREAKS, 0); break; default: createSpaceInCode(spaceAroundArrow); diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBracesTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBracesTest.java index 0a5c29b688db..a1678336c6ea 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBracesTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterBracesTest.java @@ -374,7 +374,7 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest { } public void testLambdaBrace() { - getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; + getSettings().LAMBDA_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; doMethodTest( "Runnable r = () -> {\n" + "};", @@ -383,5 +383,16 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest { "};" ); } + + public void testLambdaBraceMoveToPrevLine() { + getSettings().LAMBDA_BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE; + getSettings().KEEP_LINE_BREAKS = false; + doMethodTest( + "Runnable r = () ->\n" + + "{\n" + + "};", + "Runnable r = () -> {\n" + + "};"); + } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java index e82ff61e6527..ffb1634077cf 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java @@ -188,6 +188,7 @@ public interface CodeStyleSettingsCustomizable { BRACE_STYLE, CLASS_BRACE_STYLE, METHOD_BRACE_STYLE, + LAMBDA_BRACE_STYLE, USE_FLYING_GEESE_BRACES, FLYING_GEESE_BRACES_GAP, DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS, diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java index c7ad504d9247..fd51fdcd66c1 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java @@ -324,6 +324,7 @@ public class CommonCodeStyleSettings { @BraceStyleConstant public int BRACE_STYLE = END_OF_LINE; @BraceStyleConstant public int CLASS_BRACE_STYLE = END_OF_LINE; @BraceStyleConstant public int METHOD_BRACE_STYLE = END_OF_LINE; + @BraceStyleConstant public int LAMBDA_BRACE_STYLE = END_OF_LINE; /** * Defines if 'flying geese' style should be used for curly braces formatting, e.g. if we want to format code like diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/presentation/CodeStyleSettingPresentation.java b/platform/lang-api/src/com/intellij/psi/codeStyle/presentation/CodeStyleSettingPresentation.java index 1b002b412a78..a7a032b3586f 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/presentation/CodeStyleSettingPresentation.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/presentation/CodeStyleSettingPresentation.java @@ -328,9 +328,10 @@ public class CodeStyleSettingPresentation { new CodeStyleSelectSettingPresentation("METHOD_BRACE_STYLE", ApplicationBundle.message("wrapping.brace.placement.method.declaration"), BRACE_PLACEMENT_VALUES, BRACE_PLACEMENT_OPTIONS), + new CodeStyleSelectSettingPresentation("LAMBDA_BRACE_STYLE", ApplicationBundle.message("wrapping.brace.placement.lambda"), + BRACE_PLACEMENT_VALUES, BRACE_PLACEMENT_OPTIONS), new CodeStyleSelectSettingPresentation("BRACE_STYLE", ApplicationBundle.message("wrapping.brace.placement.other"), BRACE_PLACEMENT_VALUES, BRACE_PLACEMENT_OPTIONS) - )); putGroupTop(result, "EXTENDS_LIST_WRAP", WRAPPING_EXTENDS_LIST, WRAP_VALUES, WRAP_OPTIONS); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index e23c2cba26ec..57ce58e9a482 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -165,6 +165,7 @@ wrapping.brace.placement=Braces placement wrapping.brace.placement.class.declaration=In class declaration wrapping.brace.placement.method.declaration=In method declaration wrapping.brace.placement.other=Other +wrapping.brace.placement.lambda=In lambda declaration wrapping.brace.placement.end.of.line=End of line wrapping.brace.placement.next.line.if.wrapped=Next line if wrapped wrapping.brace.placement.next.line=Next line