diff --git a/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java b/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java index f5e385f6a1f4..1e3336eaac6c 100644 --- a/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java +++ b/java/java-impl/src/com/intellij/ide/JavaLanguageCodeStyleSettingsProvider.java @@ -102,6 +102,7 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett "MODIFIER_LIST_WRAP", "KEEP_SIMPLE_BLOCKS_IN_ONE_LINE", "KEEP_SIMPLE_METHODS_IN_ONE_LINE", + "KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE", "KEEP_SIMPLE_CLASSES_IN_ONE_LINE", "KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE", "FOR_STATEMENT_WRAP", @@ -396,7 +397,8 @@ public class JavaLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSett " try (MyResource r1 = getResource();\n" + " MyResource r2 = null) {\n" + " doSomething();\n" + - " }" + + " }\n" + + " Runnable r = () -> {};\n" + " }\n" + " public static void test() \n" + " throws Exception { \n" + 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 595246bf1306..27999a62ea6c 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 @@ -910,9 +910,16 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor { if (block.getParent() instanceof PsiMethod) { return shouldHandleAsSimpleMethod((PsiMethod)block.getParent()); } + else if (block.getParent() instanceof PsiLambdaExpression) { + return shouldHandleAsSimpleLambda((PsiLambdaExpression)block.getParent()); + } else { return shouldHandleAsSimpleBlock(block.getNode()); - } + } + } + + private boolean shouldHandleAsSimpleLambda(PsiLambdaExpression lambda) { + return mySettings.KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE && !lambda.textContains('\n'); } @Override diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java index 4f2cd4064565..552635e79071 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterSpaceTest.java @@ -334,7 +334,7 @@ public class JavaFormatterSpaceTest extends AbstractJavaFormatterTest { } public void testSpacesInsideLambda() { - getSettings().KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = true; + getSettings().KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE = true; getSettings().SPACE_AROUND_LAMBDA_ARROW = true; doMethodTest("()->{}", diff --git a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java index 040648043d7c..85097c372e85 100644 --- a/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/formatter/java/JavaFormatterWrapTest.java @@ -646,4 +646,15 @@ public class JavaFormatterWrapTest extends AbstractJavaFormatterTest { ); } + public void test_KeepSimpleLambdasInOneLine() { + getSettings().KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE = true; + doMethodTest(" execute( () -> {});", + "execute(() -> {});"); + + getSettings().KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE = false; + doMethodTest("execute(() -> {});", + "execute(() -> {\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 20536dd9b72e..6b5dce536cdb 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CodeStyleSettingsCustomizable.java @@ -144,6 +144,7 @@ public interface CodeStyleSettingsCustomizable { KEEP_SIMPLE_BLOCKS_IN_ONE_LINE, KEEP_SIMPLE_METHODS_IN_ONE_LINE, KEEP_SIMPLE_CLASSES_IN_ONE_LINE, + KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE, KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE, FOR_STATEMENT_WRAP, FOR_STATEMENT_LPAREN_ON_NEXT_LINE, 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 4eff030072f7..438567bfbac1 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/CommonCodeStyleSettings.java @@ -828,6 +828,7 @@ public class CommonCodeStyleSettings { public boolean KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false; public boolean KEEP_SIMPLE_METHODS_IN_ONE_LINE = false; + public boolean KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE = false; public boolean KEEP_SIMPLE_CLASSES_IN_ONE_LINE = false; public boolean KEEP_MULTIPLE_EXPRESSIONS_IN_ONE_LINE = false; 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 4d65bd83f49f..1b002b412a78 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 @@ -307,6 +307,8 @@ public class CodeStyleSettingPresentation { ApplicationBundle.message("wrapping.keep.simple.blocks.in.one.line")), new CodeStyleSettingPresentation("KEEP_SIMPLE_METHODS_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.simple.methods.in.one.line")), + new CodeStyleSettingPresentation("KEEP_SIMPLE_LAMBDAS_IN_ONE_LINE", + ApplicationBundle.message("wrapping.keep.simple.lambdas.in.one.line")), new CodeStyleSettingPresentation("KEEP_SIMPLE_CLASSES_IN_ONE_LINE", ApplicationBundle.message("wrapping.keep.simple.classes.in.one.line")) )); diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index a3cccc8bcdc6..a79aae59ad57 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -146,6 +146,7 @@ wrapping.keep.line.breaks=Line breaks wrapping.keep.comment.at.first.column=Comment at first column wrapping.keep.simple.classes.in.one.line=Simple classes in one line wrapping.keep.simple.methods.in.one.line=Simple methods in one line +wrapping.keep.simple.lambdas.in.one.line=Simple lambdas in one line wrapping.keep.multiple.expressions.in.one.line=Multiple expressions in one line wrapping.keep.simple.blocks.in.one.line=Simple blocks in one line