forked from phoedos/pmd
Merge pull request #4489 from adangel/java-immutable-field-ignoredannot
[java] ImmutableField: Remove deprecated property "ignoredAnnotations"
This commit is contained in:
@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.design;
|
||||
|
||||
import static net.sourceforge.pmd.util.CollectionUtil.setOf;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.NodeStream;
|
||||
@ -25,15 +24,10 @@ import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass.AssignmentEntry;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass.DataflowResult;
|
||||
import net.sourceforge.pmd.lang.java.rule.internal.JavaPropertyUtil;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.util.CollectionUtil;
|
||||
|
||||
public class ImmutableFieldRule extends AbstractJavaRulechainRule {
|
||||
|
||||
private static final PropertyDescriptor<List<String>> IGNORED_ANNOTS =
|
||||
JavaPropertyUtil.ignoredAnnotationsDescriptor();
|
||||
|
||||
private static final Set<String> INVALIDATING_CLASS_ANNOT =
|
||||
setOf(
|
||||
"lombok.Builder",
|
||||
@ -49,7 +43,6 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule {
|
||||
|
||||
public ImmutableFieldRule() {
|
||||
super(ASTFieldDeclaration.class);
|
||||
definePropertyDescriptor(IGNORED_ANNOTS);
|
||||
}
|
||||
|
||||
|
||||
@ -59,8 +52,7 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule {
|
||||
if (field.getEffectiveVisibility().isAtMost(Visibility.V_PRIVATE)
|
||||
&& !field.getModifiers().hasAny(JModifier.VOLATILE, JModifier.STATIC, JModifier.FINAL)
|
||||
&& !JavaAstUtils.hasAnyAnnotation(enclosingType, INVALIDATING_CLASS_ANNOT)
|
||||
&& !JavaAstUtils.hasAnyAnnotation(field, INVALIDATING_FIELD_ANNOT)
|
||||
&& !JavaAstUtils.hasAnyAnnotation(field, getProperty(IGNORED_ANNOTS))) {
|
||||
&& !JavaAstUtils.hasAnyAnnotation(field, INVALIDATING_FIELD_ANNOT)) {
|
||||
|
||||
DataflowResult dataflow = DataflowPass.getDataflowResult(field.getRoot());
|
||||
|
||||
@ -87,9 +79,9 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule {
|
||||
|
||||
if (!hasWrite && !isBlank) {
|
||||
//todo this case may also handle static fields easily.
|
||||
addViolation(data, varId, varId.getName());
|
||||
asCtx(data).addViolation(varId, varId.getName());
|
||||
} else if (hasWrite && defaultValueDoesNotReachEndOfCtor(dataflow, varId)) {
|
||||
addViolation(data, varId, varId.getName());
|
||||
asCtx(data).addViolation(varId, varId.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -493,23 +493,6 @@ class Foo {
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1056 [java] Property ignoredAnnotations does not work for SingularField and ImmutableField</description>
|
||||
<rule-property name="ignoredAnnotations">java.lang.Deprecated</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class Foo {
|
||||
@Deprecated
|
||||
@SuppressWarnings("PMD.ImmutableField")
|
||||
private int x;
|
||||
|
||||
public Foo() {
|
||||
x = 2;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1792 Immutable field should still be detected with @Delegate</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
|
Reference in New Issue
Block a user