Place brace on next line works for lambdas (IDEA-140199)

This commit is contained in:
Yaroslav Lepenkin
2016-03-24 19:06:59 +03:00
parent b6be69e4a9
commit f98a2a050e
2 changed files with 34 additions and 3 deletions
@@ -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" +
"};"
);
}
}