[core] Remove deprecated methods in AbstractRule

AbstractRule#deepCopyValuesTo
AbstractRule#addRuleChainVisit
AbstractRule#addViolation
AbstractRule#addViolationWithMessage
This commit is contained in:
Andreas Dangel 2024-02-08 08:15:15 +01:00
parent f95431f336
commit 1900aa79c4
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
7 changed files with 18 additions and 100 deletions

View File

@ -205,6 +205,13 @@ The following previously deprecated rules have been finally removed:
* Only XPath version 3.1 is now supported. This version of the XPath language is mostly identical to
XPath 2.0. XPath rules by default use now {%jdoc core::lang.rule.xpath.XPathVersion#XPATH_3_1 %}.
* `net.sourceforge.pmd.lang.rule.AbstractDelegateRule` removed. It has been merged with {%jdoc core::lang.rule.RuleReference %}.
* {%jdoc !!core::lang.rule.AbstractRule %} - the following methods have been removed:
* `deepCopyValuesTo(AbstractRule)` - use {%jdoc core::lang.rule.AbstractRule#deepCopy() %} instead.
* `addRuleChainVisit(Class)` - override {%jdoc core::lang.rule.AbstractRule#buildTargetSelector() %} in order to register nodes for rule chain visits.
* `addViolation(...)` - use {%jdoc core::RuleContext#addViolation(core::lang.ast.Node) %} instead, e.g. via `asCtx(data).addViolation(...)`.
Note: These methods were only marked as deprected in javadoc.
* `addViolationWithMessage(...)` - use {%jdoc core::RuleContext#addViolationWithMessage(core::lang.ast.Node,java.lang.String) %} instead, e.g. via
`asCtx(data).addViolationWithMessage(...)`. Note: These methods were only marked as deprected in javadoc.
* pmd-apex
* {%jdoc apex::lang.apex.ast.ApexNode %} and {% jdoc apex::lang.apex.ast.ASTApexFile %}
* `#getApexVersion()`: In PMD 6, this method has been deprecated but was defined in the class `ApexRootNode`.

View File

@ -60,34 +60,6 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
return "rule";
}
/**
* @deprecated Use {@link #deepCopy()} to create verbatim copies of rules.
*/
@Deprecated
public void deepCopyValuesTo(AbstractRule otherRule) {
otherRule.language = language;
otherRule.minimumLanguageVersion = minimumLanguageVersion;
otherRule.maximumLanguageVersion = maximumLanguageVersion;
otherRule.deprecated = deprecated;
otherRule.name = name;
otherRule.since = since;
otherRule.ruleClass = ruleClass;
otherRule.ruleSetName = ruleSetName;
otherRule.message = message;
otherRule.description = description;
otherRule.examples = copyExamples();
otherRule.externalInfoUrl = externalInfoUrl;
otherRule.priority = priority;
otherRule.propertyDescriptors = new ArrayList<>(getPropertyDescriptors());
otherRule.propertyValuesByDescriptor = copyPropertyValues();
otherRule.ruleChainVisits = new LinkedHashSet<>(ruleChainVisits);
otherRule.classRuleChainVisits = new LinkedHashSet<>(classRuleChainVisits);
}
private List<String> copyExamples() {
return new ArrayList<>(examples);
}
@Override
public Language getLanguage() {
return language;
@ -237,16 +209,6 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
return classRuleChainVisits;
}
/**
* @deprecated Override {@link #buildTargetSelector()}, this is
* provided for legacy compatibility
*/
@Deprecated
protected void addRuleChainVisit(Class<? extends Node> nodeClass) {
classRuleChainVisits.add(nodeClass);
}
@Override
public final RuleTargetSelector getTargetSelector() {
if (myStrategy == null) {
@ -256,8 +218,7 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
}
/**
* Create the targeting strategy for this rule. Please override
* this instead of using {@link #addRuleChainVisit(Class)}.
* Create the targeting strategy for this rule.
* Use the factory methods of {@link RuleTargetSelector}.
*/
@NonNull
@ -286,10 +247,10 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
* asCtx(data).addViolationWithMessage(node, "Some message");
* }</pre>
*
* In PMD 7, rules will have type-safe access to a RuleContext, and
* this will be deprecated as useless. In PMD 6, you can use this to
* stop using the deprecated {@link #addViolation(Object, Node)} overloads
* of this class.
* In longer term, rules will have type-safe access to a RuleContext, when the
* rules use an appropriate visitor. Many rules have not been refactored yet.
* Once this is done, this method will be deprecated as useless. Until then,
* this is a way to hide the explicit cast to {@link RuleContext} in rules.
*/
protected final RuleContext asCtx(Object ctx) {
if (ctx instanceof RuleContext) {
@ -306,56 +267,6 @@ public abstract class AbstractRule extends AbstractPropertySource implements Rul
|| rule instanceof RuleReference && this.isThisRule(((RuleReference) rule).getRule());
}
/**
* @see RuleContext#addViolation(Node)
* @deprecated Replace with {@code asCtx(data).addViolation(node)}.
*/
public void addViolation(Object data, Node node) {
asCtx(data).addViolation(node);
}
/**
* @see RuleContext#addViolation(Node, Object[])
*
* @deprecated Replace with {@code asCtx(data).addViolation(node, arg)}.
*/
public void addViolation(Object data, Node node, String arg) {
asCtx(data).addViolation(node, arg);
}
/**
* @see RuleContext#addViolation(Node, Object[])
*
* @deprecated Replace with {@code asCtx(data).addViolation(node, arg1, arg2)}.
*/
public void addViolation(Object data, Node node, Object... args) {
asCtx(data).addViolation(node, args);
}
/**
* @see RuleContext#addViolationWithMessage(Node, String)
* @deprecated Replace with {@code asCtx(data).addViolationWithMessage(node, message)}.
*/
public void addViolationWithMessage(Object data, Node node, String message) {
asCtx(data).addViolationWithMessage(node, message);
}
/**
* @see RuleContext#addViolationWithPosition(Node, int, int, String, Object...)
* @deprecated Replace with {@code asCtx(data).addViolationWithPosition(node, beginLine, endLine, message)}.
*/
public void addViolationWithMessage(Object data, Node node, String message, int beginLine, int endLine) {
asCtx(data).addViolationWithPosition(node, beginLine, endLine, message);
}
/**
* @see RuleContext#addViolationWithMessage(Node, String, Object...)
* @deprecated Replace with {@code asCtx(data).addViolationWithMessage(node, message, args)}.
*/
public void addViolationWithMessage(Object data, Node node, String message, Object[] args) {
asCtx(data).addViolationWithMessage(node, message, args);
}
/**
* Rules are equal if:
* <ol>

View File

@ -134,7 +134,7 @@ public final class XPathRule extends AbstractRule {
}
for (Node nodeWithViolation : nodesWithViolation) {
addViolation(ctx, nodeWithViolation, nodeWithViolation.getImage());
ctx.addViolation(nodeWithViolation, nodeWithViolation.getImage());
}
}

View File

@ -45,7 +45,7 @@ public class FooRule extends AbstractRule {
apply(node.getChild(i), ctx);
}
if ("Foo".equals(node.getImage())) {
addViolation(ctx, node);
ctx.addViolation(node);
}
}
}

View File

@ -518,7 +518,7 @@ class RuleSetTest {
}).addRule(new MockRule() {
@Override
public void apply(Node target, RuleContext ctx) {
addViolationWithMessage(ctx, target, "Test violation of the second rule in the ruleset");
ctx.addViolationWithMessage(target, "Test violation of the second rule in the ruleset");
}
}).build();
@ -557,7 +557,7 @@ class RuleSetTest {
@Override
public void apply(Node target, RuleContext ctx) {
addViolationWithMessage(ctx, target, "Test violation of the second rule in the ruleset");
ctx.addViolationWithMessage(target, "Test violation of the second rule in the ruleset");
}
}).build();

View File

@ -111,7 +111,7 @@ class MultiThreadProcessorTest extends AbstractPMDProcessorTest {
letTheOtherThreadRun(100);
if (hasViolation) {
addViolation(ctx, target);
ctx.addViolation(target);
}
}

View File

@ -88,7 +88,7 @@ public abstract class AbstractMetricTestRule<N extends Number & Comparable<N>> e
N result = Metric.compute(metric, target, options);
if (result != null && reportLevel.compareTo(result) <= 0) {
addViolationWithMessage(ctx, target, violationMessage(target, result));
ctx.addViolationWithMessage(target, violationMessage(target, result));
}
}