diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java | 5 | ||||
-rw-r--r-- | core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java | 19 |
2 files changed, 23 insertions, 1 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 bd5c069f87b..d6518351cfd 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 @@ -3998,11 +3998,13 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } // switch body String brace_position = preferences.brace_position_for_switch; + boolean hasOpenBrace = false; int braceIndent = -1; IASTStatement bodyStmt = node.getBody(); if (!startsWithMacroExpansion(bodyStmt)) { boolean insertSpaceBeforeOpeningBrace = preferences.insert_space_before_opening_brace_in_switch; formatAttributes(bodyStmt, insertSpaceBeforeOpeningBrace, false); + hasOpenBrace = peekNextToken() == Token.tLBRACE; formatOpeningBrace(brace_position, insertSpaceBeforeOpeningBrace); scribe.startNewLine(); braceIndent = scribe.numberOfIndentations; @@ -4142,7 +4144,8 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } scribe.startNewLine(); - formatClosingBrace(brace_position); + if (hasOpenBrace) + formatClosingBrace(brace_position); } exitNode(bodyStmt); return PROCESS_SKIP; 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 fa128f2d680..4d9d18be895 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 @@ -4223,4 +4223,23 @@ public class CodeFormatterTest extends BaseUITestCase { public void testAlignmentOfLambda3_Bug500000() throws Exception { assertFormatterResult(); } + + //void foo() { + // int a; + // switch (a) + // default: { + // break; + // } + //} + + //void foo() { + // int a; + // switch (a) + // default: { + // break; + // } + //} + public void testSwitchNoParen_Bug353022() throws Exception { + assertFormatterResult(); + } } |