Java: support parameterized types in ChangeMethodInvocationReturnType#7509
Draft
Java: support parameterized types in ChangeMethodInvocationReturnType#7509
ChangeMethodInvocationReturnType#7509Conversation
…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.
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.
Previously the recipe ran
JavaType.buildType(newReturnType), which folded the generic suffix into a malformedShallowClassFQN and rebuilt the variable's type expression as a singleJ.Identifierwhose simple name still contained<...>. Now it parses the new return type into a properTypeTree(handlingParameterized, arrays, wildcards, primitives) and walks everyFullyQualifiednode when adding/removing imports so type parameters get imported too.Test plan
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.