Skip to content

Commit e99aa5f

Browse files
committed
Use MethodMatcher.methodPattern(method)
1 parent 37be475 commit e99aa5f

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/main/java/org/openrewrite/java/migrate/lombok/NormalizeSetter.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openrewrite.TreeVisitor;
2525
import org.openrewrite.java.ChangeMethodName;
2626
import org.openrewrite.java.JavaIsoVisitor;
27+
import org.openrewrite.java.MethodMatcher;
2728
import org.openrewrite.java.tree.J;
2829
import org.openrewrite.java.tree.JavaType;
2930
import org.openrewrite.java.tree.TypeUtils;
@@ -59,8 +60,7 @@ public static class MethodAcc {
5960

6061
@Value
6162
private static class RenameRecord {
62-
String pathToClass_;
63-
String methodName_;
63+
String methodPattern;
6464
String parameterType_;
6565
String newMethodName_;
6666
}
@@ -125,8 +125,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
125125
//todo write separate recipe for merging effective setters
126126
acc.renameRecords.add(
127127
new RenameRecord(
128-
pathToClass,
129-
actualMethodName,
128+
MethodMatcher.methodPattern(method),
130129
parameterType,
131130
expectedMethodName
132131
)
@@ -157,15 +156,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
157156

158157
@Override
159158
public TreeVisitor<?, ExecutionContext> getVisitor(MethodAcc acc) {
160-
161159
return new TreeVisitor<Tree, ExecutionContext>() {
162-
163160
@Override
164161
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
165-
166162
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)
169164
.getVisitor().visit(tree, ctx);
170165
}
171166
return tree;

src/test/java/org/openrewrite/java/migrate/lombok/NormalizeSetterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ public void setBa(long ba) {
485485
* If existing method names need to be rotated in a loop the recipe should still work.
486486
* For now this is not planned.
487487
*/
488+
488489
@Test
489490
void shouldWorkOnCircleCasesButDoesntYet() {
490491
rewriteRun(// language=java

0 commit comments

Comments
 (0)