Replace derive4j with a sealed interface and records - #99
Merged
Merged
Conversation
derive4j generated BreakBehaviours for one type, BreakBehaviour: four cases, two of them with a keepIndentWhenInlined flag. BreakBehaviour is now a sealed interface whose cases are records, and the factories the call sites used moved onto it. Level picks the case with a switch over record patterns instead of a Cases visitor and caseOf chains, so the compiler checks that every case is handled; the JSON serializer and LevelDelimitedFlatValueDocVisitor switch the same way. Each case keeps derive4j's toString, which the debug visitor prints, and the JSON keeps its shape. Level.BreakImpl's preferBreakingLastInnerLevel never read the flag and now takes no parameter. open-java-format no longer runs the derive4j processor. The 15,747 files of the JDK 21 sources format exactly as before, and the plugins' tests pass against a native image built from this.
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.
Follows #98 and targets its branch, so this diff shows only its own change; once #98 is merged it goes to
main.derive4j generated
BreakBehavioursfor one type,BreakBehaviour: four cases, two of them with akeepIndentWhenInlinedflag. Standard Java does the same job now, andopen-java-formatno longer runs the derive4j processor.What changes
BreakBehaviouris a sealed interface whose cases are records:BreakThisLevel,PreferBreakingLastInnerLevel,InlineSuffixandBreakOnlyIfInnerLevelsThenFitOnOneLine. The factories the 25 call sites used moved fromBreakBehavioursontoBreakBehaviour, with the same names.Levelpicks the case with a switch over record patterns instead of theCasesvisitor and thecaseOfchains, so the compiler checks that every case is handled. The JSON serializer andLevelDelimitedFlatValueDocVisitorswitch the same way.toString, such aspreferBreakingLastInnerLevel(true), which the debug visitor prints, and the JSON keeps its shape:{"type": ..., "keepIndentWhenInlined": ...}.Level.BreakImpl.preferBreakingLastInnerLevelnever read the flag and now takes no parameter. Error Prone's UnusedVariable said so once the method no longer implemented an interface.Checked
./gradlew test: 1597 tests in:open-java-format, 10 in the IDEA plugin, 51 in the Gradle plugin.-PnativeImage=true, the native image compiles from this and the Gradle plugin's 60 tests and jdk-bootstrap's 8 pass against it.formatDiffthrough the released plugin, which reshaped the new switches.