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:
parent
ae4651ac31
commit
dd6f20db86
2 changed files with 31 additions and 5 deletions
|
@ -3209,16 +3209,25 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.space();
|
scribe.space();
|
||||||
}
|
}
|
||||||
IASTExpression condExpr= node.getConditionExpression();
|
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) {
|
if (condExpr == null || condExpr instanceof IASTProblemExpression) {
|
||||||
scribe.skipToToken(Token.tRPAREN);
|
scribe.skipToToken(Token.tRPAREN);
|
||||||
} else {
|
} else {
|
||||||
condExpr.accept(this);
|
condExpr.accept(this);
|
||||||
}
|
}
|
||||||
if (peekNextToken() == Token.tRPAREN) {
|
scribe.runTailFormatter();
|
||||||
scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_if);
|
scribe.setTailFormatter(null);
|
||||||
}
|
|
||||||
final IASTStatement thenStatement = node.getThenClause();
|
|
||||||
final IASTStatement elseStatement = node.getElseClause();
|
|
||||||
|
|
||||||
boolean thenStatementIsBlock = false;
|
boolean thenStatementIsBlock = false;
|
||||||
if (thenStatement != null) {
|
if (thenStatement != null) {
|
||||||
|
|
|
@ -238,6 +238,23 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
assertFormatterResult();
|
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:
|
//#define MY private:
|
||||||
//
|
//
|
||||||
//class ClassA
|
//class ClassA
|
||||||
|
|
Loading…
Add table
Reference in a new issue