Only use ignored annotation, not lombok one, fix #2876
This commit is contained in:
1 parent
9158c9f439
commit
dbecb80c9e
2 files changed
+19
-5
No files matched your search
+7
-5
@@ -42,16 +42,18 @@ public class UnusedPrivateFieldRule extends AbstractLombokAwareRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
boolean classHasLombok = hasLombokAnnotation(node);
|
||||
if (hasIgnoredAnnotation(node)) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
||||
Map<VariableNameDeclaration, List<NameOccurrence>> vars = node.getScope()
|
||||
.getDeclarations(VariableNameDeclaration.class);
|
||||
.getDeclarations(VariableNameDeclaration.class);
|
||||
for (Map.Entry<VariableNameDeclaration, List<NameOccurrence>> entry : vars.entrySet()) {
|
||||
VariableNameDeclaration decl = entry.getKey();
|
||||
AccessNode accessNodeParent = decl.getAccessNodeParent();
|
||||
if (!accessNodeParent.isPrivate() || isOK(decl.getImage()) || classHasLombok
|
||||
|| hasIgnoredAnnotation((Annotatable) accessNodeParent)
|
||||
|| hasIgnoredAnnotation(node)) {
|
||||
if (!accessNodeParent.isPrivate()
|
||||
|| isOK(decl.getImage())
|
||||
|| hasIgnoredAnnotation((Annotatable) accessNodeParent)) {
|
||||
continue;
|
||||
}
|
||||
if (!actuallyUsed(entry.getValue())) {
|
||||
|
||||
+12
@@ -636,6 +636,18 @@ public class Foo {
|
||||
<code><![CDATA[
|
||||
import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode
|
||||
public class Foo {
|
||||
private String bar;
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#2673 UnusedPrivateField false positive with lombok annotation EqualsAndHashCode</description>
|
||||
<rule-property name="ignoredAnnotations">lombok.Getter|lombok.Data</rule-property>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
public class Foo {
|
||||
private String bar;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user