mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Added option to keep simple lambdas in one line (IDEA-148295)
This commit is contained in:
@@ -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" +
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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("()->{}",
|
||||
|
||||
@@ -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" +
|
||||
"});");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+2
@@ -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"))
|
||||
));
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user