Repository navigation
Autodetect: fix three bugs in building an import layout - #10231
Merged
Merged
Conversation
- A javax.* block followed by a final java.* block listed java.* twice. - When no sampled file had imports, the layout listed every block twice. - The last import block of a file overwrote where java.* or javax.* first appeared, which could flip the detected java/javax order.
…-builder-fixes # Conflicts: # rewrite-java-test/src/test/java/org/openrewrite/java/style/AutodetectTest.java
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.
Three bugs in how
Autodetectbuilds an import layout from the chosen block sequence. Each shows up with today's longest-sequence choice, and each gets its own test that fails without its fix.javax.*block followed by a finaljava.*block listedjava.*twice. The check for ajava.*neighbour afterjavax.*stopped one block short.java.*orjavax.*first appeared, while every earlier block kept the first position. That could count a file that putsjava.*first as puttingjavax.*first.Part of splitting #10217 into smaller PRs, after #10230.
Measured with
FindAutodetectedStyleVotes(branchtim/autodetect-style-votes) on dev.moderne.io over the Spring, Maven, MyBatis, Micronaut and Dropwizard organizations (341 repositories), comparing this change with #10230 alone. The layout changes in 11 repositories, 10 in Micronaut plusdropwizard/dropwizard. In each, the old layout listedjava.*twice (import javax.* | import java.* | <blank line> | import java.*), and the new one is IntelliJ's. Six more files follow the detected layout, and no repository loses any.Verified locally: the new tests
javaxThenJavaAsLastBlocks,filesWithoutImportsandjavaBeforeJavaxCountsWhereJavaFirstAppearsfail without the fixes and pass with them.AutodetectTest, the Java style, format,OrderImports,AddImportandRemoveImporttests, and the Kotlin and GroovyAutodetectTestpass.