diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolationFactory.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolationFactory.java index 40adaf5c9b..2d155fa0cf 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolationFactory.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolationFactory.java @@ -16,9 +16,9 @@ import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.ViolationSuppressor; import net.sourceforge.pmd.lang.apex.ast.CanSuppressWarnings; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; +import net.sourceforge.pmd.lang.rule.DefaultRuleViolationFactory; -public final class ApexRuleViolationFactory extends AbstractRuleViolationFactory { +public final class ApexRuleViolationFactory extends DefaultRuleViolationFactory { public static final ApexRuleViolationFactory INSTANCE = new ApexRuleViolationFactory(); private static final ViolationSuppressor APEX_ANNOT_SUPPRESSOR = new ViolationSuppressor() { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java index a730f06c64..7656ca42c4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageVersionHandler.java @@ -9,9 +9,10 @@ import java.util.List; import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.AstProcessingStage; +import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; import net.sourceforge.pmd.lang.dfa.DFAGraphRule; import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; +import net.sourceforge.pmd.lang.rule.DefaultRuleViolationFactory; import net.sourceforge.pmd.lang.rule.RuleViolationFactory; @@ -31,7 +32,9 @@ public interface LanguageVersionHandler { /** * Get the XPathHandler. */ - XPathHandler getXPathHandler(); + default XPathHandler getXPathHandler() { + return new DefaultASTXPathHandler(); + } /** @@ -63,7 +66,7 @@ public interface LanguageVersionHandler { * Get the RuleViolationFactory. */ default RuleViolationFactory getRuleViolationFactory() { - return new AbstractRuleViolationFactory() {}; + return DefaultRuleViolationFactory.defaultInstance(); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/DefaultRuleViolationFactory.java similarity index 91% rename from pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactory.java rename to pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/DefaultRuleViolationFactory.java index 9526056375..12fd5b9a1c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/DefaultRuleViolationFactory.java @@ -26,13 +26,13 @@ import net.sourceforge.pmd.lang.ast.Node; * It may be extended to add more suppression options. * *
Implementations should be internal. Only the interface should be exposed.
- *
- * TODO this should not be an abstract class anymore
*/
-public abstract class AbstractRuleViolationFactory implements RuleViolationFactory {
+public class DefaultRuleViolationFactory implements RuleViolationFactory {
private static final Object[] NO_ARGS = new Object[0];
+ private static final DefaultRuleViolationFactory DEFAULT = new DefaultRuleViolationFactory();
+
private String cleanup(String message, Object[] args) {
if (message != null) {
@@ -45,7 +45,6 @@ public abstract class AbstractRuleViolationFactory implements RuleViolationFacto
}
}
- // TODO why do we need those two overloads??
@Override
public void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, Object[] args) {
@@ -101,4 +100,9 @@ public abstract class AbstractRuleViolationFactory implements RuleViolationFacto
rv.setLines(beginLine, endLine);
return rv;
}
+
+ /** Returns the default instance (no additional suppressors, creates a ParametricRuleViolation). */
+ public static RuleViolationFactory defaultInstance() {
+ return DEFAULT;
+ }
}
diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java
index faca92e3cc..6b6ff96177 100644
--- a/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java
+++ b/pmd-core/src/test/java/net/sourceforge/pmd/AbstractRuleTest.java
@@ -20,9 +20,9 @@ import net.sourceforge.pmd.lang.DummyLanguageModule;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ast.DummyNode;
import net.sourceforge.pmd.lang.ast.DummyRoot;
-import net.sourceforge.pmd.lang.ast.DummyRuleViolationFactory;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.lang.rule.DefaultRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
import net.sourceforge.pmd.properties.PropertyDescriptor;
import net.sourceforge.pmd.properties.PropertyFactory;
@@ -128,7 +128,7 @@ public class AbstractRuleTest {
ctx.setSourceCodeFile(new File("filename"));
DummyRoot n = new DummyRoot(m);
n.setCoords(5, 1, 6, 0);
- DummyRuleViolationFactory.INSTANCE.addViolation(ctx, r, n, "specificdescription", new Object[0]);
+ DefaultRuleViolationFactory.defaultInstance().addViolation(ctx, r, n, "specificdescription", new Object[0]);
assertTrue(ctx.getReport().isEmpty());
}
diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java
index 888a46487a..fcd0908637 100644
--- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java
+++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java
@@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.lang.ast.ParseException;
import net.sourceforge.pmd.lang.ast.RootNode;
import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor;
-import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory;
+import net.sourceforge.pmd.lang.rule.DefaultRuleViolationFactory;
import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
/**
@@ -93,7 +93,7 @@ public class DummyLanguageModule extends BaseLanguageModule {
}
}
- public static class RuleViolationFactory extends AbstractRuleViolationFactory {
+ public static class RuleViolationFactory extends DefaultRuleViolationFactory {
@Override
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) {
return createRuleViolation(rule, ruleContext, node, message, 0, 0);
@@ -103,6 +103,7 @@ public class DummyLanguageModule extends BaseLanguageModule {
protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message,
int beginLine, int endLine) {
ParametricRuleViolationfile " + PMD.EOL + " " + PMD.EOL + "" + PMD.EOL
+ "" + error.getDetail() + "