From 3f98811f7326e0eb94c745489985183e4bec2d7a Mon Sep 17 00:00:00 2001 From: Hansruedi Patzen Date: Tue, 29 May 2018 12:03:34 +0200 Subject: [PATCH] Bug 535266: Formatter error CaseStatement with attributes Fix and test. Also fixes formatting errors with DefaultStatements. Change-Id: Idac4a7105d7ae86db40755bd27cef60e197de664 Signed-off-by: Hansruedi Patzen Signed-off-by: Thomas Corbat --- .../formatter/CodeFormatterVisitor.java | 2 ++ .../cdt/ui/tests/text/CodeFormatterTest.java | 21 +++++++++++++++++++ 2 files changed, 23 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 3bb46f31da8..f5947591368 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 @@ -3615,6 +3615,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, private int visit(IASTCaseStatement node) { IASTExpression constant = node.getExpression(); + formatLeadingAttributes(node); if (constant == null) { scribe.printNextToken(Token.t_default); scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_default); @@ -3628,6 +3629,7 @@ public class CodeFormatterVisitor extends ASTVisitor implements ICPPASTVisitor, } private int visit(IASTDefaultStatement node) { + formatLeadingAttributes(node); scribe.printNextToken(Token.t_default); scribe.printNextToken(Token.tCOLON, preferences.insert_space_before_colon_in_default); 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 30e51cc960e..f98eecadcda 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 @@ -3384,4 +3384,25 @@ public class CodeFormatterTest extends BaseUITestCase { public void testInlineNamespace_Bug532849() throws Exception { assertFormatterResult(); } + + //void f() { + // switch (1) { + // [[foo]] case 1: + // break; + // [[foo]] default: + // break; + // } + //} + + //void f() { + // switch (1) { + // [[foo]] case 1: + // break; + // [[foo]] default: + // break; + // } + //} + public void testFormatAttributedLabelStatements_Bug535266() throws Exception { + assertFormatterResult(); + } }