Start a switch expression on the line of the declaration it initializes - #76
Merged
Merged
Conversation
palantir#1789) (cherry picked from commit 478d4c5)
The upstream commit rewrote the input of test1 into the new shape, so both inputs of the golden that declare a variable with a switch expression already started from the target form, and the golden checked re-indentation and stability only. Nothing started from "=", a line break and the switch, which is what the change moves. test1's input goes back to that shape, as it was before; its expected output does not change. A field initialized with a switch expression, written in the same old shape, is added as well, since no golden covered a field.
abashev
added a commit
to openjavaformat/docs
that referenced
this pull request
Sep 25, 2026
…grate Two more changes on the formatter's main branch move output away from palantir-java-format 2.98.0, and Migrate lists every such difference. openjavaformat/open-java-format#76 brings over palantir 2.99.0's one change: a switch expression that initializes a variable or a field starts on the declaration's line, 57 declarations in 51 files of the JDK 21 sources. openjavaformat/open-java-format#74 stops counting a comment that opens with /*** as javadoc, so a blank line between such a banner and the declaration after it stays: 70 blank lines in 43 files, all of them in the source. Both join the cast fix as not yet released, and the corpus paragraph gives their numbers.
abashev
added a commit
to openjavaformat/docs
that referenced
this pull request
Sep 25, 2026
2.98.0.4 is out on GitHub, Maven Central and the Gradle Plugin Portal, so the pages now install it. It carries the three output changes that Migrate listed as not yet in a release: the cast fix (openjavaformat/open-java-format#78), the switch expression on the declaration's line (openjavaformat/open-java-format#76) and the /*** banner that no longer counts as javadoc (openjavaformat/open-java-format#74). Each now says it applies since 2.98.0.4, and the corpus paragraph no longer calls them unreleased. The GitHub Action page keeps 2.98.0.3 as the default of the action's version input, because the action itself still defaults to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #63. Brings over palantir#1789 by Patrick Koenig, which fixes palantir#1258 and shipped in palantir-java-format 2.99.0.
What changes
A local variable or a field initialized with a switch expression broke after the
=, with the switch indented by eight, while a plain assignment of the same switch already kept it on the line:From upstream, with the author kept
git cherry-pick -x, rename detection mappedpalantir-java-format/toopen-java-format/, nothing to adapt).declareOneloses its special case for an initializer that starts withswitch, so the initializer takes the same level as any other, andvisitCasedrops the forced break after a rule case's;. The goldenExpressionSwitchmoves in the same two methods as upstream's.Added here
test1into the new shape, so both declarations in the golden started from the target form and nothing checked the move itself.test1's input goes back to the old shape,=, a line break and the switch, with the same expected output; a field initialized with a switch expression, written in the same old shape, is added too, since no golden covered a field. Both fail on main.Checked
assignmentand the upstreamtest1output pin the new shape, the restoredtest1input and the new field pin the move from the old one../gradlew :open-java-format:teston JDK 21: 1497 tests, all green.=line and its body eight columns left; in 9 of the files a case body or athrowargument that had to wrap at the deeper indent now fits on one line. Nothing else changes.MethodHandleImpl.javaandCalendar.java, which change on a second run on main already, in the same way (a trailing comment after a call, and a block comment before acase).Version
This changes the output of files that format correctly today, which the README reserves for 3.0 (#22 and #31 are in the same position). Merging is the call on that, not this PR.