Reorder non-sealed as one modifier - #67
Merged
Merged
Conversation
"non-sealed private interface B" came out as text that no longer parsed, so the whole file failed with "<identifier> expected". javac lexes non-sealed as three tokens, "non", "-" and "sealed", and the modifier sorting looked at one token at a time: it never saw "non-sealed", took the trailing "sealed" as the modifier to move in front of "private", and left "non-" behind. This ports google/google-java-format#1107 by Liam Miller-Cushon: the sorter now reads the three tokens as one modifier and writes it back whole. The golden Sealed and the sealedClass test come from upstream, with the expected output in this project's style; a second unit test pins the shape that failed. The 15,747 files of the JDK 21 sources format exactly as before; none of them writes non-sealed out of order.
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.
Brings over google/google-java-format#1107, a fix from google-java-format 1.23.
The bug
non-sealed private interface B extends I {}made the whole file fail witherror: <identifier> expected. javac lexesnon-sealedas three tokens,non,-andsealed, andModifierOrdererlooked at one token at a time: it never sawnon-sealed, took the trailingsealedas the modifier to move in front ofprivate, and leftnon-behind, so the reordered text no longer parsed.From upstream, with the author kept
non-sealedgoogle/google-java-format#1107 by Liam Miller-Cushon, commit authored by them. The sorter reads the three tokens as one modifier (ModifierTokens) and writes it back whole. Adapted to this codebase'sjavax.annotation.Nullableand NullAway suppressions. The upstream goldenSealedand thesealedClassunit test come with it, with the expected output in this project's style.Added here
ModifierOrdererTestcase for the exact shape that failed,non-sealed private.Checked
./gradlew :open-java-format:teston JDK 21: 1503 tests, all green.non-sealedout of JLS order.