Skip to content

Commit 79257ed

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Fix indentation of case statements on JDK 17
Fixes #643 PiperOrigin-RevId: 392966720
1 parent 865cff0 commit 79257ed

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

core/src/main/java/com/google/googlejavaformat/java/java14/Java14InputAstVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public Void visitCase(CaseTree node, Void unused) {
251251
token("default", plusTwo);
252252
} else {
253253
token("case", plusTwo);
254-
builder.open(plusFour);
254+
builder.open(node.getExpressions().size() > 1 ? plusFour : ZERO);
255255
builder.space();
256256
boolean first = true;
257257
for (ExpressionTree expression : node.getExpressions()) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Foo {
2+
static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
3+
static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
4+
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;
5+
6+
public static int fn(int x) {
7+
switch (x) {
8+
case VERBOSE_WORDY_AND_LENGTHY_ONE | VERBOSE_WORDY_AND_LENGTHY_TWO | VERBOSE_WORDY_AND_LENGTHY_FOUR:
9+
return 0;
10+
default:
11+
return 1;
12+
}
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Foo {
2+
static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
3+
static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
4+
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;
5+
6+
public static int fn(int x) {
7+
switch (x) {
8+
case VERBOSE_WORDY_AND_LENGTHY_ONE
9+
| VERBOSE_WORDY_AND_LENGTHY_TWO
10+
| VERBOSE_WORDY_AND_LENGTHY_FOUR:
11+
return 0;
12+
default:
13+
return 1;
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)