Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2011-09-19 08:34:05 +0000
committerAnton Leherbauer2011-09-19 09:10:22 +0000
commit01b24ceba436b57970ceac00c9b2c22c48bd52a3 (patch)
treeecc585ef3f1a2505de79da2f58eb2d97b5c0694e
parent12d4746a36f36bd18e286673b0aca480ec23a33f (diff)
downloadorg.eclipse.cdt-01b24ceba436b57970ceac00c9b2c22c48bd52a3.tar.gz
org.eclipse.cdt-01b24ceba436b57970ceac00c9b2c22c48bd52a3.tar.xz
org.eclipse.cdt-01b24ceba436b57970ceac00c9b2c22c48bd52a3.zip
Bug 356690 - Macro use after for loop formats incorrectly
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java11
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java14
2 files changed, 19 insertions, 6 deletions
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
index ff05296897..765cf5c7e5 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java
@@ -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;
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
index ef207f78c7..8350569934 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java
@@ -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();
+ }
+
}

Back to the top