Skip to content

Commit 37be475

Browse files
committed
Adopt TypeUtils.isOverride
1 parent 31659ef commit 37be475

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.openrewrite.java.JavaIsoVisitor;
2727
import org.openrewrite.java.tree.J;
2828
import org.openrewrite.java.tree.JavaType;
29+
import org.openrewrite.java.tree.TypeUtils;
2930

3031
import java.util.ArrayList;
3132
import java.util.List;
@@ -39,12 +40,12 @@ public class NormalizeSetter extends ScanningRecipe<NormalizeSetter.MethodAcc> {
3940

4041
@Override
4142
public String getDisplayName() {
42-
return "Rename setter methods to fit lombok";
43+
return "Rename setter methods to fit Lombok";
4344
}
4445

4546
@Override
4647
public String getDescription() {
47-
return "Rename methods that are effectively setter to the name lombok would give them.\n" +
48+
return "Rename methods that are effectively setter to the name Lombok would give them.\n" +
4849
"Limitations:\n" +
4950
" - If two methods in a class are effectively the same setter then one's name will be corrected and the others name will be left as it is.\n" +
5051
" - If the correct name for a method is already taken by another method then the name will not be corrected.\n" +
@@ -91,16 +92,9 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
9192

9293
@Override
9394
public J.MethodDeclaration visitMethodDeclaration(J.MethodDeclaration method, ExecutionContext ctx) {
94-
assert method.getMethodType() != null;
95-
96-
if (!LombokUtils.isEffectivelySetter(method)) {
97-
return method;
98-
}
99-
100-
// return early if the method overrides another
101-
// if the project defined both the original and the overridden method,
102-
// then the renaming of the "original" in the base class will cover the override
103-
if (method.getLeadingAnnotations().stream().anyMatch(a -> "Override".equals(a.getSimpleName()))) {
95+
if (method.getMethodType() == null || method.getBody() == null ||
96+
!LombokUtils.isEffectivelySetter(method) ||
97+
TypeUtils.isOverride(method.getMethodType())) {
10498
return method;
10599
}
106100

0 commit comments

Comments
 (0)