palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
438 stars 46 forks source link

Fix: Properly format switch expressions #1069

Closed johnhany97 closed 6 months ago

johnhany97 commented 6 months ago

Before this PR

Fixes https://github.com/palantir/palantir-java-format/issues/1025 where before this change, we'd format switch expressions used in an assignment to yield the following:

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

After this PR

==COMMIT_MSG== Properly format switch expressions ==COMMIT_MSG== and now we generate this:

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

Possible downsides?

svc-autorelease commented 6 months ago

Released 2.42.0