1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 549653 - Fix wrapping for lambda expression

Change-Id: I5b879edbcda9c5c1fb0087891391612af2c47d09
Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
This commit is contained in:
Marco Stornelli 2019-07-30 11:17:13 +02:00
parent b9359d5247
commit cd97ba6ced
2 changed files with 78 additions and 13 deletions

View file

@ -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);

View file

@ -4460,4 +4460,61 @@ public class CodeFormatterTest extends BaseUITestCase {
DefaultCodeFormatterConstants.NEXT_LINE);
assertFormatterResult();
}
//bool thisIsMyVeeeeeeeeeeeeeeeeeryLongMethod() {
// return true;
//}
//
//bool thisIsMyVeryLong2() {
// return false;
//}
//
//template<typename T>
//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<typename T>
//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();
}
}