Bug 535266: Formatter error CaseStatement with attributes
Fix and test.
Also fixes formatting errors with DefaultStatements.
Change-Id: Idac4a7105d7ae86db40755bd27cef60e197de664
Signed-off-by: Hansruedi Patzen <hansruedi.patzen@hsr.ch>
Signed-off-by: Thomas Corbat <tcorbat@hsr.ch>
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 3bb46f3..f594759 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 @@
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 @@
}
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 30e51cc..f98eeca 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 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();
+ }
}