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:
parent
12d4746a36
commit
01b24ceba4
2 changed files with 19 additions and 6 deletions
|
@ -4108,22 +4108,22 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
private void formatStatements(final List<IASTStatement> statements, boolean insertNewLineAfterLastStatement) {
|
private void formatStatements(final List<IASTStatement> statements, boolean insertNewLineAfterLastStatement) {
|
||||||
final int statementsLength= statements.size();
|
final int statementsLength= statements.size();
|
||||||
if (statementsLength > 1) {
|
if (statementsLength > 1) {
|
||||||
IASTStatement previousStatement= statements.get(0);
|
IASTStatement firstStatement= statements.get(0);
|
||||||
try {
|
try {
|
||||||
previousStatement.accept(this);
|
firstStatement.accept(this);
|
||||||
} catch (ASTProblemException e) {
|
} catch (ASTProblemException e) {
|
||||||
skipToNode(statements.get(1));
|
skipToNode(statements.get(1));
|
||||||
}
|
}
|
||||||
final int indentLevel= scribe.indentationLevel;
|
final int indentLevel= scribe.indentationLevel;
|
||||||
for (int i = 1; i < statementsLength - 1; i++) {
|
for (int i = 1; i < statementsLength - 1; i++) {
|
||||||
final IASTStatement statement= statements.get(i);
|
final IASTStatement statement= statements.get(i);
|
||||||
if (!startNode(statement)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(statement instanceof IASTNullStatement) &&
|
if (!(statement instanceof IASTNullStatement) &&
|
||||||
!doNodeLocationsOverlap(statement, statements.get(i - 1))) {
|
!doNodeLocationsOverlap(statement, statements.get(i - 1))) {
|
||||||
scribe.startNewLine();
|
scribe.startNewLine();
|
||||||
}
|
}
|
||||||
|
if (!startNode(statement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
statement.accept(this);
|
statement.accept(this);
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
@ -4140,7 +4140,6 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor,
|
||||||
scribe.unIndent();
|
scribe.unIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
previousStatement= statement;
|
|
||||||
}
|
}
|
||||||
final IASTStatement statement= statements.get(statementsLength - 1);
|
final IASTStatement statement= statements.get(statementsLength - 1);
|
||||||
final boolean statementIsNullStmt= statement instanceof IASTNullStatement;
|
final boolean statementIsNullStmt= statement instanceof IASTNullStatement;
|
||||||
|
|
|
@ -2657,4 +2657,18 @@ public class CodeFormatterTest extends BaseUITestCase {
|
||||||
public void testMacroInElseBranch_Bug350689() throws Exception {
|
public void testMacroInElseBranch_Bug350689() throws Exception {
|
||||||
assertFormatterResult();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue