|
17 | 17 |
|
18 | 18 | import org.openrewrite.*; |
19 | 19 | import org.openrewrite.internal.ListUtils; |
| 20 | +import org.openrewrite.java.AnnotationMatcher; |
| 21 | +import org.openrewrite.java.service.AnnotationService; |
20 | 22 | import org.openrewrite.java.tree.Flag; |
21 | 23 | import org.openrewrite.java.tree.J; |
22 | 24 | import org.openrewrite.java.tree.JavaType; |
|
40 | 42 | * - The recipe will not rename fields if the result already exists in a class or the result will be a java reserved keyword. |
41 | 43 | */ |
42 | 44 | public class RenamePrivateFieldsToCamelCase extends Recipe { |
| 45 | + private static final AnnotationMatcher LOMBOK_ANNOTATION = new AnnotationMatcher("@lombok.*"); |
43 | 46 |
|
44 | 47 | @Override |
45 | 48 | public String getDisplayName() { |
@@ -83,6 +86,15 @@ protected boolean shouldRename(Set<String> hasNameKey, J.VariableDeclarations.Na |
83 | 86 | ); |
84 | 87 | } |
85 | 88 |
|
| 89 | + @Override |
| 90 | + public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) { |
| 91 | + // Skip classes annotated with Lombok annotations, as their fields might be set or exposed by Lombok. |
| 92 | + if (service(AnnotationService.class).matches(getCursor(), LOMBOK_ANNOTATION)) { |
| 93 | + return classDecl; |
| 94 | + } |
| 95 | + return super.visitClassDeclaration(classDecl, ctx); |
| 96 | + } |
| 97 | + |
86 | 98 | @SuppressWarnings("all") |
87 | 99 | @Override |
88 | 100 | public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations.NamedVariable variable, ExecutionContext ctx) { |
@@ -123,6 +135,10 @@ public J.VariableDeclarations.NamedVariable visitVariable(J.VariableDeclarations |
123 | 135 |
|
124 | 136 | @Override |
125 | 137 | public J.VariableDeclarations visitVariableDeclarations(J.VariableDeclarations multiVariable, ExecutionContext ctx) { |
| 138 | + if (service(AnnotationService.class).matches(getCursor(), LOMBOK_ANNOTATION)) { |
| 139 | + return multiVariable; |
| 140 | + } |
| 141 | + |
126 | 142 | J.VariableDeclarations vds = super.visitVariableDeclarations(multiVariable, ctx); |
127 | 143 | if (getCursor().getMessage("ADD_STATIC", false)) { |
128 | 144 | return vds.withModifiers(ListUtils.insert(vds.getModifiers(), |
|
0 commit comments