RemoveImport: keep package-qualified and inherited static imports#8159
Draft
timtebeek wants to merge 1 commit into
Draft
RemoveImport: keep package-qualified and inherited static imports#8159timtebeek wants to merge 1 commit into
timtebeek wants to merge 1 commit into
Conversation
Handle two cases generically in the shared recipe, without language-specific path or facade special-casing: - Members imported by their package-qualified name even though they are compiled onto a synthetic enclosing class (e.g. Kotlin top-level functions on a `<File>Kt` facade), matched via the declaring type's package plus method name. - Members statically imported through a subtype that inherits them (e.g. a Kotlin companion-object member declared on an implemented interface), matched by walking the imported owner's supertypes. No type-attribution changes; driven off existing JavaType data.
3 tasks
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.
What's changed?
RemoveImportnow keeps two kinds of valid imports it previously dropped, handled generically in the sharedrewrite-javarecipe with no language-specific (source-path /"Kt"facade) special-casing: members imported by their package-qualified name even though they are compiled onto a synthetic enclosing class (e.g. Kotlin top-level functions on a<File>Ktfacade), and members statically imported through a subtype that inherits them (e.g. a Kotlin companion-object member declared on an implemented interface). The first is matched via the used method's declaring-type package plus name (with a guard so a used package-qualified import isn't removed); the second by walking the imported owner's supertypes/interfaces.What's your motivation?
This expresses the behavior purely in terms of existing
JavaTypedata instead of leaking Kotlin awareness into the shared module, so every recipe callingmaybeRemoveImportbenefits and no type-attribution/parser changes are needed.Any additional context
Added Kotlin
RemoveImportTestcoverage for top-level functions and inherited companion members;keepStarFoldWhenUsingStaticChildAndParentMembersFromJavaClassesstays@Disabledfor the pre-existing reason (Java sources can't yet be deps of Kotlin sources in tests). Verified green with no regressions across the fullrewrite-java-testmodule and KotlinRemoveImportTest/ChangeTypeTest/OrderImportsTest/AddImportTest.Checklist