diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BeanMembersShouldSerializeRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BeanMembersShouldSerializeRule.java index b36674a30e..9b16bf3c5c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BeanMembersShouldSerializeRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/BeanMembersShouldSerializeRule.java @@ -21,14 +21,15 @@ import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclarator; import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType; import net.sourceforge.pmd.lang.java.ast.ASTResultType; import net.sourceforge.pmd.lang.java.ast.AccessNode; -import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; +import net.sourceforge.pmd.lang.java.ast.Annotatable; +import net.sourceforge.pmd.lang.java.rule.AbstractLombokAwareRule; import net.sourceforge.pmd.lang.java.symboltable.ClassScope; import net.sourceforge.pmd.lang.java.symboltable.MethodNameDeclaration; import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration; import net.sourceforge.pmd.lang.symboltable.NameOccurrence; import net.sourceforge.pmd.properties.PropertyDescriptor; -public class BeanMembersShouldSerializeRule extends AbstractJavaRule { +public class BeanMembersShouldSerializeRule extends AbstractLombokAwareRule { private String prefixProperty; @@ -62,6 +63,8 @@ public class BeanMembersShouldSerializeRule extends AbstractJavaRule { return data; } + boolean classHasLombok = hasLombokAnnotation(node); + Map> methods = node.getScope().getEnclosingScope(ClassScope.class) .getMethodDeclarations(); List getSetMethList = new ArrayList<>(methods.size()); @@ -81,7 +84,8 @@ public class BeanMembersShouldSerializeRule extends AbstractJavaRule { for (Map.Entry> entry : vars.entrySet()) { VariableNameDeclaration decl = entry.getKey(); AccessNode accessNodeParent = decl.getAccessNodeParent(); - if (entry.getValue().isEmpty() || accessNodeParent.isTransient() || accessNodeParent.isStatic()) { + if (entry.getValue().isEmpty() || accessNodeParent.isTransient() || accessNodeParent.isStatic() + || classHasLombok || hasIgnoredAnnotation((Annotatable) accessNodeParent)) { continue; } String varName = StringUtils.capitalize(trimIfPrefix(decl.getImage())); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/BeanMembersShouldSerialize.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/BeanMembersShouldSerialize.xml index 90b4112ad4..983fca10cd 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/BeanMembersShouldSerialize.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/BeanMembersShouldSerialize.xml @@ -185,6 +185,84 @@ public class Foo { private String baz; public void setBaz(String b) { baz = b; } public String getBaz() { return baz; } +} + ]]> + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 1 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 2 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 3 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 4 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 5 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 6 + 0 + + + + #780 [java] BeanMembersShouldSerializeRule does not recognize lombok accessors - 7 + 0 +