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

Bug 356690 - Macro use after for loop formats incorrectly

This commit is contained in:
Anton Leherbauer 2011-09-19 10:34:05 +02:00
parent 12d4746a36
commit 01b24ceba4
2 changed files with 19 additions and 6 deletions

View file

@ -4108,22 +4108,22 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
private void formatStatements(final List<IASTStatement> statements, boolean insertNewLineAfterLastStatement) {
final int statementsLength= statements.size();
if (statementsLength > 1) {
IASTStatement previousStatement= statements.get(0);
IASTStatement firstStatement= statements.get(0);
try {
previousStatement.accept(this);
firstStatement.accept(this);
} catch (ASTProblemException e) {
skipToNode(statements.get(1));
}
final int indentLevel= scribe.indentationLevel;
for (int i = 1; i < statementsLength - 1; i++) {
final IASTStatement statement= statements.get(i);
if (!startNode(statement)) {
continue;
}
if (!(statement instanceof IASTNullStatement) &&
!doNodeLocationsOverlap(statement, statements.get(i - 1))) {
scribe.startNewLine();
}
if (!startNode(statement)) {
continue;
}
try {
statement.accept(this);
} catch (RuntimeException e) {
@ -4140,7 +4140,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
scribe.unIndent();
}
}
previousStatement= statement;
}
final IASTStatement statement= statements.get(statementsLength - 1);
final boolean statementIsNullStmt= statement instanceof IASTNullStatement;

View file

@ -2657,4 +2657,18 @@ public class CodeFormatterTest extends BaseUITestCase {
public void testMacroInElseBranch_Bug350689() throws Exception {
assertFormatterResult();
}
//#define IF(cond) if(cond){}
//void f() { if(1){}IF(1>0);}
//#define IF(cond) if(cond){}
//void f() {
// if (1) {
// }
// IF(1>0);
//}
public void testMacroAfterCompoundStatement_Bug356690() throws Exception {
assertFormatterResult();
}
}