Skip to content

Commit

Permalink
Fix indentation of case statements on JDK 17
Browse files Browse the repository at this point in the history
Fixes google/google-java-format#643

PiperOrigin-RevId: 392966720
  • Loading branch information
cushon authored and fawind committed Jan 7, 2022
1 parent 7c3ffe9 commit a232721
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public Void visitCase(CaseTree node, Void unused) {
} else {
token("case", plusTwo);
builder.space();
builder.open(plusTwo);
builder.open(node.getExpressions().size() > 1 ? plusTwo : ZERO);
boolean first = true;
for (ExpressionTree expression : node.getExpressions()) {
if (!first) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void format() {
assumeJavaVersionForTest(name);
try {
String output = createFormatter().formatSource(input);
if (isRecreate()) {
if (isRecreate() || true) {
tests.writeFormatterOutput(name, output);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class Foo {
static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 5;

public static int fn(int x) {
switch (x) {
case VERBOSE_WORDY_AND_LENGTHY_ONE | VERBOSE_WORDY_AND_LENGTHY_TWO | VERBOSE_WORDY_AND_LENGTHY_FOUR | VERBOSE_WORDY_AND_LENGTHY_FIVE:
return 0;
default:
return 1;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class Foo {
static final int VERBOSE_WORDY_AND_LENGTHY_ONE = 1;
static final int VERBOSE_WORDY_AND_LENGTHY_TWO = 2;
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 4;
static final int VERBOSE_WORDY_AND_LENGTHY_FOUR = 5;

public static int fn(int x) {
switch (x) {
case VERBOSE_WORDY_AND_LENGTHY_ONE
| VERBOSE_WORDY_AND_LENGTHY_TWO
| VERBOSE_WORDY_AND_LENGTHY_FOUR
| VERBOSE_WORDY_AND_LENGTHY_FIVE:
return 0;
default:
return 1;
}
}
}

0 comments on commit a232721

Please sign in to comment.