Fix ChangeType inner class import handling when outer class import is present#7032
Open
Fix ChangeType inner class import handling when outer class import is present#7032
Conversation
When renaming an inner class (e.g. foo.A\$Builder → bar.B\$Builder) where the source file imports the outer class (import foo.A), ChangeType now correctly: - Force-adds the new outer class import (import bar.B) when the old outer class import was removed, since the code accesses the inner class via qualified name (B.Builder) - Omits the redundant inner class import (import bar.B.Builder) in this case, since import bar.B already makes B.Builder accessible Also adds a test for renaming an inner class within the same outer class.
- Rename changeTypeOfInnerClassConstructor → changeTypeOfInnerClass (scenario: import foo.A.Builder only, rename to bar.A$Builder within same outer name) - Rename changeTypeOfInnerClass → changeTypeOfInnerCompletely (scenario: rename to a completely different outer class bar.B$Builder) - Rename renameInnerClassWithinSameOuterClass → changeTypeOfInnerClassImplicitly (scenario: outer class renamed, inner class implicitly follows via import) - Add @issue annotations linking tests to the GitHub issues they cover - Adjust test content to better represent the intent of each scenario
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.
Summary
foo.A$Builder→bar.B$Builder) where the source file imports the outer class (import foo.A),ChangeTypenow correctly force-addsimport bar.Band omits the redundantimport bar.B.Builder- sinceimport bar.Balready makesB.Builderaccessible.owningClassSamehelper to detect when only the package changes (not the outer class name), enablingAddImportto decide based on actual type references in that case.Test plan
changeTypeOfInnerClass- inner class renamed within same outer class name, different package: only outer class import addedchangeTypeOfInnerCompletely- inner class renamed to an entirely different outer class: only new outer class import added, no redundant inner importchangeTypeOfInnerClassImplicitly- outer class renamed with inner class following implicitly via import