File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed
main/java/org/openrewrite/java/migrate
test/java/org/openrewrite/java/migrate Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ public class ChangeMethodInvocationReturnType extends Recipe {
4141 String methodPattern ;
4242
4343 @ Option (displayName = "New method invocation return type" ,
44- description = "The return return type of method invocation." ,
44+ description = "The fully qualified new return type of method invocation." ,
4545 example = "long" )
4646 String newReturnType ;
4747
@@ -96,7 +96,7 @@ public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations m
9696 mv .getTypeExpression ().getPrefix (),
9797 Markers .EMPTY ,
9898 emptyList (),
99- newReturnType ,
99+ newReturnType . substring ( newReturnType . lastIndexOf ( '.' ) + 1 ) ,
100100 newType ,
101101 null
102102 )
Original file line number Diff line number Diff line change 1717
1818import org .junit .jupiter .api .Test ;
1919import org .openrewrite .DocumentExample ;
20+ import org .openrewrite .java .JavaParser ;
2021import org .openrewrite .test .RecipeSpec ;
2122import org .openrewrite .test .RewriteTest ;
2223
@@ -79,4 +80,46 @@ void bar() {
7980 )
8081 );
8182 }
83+
84+ @ Test
85+ void replaceVariableAssignmentFullyQualified () {
86+ rewriteRun (
87+ spec -> spec .recipe (new ChangeMethodInvocationReturnType ("bar.Bar bar()" , "java.math.BigInteger" ))
88+ .parser (JavaParser .fromJavaVersion ()
89+ //language=java
90+ .dependsOn (
91+ """
92+ package bar;
93+ public class Bar {
94+ public static Integer bar() {
95+ return null;
96+ }
97+ }
98+ """
99+ )
100+ ),
101+ //language=java
102+ java (
103+ """
104+ import bar.Bar;
105+ class Foo {
106+ void foo() {
107+ Integer one = Bar.bar();
108+ }
109+ }
110+ """ ,
111+ """
112+ import bar.Bar;
113+
114+ import java.math.BigInteger;
115+
116+ class Foo {
117+ void foo() {
118+ BigInteger one = Bar.bar();
119+ }
120+ }
121+ """
122+ )
123+ );
124+ }
82125}
You can’t perform that action at this time.
0 commit comments