[java] ImmutableField: Remove deprecated property "ignoredAnnotations"

This commit is contained in:
Andreas Dangel
2023-04-20 14:14:06 +02:00
parent f072227721
commit 990fb94845
4 changed files with 11 additions and 28 deletions

View File

@ -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",
@ -51,7 +45,6 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule {
public ImmutableFieldRule() {
super(ASTFieldDeclaration.class);
definePropertyDescriptor(IGNORED_ANNOTS);
}
@ -61,8 +54,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());
@ -89,9 +81,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());
}
}

View File

@ -496,23 +496,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>