Skip to content

Commit

Permalink
Fix: Properly format switch expressions (#1069)
Browse files Browse the repository at this point in the history
Properly format switch expressions
  • Loading branch information
johnhany97 committed Apr 5, 2024
1 parent b1db678 commit 1f52b40
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-1069.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: fix
fix:
description: Properly format switch expressions
links:
- https://github.com/palantir/palantir-java-format/pull/1069
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void reformat_a_subpath_of_a_git_directory_for_only_changed_lines() throws IOExc
runCommandInRepo("git", "init");
runCommandInRepo("git", "config", "user.name", "Test User");
runCommandInRepo("git", "config", "user.email", "test-user@palantir.com");
runCommandInRepo("git", "config", "commit.gpgsign", "false");
runCommandInRepo("git", "commit", "--allow-empty", "-m", "Init");

Path subdir = repo.resolve("subdir");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ public Void visitCase(CaseTree node, Void unused) {
scan(node.getBody(), null);
}
builder.guessToken(";");
builder.forcedBreak(minusTwo);
break;
default:
throw new IllegalArgumentException(node.getCaseKind().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,21 @@ class ExpressionSwitch {
default -> false;
};
}

public void test1(int y) {
int x =
switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}

public void test2(int y) {
int x;
x = switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,22 @@ class ExpressionSwitch {
default -> false;
};
}

public void test1(int y) {
int x =
switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}

public void test2(int y) {
int x;
x = switch (y) {
case 1 -> 1;
case 2 -> throw new IllegalArgumentException();
default -> throw new IllegalStateException();
};
}
}

0 comments on commit 1f52b40

Please sign in to comment.