From cd8a4b82b04413b96a592c9e8bb07a78340991c3 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Thu, 20 Nov 2008 12:34:28 +0000 Subject: [PATCH] Bug 244928 - follow up --- .../formatter/CodeFormatterVisitor.java | 4 ++ .../cdt/ui/tests/text/CodeFormatterTest.java | 52 +++++++++++++++++++ 2 files changed, 56 insertions(+) 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 2e89d0d1055..2471bcbab6e 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 @@ -3090,6 +3090,10 @@ public class CodeFormatterVisitor extends CPPASTVisitor { } if (!endsWithMacroExpansion) { formatClosingBrace(block_brace_position); + } else { + if (DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED.equals(block_brace_position)) { + scribe.unIndent(); + } } } 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 04e50ff1985..d15947cf68f 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 @@ -948,6 +948,58 @@ public class CodeFormatterTest extends BaseUITestCase { assertFormatterResult(); } + //#define BLOCK { } + //#define DOIT1() { } + //#define DOIT2() do { } while(false) + //#define ALWAYS if(true) + //#define NEVER if(false) + //#define FOREVER for(;;) + // + //void foo() { + // int i=0; + // if (true) DOIT1(); + // if (true) DOIT2(); + // for (;;) BLOCK + // ALWAYS BLOCK + // NEVER FOREVER BLOCK + // switch(i) { + // case 0: BLOCK + // } + //} + + //#define BLOCK { } + //#define DOIT1() { } + //#define DOIT2() do { } while(false) + //#define ALWAYS if(true) + //#define NEVER if(false) + //#define FOREVER for(;;) + // + //void + //foo() + //{ + // int i = 0; + // if (true) + // DOIT1(); + // if (true) + // DOIT2(); + // for (;;) + // BLOCK + // ALWAYS + // BLOCK + // NEVER + // FOREVER + // BLOCK + // switch (i) + // { + // case 0: + // BLOCK + // } + //} + public void testCompoundStatementAsMacroGNU_Bug244928() throws Exception { + fOptions= DefaultCodeFormatterOptions.getGNUSettings().getMap(); + assertFormatterResult(); + } + //#define A (0) //#define B (1) //#define ARGS (A, B)