From b270076e136c0db512d6883c22be9cffe1cf53ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 17 Aug 2019 11:09:11 +0200 Subject: [PATCH] Remove useless violation factories --- .../apex/rule/ApexRuleViolationFactory.java | 6 ++- .../sourceforge/pmd/ViolationSuppressor.java | 47 ++++++++++++++----- .../rule/AbstractRuleViolationFactory.java | 18 +++++-- .../pmd/lang/rule/RuleViolationFactory.java | 8 ++-- .../AbstractRuleViolationFactoryTest.java | 18 +------ .../java/rule/JavaRuleViolationFactory.java | 6 ++- .../sourceforge/pmd/lang/jsp/JspHandler.java | 6 --- .../jsp/rule/JspRuleViolationFactory.java | 33 ------------- .../pmd/lang/plsql/PLSQLHandler.java | 7 --- .../plsql/rule/PLSQLRuleViolationFactory.java | 34 -------------- .../pmd/lang/swift/SwiftHandler.java | 7 --- .../sourceforge/pmd/lang/vf/VfHandler.java | 7 --- .../lang/vf/rule/VfRuleViolationFactory.java | 36 -------------- .../sourceforge/pmd/lang/vm/VmHandler.java | 6 --- .../lang/vm/rule/VmRuleViolationFactory.java | 37 --------------- .../sourceforge/pmd/lang/xml/XmlHandler.java | 7 --- .../xml/rule/XmlRuleViolationFactory.java | 33 ------------- 17 files changed, 64 insertions(+), 252 deletions(-) delete mode 100644 pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/rule/JspRuleViolationFactory.java delete mode 100644 pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/PLSQLRuleViolationFactory.java delete mode 100644 pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/VfRuleViolationFactory.java delete mode 100644 pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/rule/VmRuleViolationFactory.java delete mode 100644 pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/XmlRuleViolationFactory.java 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 bead5ae641..40adaf5c9b 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 @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.apex.rule; import java.util.Collections; import java.util.List; +import org.checkerframework.checker.nullness.qual.NonNull; + import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Report.SuppressedViolation; import net.sourceforge.pmd.Rule; @@ -26,8 +28,8 @@ public final class ApexRuleViolationFactory extends AbstractRuleViolationFactory } @Override - public Report.SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule) { - if (isSuppressed(node, rule)) { + public Report.SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + if (isSuppressed(node, rv.getRule())) { return new SuppressedViolation(rv, this, null); } return null; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java b/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java index 190ed7a042..c5b3df8176 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java @@ -3,19 +3,25 @@ package net.sourceforge.pmd; import java.util.Map; import java.util.regex.Pattern; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.Report.SuppressedViolation; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.RootNode; +import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** - * Generic rule violation suppressor. + * An object that suppresses rule violations. Suppressors are used by + * {@link RuleViolationFactory} to filter out violations. In PMD 6.0.x, + * the {@link Report} object filtered violations itself - but it has + * no knowledge of language-specific suppressors. */ public interface ViolationSuppressor { - String NOPMD_COMMENT_ID = "//NOPMD"; - - + /** + * Suppressor for the violationSuppressRegex property. + */ ViolationSuppressor REGEX_SUPPRESSOR = new ViolationSuppressor() { @Override public String id() { @@ -23,8 +29,8 @@ public interface ViolationSuppressor { } @Override - public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule) { - String regex = rule.getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR); // Regex + public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + String regex = rv.getRule().getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR); // Regex if (regex != null && rv.getDescription() != null) { if (Pattern.matches(regex, rv.getDescription())) { return new SuppressedViolation(rv, this, regex); @@ -34,6 +40,9 @@ public interface ViolationSuppressor { } }; + /** + * Suppressor for the violationSuppressXPath property. + */ ViolationSuppressor XPATH_SUPPRESSOR = new ViolationSuppressor() { @Override public String id() { @@ -41,8 +50,8 @@ public interface ViolationSuppressor { } @Override - public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule) { - String xpath = rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR); + public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + String xpath = rv.getRule().getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR); if (xpath != null && node.hasDescendantMatchingXPath(xpath)) { return new SuppressedViolation(rv, this, xpath); } @@ -50,14 +59,20 @@ public interface ViolationSuppressor { } }; + /** + * Suppressor for regular NOPMD comments. + * + * @implNote This requires special support from the language, namely + * an implementation of {@link RootNode#getNoPmdComments()}. + */ ViolationSuppressor NOPMD_COMMENT_SUPPRESSOR = new ViolationSuppressor() { @Override public String id() { - return NOPMD_COMMENT_ID; + return "//NOPMD"; } @Override - public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule) { + public @Nullable SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { Map noPmd = node.getRoot().getNoPmdComments(); if (noPmd.containsKey(rv.getBeginLine())) { return new SuppressedViolation(rv, this, noPmd.get(rv.getBeginLine())); @@ -66,10 +81,20 @@ public interface ViolationSuppressor { } }; + + /** + * A name, for reporting and documentation purposes. + */ String id(); + + /** + * Returns a {@link SuppressedViolation} if the given violation is + * suppressed by this object. The node and the rule are provided + * for context. + */ @Nullable - SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule); + SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node); } 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/AbstractRuleViolationFactory.java index 6d5ef192a4..b19ae205ee 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/AbstractRuleViolationFactory.java @@ -10,6 +10,7 @@ import java.util.Collections; import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.nullness.qual.Nullable; import net.sourceforge.pmd.Report.SuppressedViolation; import net.sourceforge.pmd.Rule; @@ -18,6 +19,15 @@ import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.ViolationSuppressor; import net.sourceforge.pmd.lang.ast.Node; +/** + * This is a functional implementation of {@link RuleViolationFactory}. + * It uses only the standard {@link ViolationSuppressor}s (constants in the interface). + * 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 { private static final Object[] NO_ARGS = new Object[0]; @@ -42,7 +52,7 @@ public abstract class AbstractRuleViolationFactory implements RuleViolationFacto String formattedMessage = cleanup(message, args); RuleViolation rv = createRuleViolation(rule, ruleContext, node, formattedMessage); - maybeSuppress(ruleContext, node, rv, rule); + maybeSuppress(ruleContext, node, rv); } @Override @@ -51,10 +61,10 @@ public abstract class AbstractRuleViolationFactory implements RuleViolationFacto String formattedMessage = cleanup(message, args); RuleViolation rv = createRuleViolation(rule, ruleContext, node, formattedMessage, beginLine, endLine); - maybeSuppress(ruleContext, node, rv, rule); + maybeSuppress(ruleContext, node, rv); } - private void maybeSuppress(RuleContext ruleContext, Node node, RuleViolation rv, Rule rule) { + private void maybeSuppress(RuleContext ruleContext, @Nullable Node node, RuleViolation rv) { List suppressors = new ArrayList<>(getSuppressors()); suppressors.add(ViolationSuppressor.NOPMD_COMMENT_SUPPRESSOR); suppressors.add(ViolationSuppressor.REGEX_SUPPRESSOR); @@ -62,7 +72,7 @@ public abstract class AbstractRuleViolationFactory implements RuleViolationFacto if (node != null) { for (ViolationSuppressor suppressor : suppressors) { - SuppressedViolation suppressed = suppressor.suppressOrNull(rv, node, rule); + SuppressedViolation suppressed = suppressor.suppressOrNull(rv, node); if (suppressed != null) { ruleContext.getReport().addSuppressedViolation(suppressed); return; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleViolationFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleViolationFactory.java index 68959d1df0..253e05c1e2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleViolationFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleViolationFactory.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.rule; +import org.checkerframework.checker.nullness.qual.Nullable; + import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.ast.Node; @@ -27,8 +29,8 @@ public interface RuleViolationFactory { * @param args * arguments to embed in the rule violation message */ - void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, Object[] args); + void addViolation(RuleContext ruleContext, Rule rule, @Nullable Node node, String message, Object[] args); - void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, int beginLine, int endLine, - Object[] args); + + void addViolation(RuleContext ruleContext, Rule rule, @Nullable Node node, String message, int beginLine, int endLine, Object[] args); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactoryTest.java index beb48181f5..168bf43f00 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactoryTest.java @@ -10,7 +10,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.ast.Node; @@ -19,21 +18,6 @@ public class AbstractRuleViolationFactoryTest { private RuleContext ruleContext; private RuleViolationFactory factory; - private static class TestRuleViolationFactory extends AbstractRuleViolationFactory { - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - ParametricRuleViolation violation = new ParametricRuleViolation<>(rule, ruleContext, node, message); - violation.setLines(beginLine, endLine); - return violation; - } - } - private static class TestRule extends AbstractRule { @Override public void apply(List nodes, RuleContext ctx) { @@ -44,7 +28,7 @@ public class AbstractRuleViolationFactoryTest { @Before public void setup() { ruleContext = new RuleContext(); - factory = new TestRuleViolationFactory(); + factory = new AbstractRuleViolationFactory() {}; } @Test diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactory.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactory.java index f57e6ba0c4..2fcdfe1b18 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactory.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactory.java @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.java.rule; import java.util.Collections; import java.util.List; +import org.checkerframework.checker.nullness.qual.NonNull; + import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Report.SuppressedViolation; import net.sourceforge.pmd.Rule; @@ -28,8 +30,8 @@ public final class JavaRuleViolationFactory extends AbstractRuleViolationFactory } @Override - public Report.SuppressedViolation suppressOrNull(RuleViolation rv, Node node, Rule rule) { - if (AnnotationSuppressionUtil.contextSuppresses(node, rule)) { + public Report.SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + if (AnnotationSuppressionUtil.contextSuppresses(node, rv.getRule())) { return new SuppressedViolation(rv, this, null); } return null; diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspHandler.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspHandler.java index b75e856be5..13e26b62a1 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspHandler.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspHandler.java @@ -9,8 +9,6 @@ import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.jsp.rule.JspRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** * Implementation of LanguageVersionHandler for the JSP parser. @@ -24,10 +22,6 @@ public class JspHandler extends AbstractPmdLanguageVersionHandler { return new DefaultASTXPathHandler(); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return JspRuleViolationFactory.INSTANCE; - } @Override public Parser getParser(ParserOptions parserOptions) { diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/rule/JspRuleViolationFactory.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/rule/JspRuleViolationFactory.java deleted file mode 100644 index 8135d54f72..0000000000 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/rule/JspRuleViolationFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.jsp.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.jsp.ast.JspNode; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; - -public final class JspRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new JspRuleViolationFactory(); - - private JspRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (JspNode) node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - return null; // FIXME - } -} diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLHandler.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLHandler.java index 66bdf24d14..1ec0e75cc8 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLHandler.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLHandler.java @@ -16,9 +16,7 @@ import net.sourceforge.pmd.lang.dfa.DFAGraphRule; import net.sourceforge.pmd.lang.plsql.ast.ASTInput; import net.sourceforge.pmd.lang.plsql.dfa.DFAPLSQLGraphRule; import net.sourceforge.pmd.lang.plsql.dfa.DataFlowFacade; -import net.sourceforge.pmd.lang.plsql.rule.PLSQLRuleViolationFactory; import net.sourceforge.pmd.lang.plsql.symboltable.SymbolFacade; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** * Implementation of LanguageVersionHandler for the PLSQL AST. It uses anonymous @@ -38,11 +36,6 @@ public class PLSQLHandler extends AbstractPmdLanguageVersionHandler { return new PLSQLParser(parserOptions); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return PLSQLRuleViolationFactory.INSTANCE; - } - @Override public DFAGraphRule getDFAGraphRule() { return new DFAPLSQLGraphRule(); diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/PLSQLRuleViolationFactory.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/PLSQLRuleViolationFactory.java deleted file mode 100644 index f4adec6b2d..0000000000 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/rule/PLSQLRuleViolationFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.plsql.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; - -public final class PLSQLRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new PLSQLRuleViolationFactory(); - - private PLSQLRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - ParametricRuleViolation violation = new ParametricRuleViolation<>(rule, ruleContext, node, message); - violation.setLines(beginLine, endLine); - return violation; - } -} diff --git a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java index 3a40fd323f..7f0b548547 100644 --- a/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java +++ b/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/SwiftHandler.java @@ -8,9 +8,7 @@ import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.XPathHandler; -import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrRuleViolationFactory; import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; public class SwiftHandler extends AbstractPmdLanguageVersionHandler { @@ -19,11 +17,6 @@ public class SwiftHandler extends AbstractPmdLanguageVersionHandler { return new DefaultASTXPathHandler(); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return AntlrRuleViolationFactory.INSTANCE; - } - @Override public Parser getParser(final ParserOptions parserOptions) { return new SwiftParserAdapter(parserOptions); diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfHandler.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfHandler.java index d0b8ef5eab..b59699ed35 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfHandler.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfHandler.java @@ -9,8 +9,6 @@ import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vf.rule.VfRuleViolationFactory; public class VfHandler extends AbstractPmdLanguageVersionHandler { @@ -19,11 +17,6 @@ public class VfHandler extends AbstractPmdLanguageVersionHandler { return new DefaultASTXPathHandler(); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return VfRuleViolationFactory.INSTANCE; - } - @Override public Parser getParser(ParserOptions parserOptions) { return new VfParser(parserOptions); diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/VfRuleViolationFactory.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/VfRuleViolationFactory.java deleted file mode 100644 index 202394278e..0000000000 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/rule/VfRuleViolationFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.vf.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vf.ast.VfNode; - -public final class VfRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new VfRuleViolationFactory(); - - private VfRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (VfNode) node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - - ParametricRuleViolation rViolation = new ParametricRuleViolation<>(rule, ruleContext, (VfNode) node, message); - rViolation.setLines(beginLine, endLine); - return rViolation; - } -} diff --git a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmHandler.java b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmHandler.java index ca685d6b46..3e2e46531c 100644 --- a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmHandler.java +++ b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmHandler.java @@ -9,8 +9,6 @@ import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vm.rule.VmRuleViolationFactory; /** * Implementation of LanguageVersionHandler for the VM parser. @@ -23,10 +21,6 @@ public class VmHandler extends AbstractPmdLanguageVersionHandler { return new DefaultASTXPathHandler(); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return VmRuleViolationFactory.INSTANCE; - } @Override public Parser getParser(final ParserOptions parserOptions) { diff --git a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/rule/VmRuleViolationFactory.java b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/rule/VmRuleViolationFactory.java deleted file mode 100644 index a12d347fa5..0000000000 --- a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/rule/VmRuleViolationFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.vm.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vm.ast.AbstractVmNode; - -public final class VmRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new VmRuleViolationFactory(); - - private VmRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(final Rule rule, final RuleContext ruleContext, final Node node, - final String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (AbstractVmNode) node, message); - } - - @Override - protected RuleViolation createRuleViolation(final Rule rule, final RuleContext ruleContext, final Node node, - final String message, final int beginLine, final int endLine) { - final ParametricRuleViolation violation = new ParametricRuleViolation<>(rule, ruleContext, - (AbstractVmNode) node, message); - violation.setLines(beginLine, endLine); - return violation; - } -} diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java index 88d11444de..e712e9285f 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlHandler.java @@ -9,8 +9,6 @@ import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.xml.rule.XmlRuleViolationFactory; /** * Implementation of LanguageVersionHandler for the XML. @@ -22,11 +20,6 @@ public class XmlHandler extends AbstractPmdLanguageVersionHandler { return new DefaultASTXPathHandler(); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return XmlRuleViolationFactory.INSTANCE; - } - @Override public ParserOptions getDefaultParserOptions() { return new XmlParserOptions(); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/XmlRuleViolationFactory.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/XmlRuleViolationFactory.java deleted file mode 100644 index 190ec2152a..0000000000 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/rule/XmlRuleViolationFactory.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.xml.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.xml.ast.XmlNode; - -public final class XmlRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new XmlRuleViolationFactory(); - - private XmlRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (XmlNode) node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - return null; // FIXME - } -}