Update instead of override classHasLombokAnnotation flag
Fixes issues where inner classes would override this flag.
This commit is contained in:
@ -65,21 +65,27 @@ public class AbstractLombokAwareRule extends AbstractIgnoredAnnotationRule {
|
||||
|
||||
@Override
|
||||
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
|
||||
boolean oldValue = classHasLombokAnnotation;
|
||||
classHasLombokAnnotation = hasLombokAnnotation(node);
|
||||
return super.visit(node, data);
|
||||
Object result = super.visit(node, data);
|
||||
classHasLombokAnnotation = oldValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(ASTEnumDeclaration node, Object data) {
|
||||
boolean oldValue = classHasLombokAnnotation;
|
||||
classHasLombokAnnotation = hasLombokAnnotation(node);
|
||||
return super.visit(node, data);
|
||||
Object result = super.visit(node, data);
|
||||
classHasLombokAnnotation = oldValue;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there have been class level Lombok annotations found.
|
||||
* Note: this can only be queried after the class declaration node has been
|
||||
* processed.
|
||||
*
|
||||
*
|
||||
* @return <code>true</code> if a lombok annotation at the class level has
|
||||
* been found
|
||||
*/
|
||||
|
@ -55,7 +55,7 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule {
|
||||
AccessNode accessNodeParent = field.getAccessNodeParent();
|
||||
if (accessNodeParent.isStatic() || !accessNodeParent.isPrivate() || accessNodeParent.isFinal()
|
||||
|| accessNodeParent.isVolatile()
|
||||
|| hasClassLombokAnnotation()
|
||||
|| hasLombokAnnotation(node)
|
||||
|| hasIgnoredAnnotation((Annotatable) accessNodeParent)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -573,6 +573,47 @@ public class MyClass {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[java] SingularField: Lombok false positive with inner class and annotated outer class</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Outer {
|
||||
public class Inner {
|
||||
private String innerField;
|
||||
}
|
||||
|
||||
private String outerField;
|
||||
|
||||
public Outer(String outerField) {
|
||||
this.outerField = outerField;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>[java] SingularField: Lombok false positive with annotated inner class</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import lombok.Data;
|
||||
|
||||
public class Outer {
|
||||
@Data
|
||||
public class Inner {
|
||||
private String innerField;
|
||||
}
|
||||
|
||||
private String outerField;
|
||||
|
||||
public Outer(String outerField) {
|
||||
this.outerField = outerField;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#177 [java] SingularField with lambdas as final fields</description>
|
||||
|
Reference in New Issue
Block a user