diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java index ffe73d2a7dd..40ecad720dd 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java @@ -1056,21 +1056,29 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, preferences.alignment_for_lambda_expression, Alignment.R_INNERMOST, 1, getCurrentPosition()); scribe.enterAlignment(alignment); - // Body - if (bodyStmt instanceof IASTCompoundStatement) { - if (enterNode(bodyStmt)) { - if (getCurrentPosition() <= nodeOffset(bodyStmt)) { - formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration); + boolean ok = false; + do { + try { + // Body + if (bodyStmt instanceof IASTCompoundStatement) { + if (enterNode(bodyStmt)) { + if (getCurrentPosition() <= nodeOffset(bodyStmt)) { + formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration); + } + formatBlock((IASTCompoundStatement) bodyStmt, preferences.brace_position_for_method_declaration, + preferences.insert_space_before_opening_brace_in_method_declaration, + preferences.indent_statements_compare_to_body); + exitNode(bodyStmt); + } + } else if (bodyStmt != null) { + bodyStmt.accept(this); } - formatBlock((IASTCompoundStatement) bodyStmt, preferences.brace_position_for_method_declaration, - preferences.insert_space_before_opening_brace_in_method_declaration, - preferences.indent_statements_compare_to_body); - exitNode(bodyStmt); + scribe.printTrailingComment(); + ok = true; + } catch (AlignmentException e) { + scribe.redoAlignment(e); } - } else if (bodyStmt != null) { - bodyStmt.accept(this); - } - scribe.printTrailingComment(); + } while (!ok); // go back to the previous alignment again: scribe.exitAlignment(alignment, true); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java index c2c24738834..7fb8106301d 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java @@ -4460,4 +4460,61 @@ public class CodeFormatterTest extends BaseUITestCase { DefaultCodeFormatterConstants.NEXT_LINE); assertFormatterResult(); } + + //bool thisIsMyVeeeeeeeeeeeeeeeeeryLongMethod() { + // return true; + //} + // + //bool thisIsMyVeryLong2() { + // return false; + //} + // + //template + //void myMethod(T &&a, int c) { + // + //} + //int main() { + // myMethod([]() { + // int i = 0; + // for (i = 0; i < 15; ++i) { + // if (thisIsMyVeeeeeeeeeeeeeeeeeryLongMethod() && thisIsMyVeryLong2()) { + // return 2; + // } else { + // return 1; + // } + // } + // }, 15); + // return 0; + //} + + //bool thisIsMyVeeeeeeeeeeeeeeeeeryLongMethod() { + // return true; + //} + // + //bool thisIsMyVeryLong2() { + // return false; + //} + // + //template + //void myMethod(T &&a, int c) { + // + //} + //int main() { + // myMethod( + // []() { + // int i = 0; + // for (i = 0; i < 15; ++i) { + // if (thisIsMyVeeeeeeeeeeeeeeeeeryLongMethod() + // && thisIsMyVeryLong2()) { + // return 2; + // } else { + // return 1; + // } + // } + // }, 15); + // return 0; + //} + public void testWrappingLambdaExpression_Bug549653() throws Exception { + assertFormatterResult(); + } }