Skip to content

Fix ChangeType inner class import handling when outer class import is present#7032

Open
MBoegers wants to merge 2 commits intomainfrom
fix/change-type-inner-class-import
Open

Fix ChangeType inner class import handling when outer class import is present#7032
MBoegers wants to merge 2 commits intomainfrom
fix/change-type-inner-class-import

Conversation

@MBoegers
Copy link
Contributor

@MBoegers MBoegers commented Mar 18, 2026

Summary

  • When renaming an inner class (e.g. foo.A$Builderbar.B$Builder) where the source file imports the outer class (import foo.A), ChangeType now correctly force-adds import bar.B and omits the redundant import bar.B.Builder - since import bar.B already makes B.Builder accessible.
  • Fixes the case where the new outer class import was silently dropped, leaving the code with an unresolved reference.
  • Adds an owningClassSame helper to detect when only the package changes (not the outer class name), enabling AddImport to 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 added
  • changeTypeOfInnerCompletely - inner class renamed to an entirely different outer class: only new outer class import added, no redundant inner import
  • changeTypeOfInnerClassImplicitly - outer class renamed with inner class following implicitly via import

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant