|
24 | 24 | import org.openrewrite.TreeVisitor; |
25 | 25 | import org.openrewrite.java.ChangeMethodName; |
26 | 26 | import org.openrewrite.java.JavaIsoVisitor; |
| 27 | +import org.openrewrite.java.MethodMatcher; |
27 | 28 | import org.openrewrite.java.tree.J; |
28 | 29 | import org.openrewrite.java.tree.JavaType; |
29 | 30 | import org.openrewrite.java.tree.TypeUtils; |
@@ -59,8 +60,7 @@ public static class MethodAcc { |
59 | 60 |
|
60 | 61 | @Value |
61 | 62 | private static class RenameRecord { |
62 | | - String pathToClass_; |
63 | | - String methodName_; |
| 63 | + String methodPattern; |
64 | 64 | String parameterType_; |
65 | 65 | String newMethodName_; |
66 | 66 | } |
@@ -125,8 +125,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex |
125 | 125 | //todo write separate recipe for merging effective setters |
126 | 126 | acc.renameRecords.add( |
127 | 127 | new RenameRecord( |
128 | | - pathToClass, |
129 | | - actualMethodName, |
| 128 | + MethodMatcher.methodPattern(method), |
130 | 129 | parameterType, |
131 | 130 | expectedMethodName |
132 | 131 | ) |
@@ -157,15 +156,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex |
157 | 156 |
|
158 | 157 | @Override |
159 | 158 | public TreeVisitor<?, ExecutionContext> getVisitor(MethodAcc acc) { |
160 | | - |
161 | 159 | return new TreeVisitor<Tree, ExecutionContext>() { |
162 | | - |
163 | 160 | @Override |
164 | 161 | public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) { |
165 | | - |
166 | 162 | for (RenameRecord rr : acc.renameRecords) { |
167 | | - String methodPattern = String.format("%s %s(%s)", rr.pathToClass_, rr.methodName_, rr.parameterType_); |
168 | | - tree = new ChangeMethodName(methodPattern, rr.newMethodName_, true, null) |
| 163 | + tree = new ChangeMethodName(rr.methodPattern, rr.newMethodName_, true, null) |
169 | 164 | .getVisitor().visit(tree, ctx); |
170 | 165 | } |
171 | 166 | return tree; |
|
0 commit comments