Skip to content

Java: support parameterized types in ChangeMethodInvocationReturnType#7509

Draft
timtebeek wants to merge 1 commit intomainfrom
tim/issue-7502
Draft

Java: support parameterized types in ChangeMethodInvocationReturnType#7509
timtebeek wants to merge 1 commit intomainfrom
tim/issue-7502

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 28, 2026

Previously the recipe ran JavaType.buildType(newReturnType), which folded the generic suffix into a malformed ShallowClass FQN and rebuilt the variable's type expression as a single J.Identifier whose simple name still contained <...>. Now it parses the new return type into a proper TypeTree (handling Parameterized, arrays, wildcards, primitives) and walks every FullyQualified node when adding/removing imports so type parameters get imported too.

Test plan

  • Added the issue's repro (List<String>Set<String>) plus nested generics (Map<String, List<Integer>>) and parameterized → raw (List<String>Object) cases.
  • ./gradlew :rewrite-java:test (full module) passes.

…e` (#7502)

Previously the recipe ran `JavaType.buildType(newReturnType)`, which folded the
generic suffix into a malformed `ShallowClass` FQN and rebuilt the variable's
type expression as a single `J.Identifier` whose simple name still contained
`<...>`. Parse the new return type into a proper `TypeTree` (handling
`Parameterized`, arrays, wildcards, primitives) and walk every `FullyQualified`
node when adding/removing imports so type parameters are imported too.
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.

ChangeMethodInvocationReturnType is not handling parameterized types

1 participant