mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Place brace on next line works for lambdas (IDEA-140199)
This commit is contained in:
@@ -50,6 +50,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.intellij.psi.codeStyle.CommonCodeStyleSettings.*;
|
||||
|
||||
public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.formatter.java.JavaSpacePropertyProcessor");
|
||||
|
||||
@@ -1291,9 +1293,27 @@ public class JavaSpacePropertyProcessor extends JavaElementVisitor {
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
if ((myRole1 == ChildRole.ARROW && (myRole2 == ChildRole.LBRACE || myRole2 == ChildRole.EXPRESSION)) ||
|
||||
(myRole1 == ChildRole.PARAMETER_LIST && myRole2 == ChildRole.ARROW)) {
|
||||
createSpaceInCode(mySettings.SPACE_AROUND_LAMBDA_ARROW);
|
||||
boolean spaceAroundArrow = mySettings.SPACE_AROUND_LAMBDA_ARROW;
|
||||
|
||||
if (myRole1 == ChildRole.PARAMETER_LIST && myRole2 == ChildRole.ARROW) {
|
||||
createSpaceInCode(spaceAroundArrow);
|
||||
}
|
||||
else if (myRole1 == ChildRole.ARROW) {
|
||||
if (myRole2 == ChildRole.LBRACE) {
|
||||
switch (mySettings.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);
|
||||
break;
|
||||
default:
|
||||
createSpaceInCode(spaceAroundArrow);
|
||||
}
|
||||
}
|
||||
else if (myRole2 == ChildRole.EXPRESSION) {
|
||||
createSpaceInCode(spaceAroundArrow);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -372,5 +372,16 @@ public class JavaFormatterBracesTest extends AbstractJavaFormatterTest {
|
||||
" throws IOException {}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testLambdaBrace() {
|
||||
getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
doMethodTest(
|
||||
"Runnable r = () -> {\n" +
|
||||
"};",
|
||||
"Runnable r = () ->\n" +
|
||||
"{\n" +
|
||||
"};"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user