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

Line breaking in 'if' statements.

This commit is contained in:
Sergey Prigogin 2011-03-31 05:32:31 +00:00
parent dd6f20db86
commit 101bcadce5
2 changed files with 17 additions and 10 deletions

View file

@ -3236,18 +3236,19 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
thenStatementIsBlock = true;
final List<IASTStatement> statements = Arrays.asList(block.getStatements());
if (isGuardClause(block, statements) && elseStatement == null && preferences.keep_guardian_clause_on_one_line) {
/*
* Need a specific formatting for guard clauses
* guard clauses are block with a single return or throw
* statement
*/
scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_block);
scribe.space();
// Specific formatting for guard clauses. A guard clause is a block
// with a single return or throw statement.
if (scribe.scanner.getCurrentPosition() <= thenStatement.getFileLocation().getNodeOffset()) {
scribe.printNextToken(Token.tLBRACE, preferences.insert_space_before_opening_brace_in_block);
scribe.space();
}
statements.get(0).accept(this);
scribe.printNextToken(Token.tRBRACE, true);
scribe.printTrailingComment();
} else {
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
if (scribe.scanner.getCurrentPosition() <= thenStatement.getFileLocation().getNodeOffset()) {
formatLeftCurlyBrace(line, preferences.brace_position_for_block);
}
thenStatement.accept(this);
if (elseStatement != null && preferences.insert_new_line_before_else_in_if_statement) {
scribe.startNewLine();

View file

@ -239,15 +239,21 @@ public class CodeFormatterTest extends BaseUITestCase {
}
//void test() {
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 7000000) {}
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 70000000) {}
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 7000000) {
// // comment
//}
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 70000000) {
// // comment
//}
//}
//void test() {
// if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 7000000) {
// // comment
// }
// if (1000000 + 2000000 < 3000000 + 4000000
// && 5000000 + 6000000 <= 70000000) {
// // comment
// }
//}
public void testIfStatement() throws Exception {