Skip to content

Commit

Permalink
fix: don't convert classes that implement interfaces (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
holgpar authored Apr 3, 2024
1 parent 414fd7a commit bb3f96f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,21 @@ private boolean isRelevantClass(J.ClassDeclaration classDeclaration) {
.allMatch(ann -> LOMBOK_VALUE_MATCHER.matches(ann) && (ann.getArguments() == null || ann.getArguments().isEmpty()))
&& !hasGenericTypeParameter(classDeclaration)
&& classDeclaration.getBody().getStatements().stream().allMatch(this::isRecordCompatibleField)
&& !hasIncompatibleModifier(classDeclaration);
&& !hasIncompatibleModifier(classDeclaration)
&& !implementsInterfaces(classDeclaration);
}

/**
* If the class target class implements an interface, transforming it to a record will not work in general,
* because the record access methods do not have the "get" prefix.
*
* @param classDeclaration
* @return
*/
private boolean implementsInterfaces(J.ClassDeclaration classDeclaration) {
List<TypeTree> classDeclarationImplements = classDeclaration.getImplements();
return !(classDeclarationImplements == null || classDeclarationImplements.isEmpty());
}
private boolean hasGenericTypeParameter(J.ClassDeclaration classDeclaration) {
List<J.TypeParameter> typeParameters = classDeclaration.getTypeParameters();
return typeParameters != null && !typeParameters.isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,5 +404,27 @@ public class A {
)
);
}

@Test
void classImplementingInterfaces() {
//language=java
rewriteRun(
java("""
package example;
import lombok.Value;
interface I {
String getTest();
}
@Value
public class A implements I {
String test;
}
""")
);

}
}
}

0 comments on commit bb3f96f

Please sign in to comment.