Skip to content

ChangeMethodInvocationReturnType is not handling parameterized types #7502

Description

@Goshenkata

What version of OpenRewrite are you using?

rewrite 8.75.2

What is the smallest, simplest way to reproduce the problem?

Add this test case in ChangeMethodInvocationReturnTypeTest

    @Test
    void replaceVariableAssignmentWithGenericReturnType() {
        rewriteRun(
          spec -> spec.recipe(new ChangeMethodInvocationReturnType("bar.Bar bar()", "java.util.Set<java.lang.String>"))
            .parser(JavaParser.fromJavaVersion()
              //language=java
              .dependsOn(
                """
                  package bar;
                  import java.util.List;
                  public class Bar {
                      public static List<String> bar() {
                          return null;
                      }
                  }
                  """
              )
            ),
          //language=java
          java(
            """
              import bar.Bar;
              import java.util.List;
              class Foo {
                  void foo() {
                      List<String> one = Bar.bar();
                  }
              }
              """,
            """
              import bar.Bar;

              import java.util.Set;

              class Foo {
                  void foo() {
                      Set<String> one = Bar.bar();
                  }
              }
              """
          )
        );
    }

Result:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions