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

View file

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