diff --git a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java index e00877e9..01f9a3e0 100644 --- a/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java +++ b/core/src/main/java/com/google/googlejavaformat/java/JavaInputAstVisitor.java @@ -1875,10 +1875,10 @@ public Void visitCase(CaseTree node, Void unused) { markForPartialFormat(); builder.forcedBreak(); if (node.getExpression() == null) { - token("default", plusTwo); + token("default", ZERO); token(":"); } else { - token("case", plusTwo); + token("case", ZERO); builder.space(); scan(node.getExpression(), null); token(":"); diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.input b/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.input new file mode 100644 index 00000000..07ce2f4d --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.input @@ -0,0 +1,17 @@ +class T { + int test(String v) { + switch (v) { + // this is a line comment about "zero" + case "zero": + return 0; + case "one": + // this is a line comment about "one" + return 1; + // this is a line comment about "two" + case "two": + return 2; + default: + return -1; + } + } +} \ No newline at end of file diff --git a/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.output b/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.output new file mode 100644 index 00000000..70a0b6be --- /dev/null +++ b/core/src/test/resources/com/google/googlejavaformat/java/testdata/LegacySwitchComment.output @@ -0,0 +1,17 @@ +class T { + int test(String v) { + switch (v) { + // this is a line comment about "zero" + case "zero": + return 0; + case "one": + // this is a line comment about "one" + return 1; + // this is a line comment about "two" + case "two": + return 2; + default: + return -1; + } + } +}