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 03:07:20 +00:00
parent ae4651ac31
commit dd6f20db86
2 changed files with 31 additions and 5 deletions

View file

@ -3209,16 +3209,25 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.space();
}
IASTExpression condExpr= node.getConditionExpression();
final IASTStatement thenStatement = node.getThenClause();
final IASTStatement elseStatement = node.getElseClause();
Runnable tailFormatter = null;
if (DefaultCodeFormatterConstants.END_OF_LINE.equals(preferences.brace_position_for_block) &&
thenStatement instanceof IASTCompoundStatement && !startsWithMacroExpansion(thenStatement)) {
tailFormatter = new TrailingTokenFormatter(Token.tLBRACE,
thenStatement.getFileLocation().getNodeOffset(),
preferences.insert_space_before_opening_brace_in_block, false);
}
tailFormatter = new ClosingParensesisTailFormatter(
preferences.insert_space_before_closing_paren_in_if, tailFormatter);
scribe.setTailFormatter(tailFormatter);
if (condExpr == null || condExpr instanceof IASTProblemExpression) {
scribe.skipToToken(Token.tRPAREN);
} else {
condExpr.accept(this);
}
if (peekNextToken() == Token.tRPAREN) {
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_if);
}
final IASTStatement thenStatement = node.getThenClause();
final IASTStatement elseStatement = node.getElseClause();
scribe.runTailFormatter();
scribe.setTailFormatter(null);
boolean thenStatementIsBlock = false;
if (thenStatement != null) {

View file

@ -238,6 +238,23 @@ public class CodeFormatterTest extends BaseUITestCase {
assertFormatterResult();
}
//void test() {
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 7000000) {}
//if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 70000000) {}
//}
//void test() {
// if (1000000 + 2000000 < 3000000 + 4000000 && 5000000 + 6000000 <= 7000000) {
// }
// if (1000000 + 2000000 < 3000000 + 4000000
// && 5000000 + 6000000 <= 70000000) {
// }
//}
public void testIfStatement() throws Exception {
fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE);
assertFormatterResult();
}
//#define MY private:
//
//class ClassA