Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMarco Stornelli2019-05-17 18:27:35 +0000
committerMarco Stornelli2019-05-18 06:15:26 +0000
commit1cd5180642ada741ec45500ec3aba26f8855fb36 (patch)
tree80cec32755d861357d012b98727539b24a2981b2 /core
parent6452688c183614a4bc1f4163a253f08d2dc507d9 (diff)
downloadorg.eclipse.cdt-1cd5180642ada741ec45500ec3aba26f8855fb36.tar.gz
org.eclipse.cdt-1cd5180642ada741ec45500ec3aba26f8855fb36.tar.xz
org.eclipse.cdt-1cd5180642ada741ec45500ec3aba26f8855fb36.zip
Bug 353022 - Fix format switch without parenthesis
Change-Id: I8d8a6498abe5c08c65c03f86b563563910f01098 Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/formatter/CodeFormatterVisitor.java5
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CodeFormatterTest.java19
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();
+ }
}

Back to the top