Skip to content

Commit

Permalink
Fix inconsistency in formatting of comments in switch statements
Browse files Browse the repository at this point in the history
This was introduced by f7543b2, which only updated the logic for for JDK 17+.

Fixes #1127

PiperOrigin-RevId: 659616575
  • Loading branch information
cushon authored and google-java-format Team committed Aug 5, 2024
1 parent de57db5 commit b3c7c11
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(":");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit b3c7c11

Please sign in to comment.