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 765cf5c7e55..8cc1eb756e9 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 @@ -3526,14 +3526,14 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, * Controller expression */ IASTExpression controllerExpression = node.getControllerExpression(); - if (!enclosedInMacroExpansion(controllerExpression)) { + if (!doNodesHaveSameOffset(node, controllerExpression)) { scribe.printNextToken(Token.tLPAREN, preferences.insert_space_before_opening_paren_in_switch); if (preferences.insert_space_after_opening_paren_in_switch) { scribe.space(); } } controllerExpression.accept(this); - if (!enclosedInMacroExpansion(controllerExpression)) { + if (peekNextToken() == Token.tRPAREN) { scribe.printNextToken(Token.tRPAREN, preferences.insert_space_before_closing_paren_in_switch); } /* 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 64401be9ca5..b21646a106a 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 @@ -2658,6 +2658,23 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define EXPR(a) a + //void f(){ + //switch(EXPR(1)){default:break;} + //} + + //#define EXPR(a) a + //void f() { + // switch (EXPR(1)) { + // default: + // break; + // } + //} + public void testMacroInSwitch() throws Exception { + fOptions.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, CCorePlugin.SPACE); + assertFormatterResult(); + } + //#define IF(cond) if(cond){} //void f() { if(1){}IF(1>0);}