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 afbba7dbb67..24c9d69e3f1 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 @@ -2494,6 +2494,8 @@ public class CodeFormatterVisitor extends CPPASTVisitor { if (elseStatement != null) { scribe.startNewLine(); } + } else if (thenStatement instanceof IASTCompoundStatement && !enclosedInMacroExpansion(thenStatement)) { + thenStatement.accept(this); } else { scribe.printTrailingComment(); scribe.startNewLine(); @@ -2508,10 +2510,12 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } if (elseStatement != null) { - if (thenStatementIsBlock) { - scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block); - } else { - scribe.printNextToken(Token.t_else, true); + if (!startsWithMacroExpansion(elseStatement)) { + if (thenStatementIsBlock) { + scribe.printNextToken(Token.t_else, preferences.insert_space_after_closing_brace_in_block); + } else { + scribe.printNextToken(Token.t_else, true); + } } if (elseStatement instanceof IASTCompoundStatement) { elseStatement.accept(this); 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 04146e3d5db..9e6d6e31271 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 @@ -1228,4 +1228,86 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define If if (1 == 1){ + //#define Else } else { + //#define EndElse } + // + //#define Try try{ + //#define Catch } catch(...) { + //#define EndCatch } + // + //int main() { + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // + // If + // cout << "OK" << endl; + // Else + // cout << "Strange" << endl; + // EndElse + // + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // + // return 0; + //} + + //#define If if (1 == 1){ + //#define Else } else { + //#define EndElse } + // + //#define Try try{ + //#define Catch } catch(...) { + //#define EndCatch } + // + //int main() { + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // + // If + // cout << "OK" << endl; + // Else + // cout << "Strange" << endl; + // EndElse + // + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // Try + // cout << "OK2" << endl; + // Catch + // cout << "Exception" << endl; + // EndCatch + // + // return 0; + //} +public void testControlStatementsAsMacro_Bug290630() throws Exception { + assertFormatterResult(); + } }