Skip to content

Commit cc6e71f

Browse files
committed
Inline MethodAcc
1 parent ee573ca commit cc6e71f

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
@Value
3737
@EqualsAndHashCode(callSuper = false)
38-
public class NormalizeSetter extends ScanningRecipe<NormalizeSetter.MethodAcc> {
38+
public class NormalizeSetter extends ScanningRecipe<List<NormalizeSetter.RenameRecord>> {
3939

4040
private final static String DO_NOT_RENAME = "DO_NOT_RENAME";
4141

@@ -54,23 +54,19 @@ public String getDescription() {
5454
"E.g. `int getFoo() { return ba; } int getBa() { return foo; }` stays as it is.";
5555
}
5656

57-
public static class MethodAcc {
58-
List<RenameRecord> renameRecords = new ArrayList<>();
59-
}
60-
6157
@Value
62-
private static class RenameRecord {
58+
public static class RenameRecord {
6359
String methodPattern;
6460
String newMethodName;
6561
}
6662

6763
@Override
68-
public MethodAcc getInitialValue(ExecutionContext ctx) {
69-
return new MethodAcc();
64+
public List<RenameRecord> getInitialValue(ExecutionContext ctx) {
65+
return new ArrayList<>();
7066
}
7167

7268
@Override
73-
public TreeVisitor<?, ExecutionContext> getScanner(MethodAcc acc) {
69+
public TreeVisitor<?, ExecutionContext> getScanner(List<RenameRecord> renameRecords) {
7470
return new JavaIsoVisitor<ExecutionContext>() {
7571
@Override
7672
public J.CompilationUnit visitCompilationUnit(J.CompilationUnit cu, ExecutionContext ctx) {
@@ -107,7 +103,7 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
107103
return method;
108104
}
109105

110-
acc.renameRecords.add(new RenameRecord(MethodMatcher.methodPattern(method), expectedMethodName));
106+
renameRecords.add(new RenameRecord(MethodMatcher.methodPattern(method), expectedMethodName));
111107
doNotRename.remove(method.getSimpleName()); //actual method name becomes available again
112108
doNotRename.add(expectedMethodName); //expected method name now blocked
113109
return method;
@@ -133,11 +129,11 @@ public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, Ex
133129
}
134130

135131
@Override
136-
public TreeVisitor<?, ExecutionContext> getVisitor(MethodAcc acc) {
132+
public TreeVisitor<?, ExecutionContext> getVisitor(List<RenameRecord> renameRecords) {
137133
return new TreeVisitor<Tree, ExecutionContext>() {
138134
@Override
139135
public @Nullable Tree visit(@Nullable Tree tree, ExecutionContext ctx) {
140-
for (RenameRecord rr : acc.renameRecords) {
136+
for (RenameRecord rr : renameRecords) {
141137
tree = new ChangeMethodName(rr.methodPattern, rr.newMethodName, true, null)
142138
.getVisitor().visit(tree, ctx);
143139
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ void shouldNotRenameTwoToTheSame() {
268268
rewriteRun(// language=java
269269
java(
270270
"""
271-
272271
class A {
273272
274273
private long foo;
@@ -283,7 +282,6 @@ public void secondToBeRenamed(long foo) {
283282
}
284283
""",
285284
"""
286-
287285
class A {
288286
289287
private long foo;
@@ -309,7 +307,6 @@ void shouldWorkOnInnerClasses() {
309307
rewriteRun(// language=java
310308
java(
311309
"""
312-
313310
class A {
314311
315312
class B {
@@ -323,7 +320,6 @@ public void storeFoo(long foo) {
323320
}
324321
""",
325322
"""
326-
327323
class A {
328324
329325
class B {
@@ -345,7 +341,6 @@ void shouldWorkOnInnerClasses2() {
345341
rewriteRun(// language=java
346342
java(
347343
"""
348-
349344
class A {
350345
351346
class B {
@@ -361,7 +356,6 @@ public void giveFoo(long foo) {
361356
}
362357
""",
363358
"""
364-
365359
class A {
366360
367361
class B {
@@ -389,7 +383,6 @@ void shouldWorkDespiteInnerClassesSameNameMethods() {
389383
rewriteRun(// language=java
390384
java(
391385
"""
392-
393386
class A {
394387
395388
private long foo;
@@ -409,7 +402,6 @@ public void storeFoo(long foo) {
409402
}
410403
""",
411404
"""
412-
413405
class A {
414406
415407
private long foo;
@@ -440,7 +432,6 @@ void shouldWorkDespiteInnerClassesDifferentNameMethods() {
440432
rewriteRun(// language=java
441433
java(
442434
"""
443-
444435
class A {
445436
446437
private long foo;
@@ -460,7 +451,6 @@ public void storeBa(long ba) {
460451
}
461452
""",
462453
"""
463-
464454
class A {
465455
466456
private long foo;

0 commit comments

Comments
 (0)