mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-20 15:35:24 +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:
parent
b9359d5247
commit
cd97ba6ced
2 changed files with 78 additions and 13 deletions
|
@ -1056,21 +1056,29 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
preferences.alignment_for_lambda_expression, Alignment.R_INNERMOST, 1, getCurrentPosition());
|
preferences.alignment_for_lambda_expression, Alignment.R_INNERMOST, 1, getCurrentPosition());
|
||||||
scribe.enterAlignment(alignment);
|
scribe.enterAlignment(alignment);
|
||||||
|
|
||||||
// Body
|
boolean ok = false;
|
||||||
if (bodyStmt instanceof IASTCompoundStatement) {
|
do {
|
||||||
if (enterNode(bodyStmt)) {
|
try {
|
||||||
if (getCurrentPosition() <= nodeOffset(bodyStmt)) {
|
// Body
|
||||||
formatLeftCurlyBrace(line, preferences.brace_position_for_method_declaration);
|
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,
|
scribe.printTrailingComment();
|
||||||
preferences.insert_space_before_opening_brace_in_method_declaration,
|
ok = true;
|
||||||
preferences.indent_statements_compare_to_body);
|
} catch (AlignmentException e) {
|
||||||
exitNode(bodyStmt);
|
scribe.redoAlignment(e);
|
||||||
}
|
}
|
||||||
} else if (bodyStmt != null) {
|
} while (!ok);
|
||||||
bodyStmt.accept(this);
|
|
||||||
}
|
|
||||||
scribe.printTrailingComment();
|
|
||||||
|
|
||||||
// go back to the previous alignment again:
|
// go back to the previous alignment again:
|
||||||
scribe.exitAlignment(alignment, true);
|
scribe.exitAlignment(alignment, true);
|
||||||
|
|
|
@ -4460,4 +4460,61 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
DefaultCodeFormatterConstants.NEXT_LINE);
|
DefaultCodeFormatterConstants.NEXT_LINE);
|
||||||
assertFormatterResult();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue