diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 0bef07a821..9b26100791 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -31,7 +31,12 @@ This is a {{ site.pmd.release_type }} release. * {% jdoc java::lang.java.JavaLanguageHandler %} * {% jdoc java::lang.java.JavaLanguageParser %} * {% jdoc java::lang.java.JavaDataFlowHandler %} - +* Implementations of {% jdoc core::lang.rule.RuleViolationFactory %} in each + language module, eg {% jdoc java::lang.java.rule.JavaRuleViolationFactory %}. + See javadoc of {% jdoc core::lang.rule.RuleViolationFactory %}. +* Implementations of {% jdoc core::RuleViolation %} in each language module, + eg {% jdoc java::lang.java.rule.JavaRuleViolation %}. See javadoc of + {% jdoc core::RuleViolation %}. ##### For removal diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexHandler.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexHandler.java index 75da9b9195..70b4676523 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexHandler.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexHandler.java @@ -11,7 +11,6 @@ import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.VisitorStarter; -import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.apex.ast.ASTMethod; import net.sourceforge.pmd.lang.apex.ast.ASTUserClassOrInterface; import net.sourceforge.pmd.lang.apex.ast.ApexNode; @@ -19,8 +18,7 @@ import net.sourceforge.pmd.lang.apex.metrics.ApexMetricsComputer; import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey; import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey; import net.sourceforge.pmd.lang.apex.multifile.ApexMultifileVisitorFacade; -import net.sourceforge.pmd.lang.apex.rule.ApexRuleViolationFactory; -import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; +import net.sourceforge.pmd.lang.apex.rule.internal.ApexRuleViolationFactory; import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider; import net.sourceforge.pmd.lang.metrics.internal.AbstractLanguageMetricsProvider; import net.sourceforge.pmd.lang.rule.RuleViolationFactory; @@ -35,12 +33,6 @@ public class ApexHandler extends AbstractPmdLanguageVersionHandler { return rootNode -> new ApexMultifileVisitorFacade().initializeWith((ApexNode) rootNode); } - - @Override - public XPathHandler getXPathHandler() { - return new DefaultASTXPathHandler(); - } - @Override public RuleViolationFactory getRuleViolationFactory() { return ApexRuleViolationFactory.INSTANCE; diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexParser.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexParser.java index 5a9df7bbd1..d0e3834635 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexParser.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ApexParser.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.apex; import java.io.Reader; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; @@ -34,8 +33,4 @@ public class ApexParser extends AbstractParser { return apexParser.parse(source); } - @Override - public Map getSuppressMap() { - return apexParser.getSuppressMap(); - } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java index f2a0fcfa40..5ad8a6a620 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexRootNode.java @@ -4,6 +4,9 @@ package net.sourceforge.pmd.lang.apex.ast; +import java.util.Collections; +import java.util.Map; + import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.SourceCodePositioner; @@ -11,6 +14,9 @@ import apex.jorje.semantic.ast.AstNode; import apex.jorje.services.Version; public abstract class ApexRootNode extends AbstractApexNode implements RootNode { + + private Map noPmdComments = Collections.emptyMap(); + public ApexRootNode(T node) { super(node); } @@ -32,4 +38,14 @@ public abstract class ApexRootNode extends AbstractApexNode getNoPmdComments() { + return noPmdComments; + } + + void setNoPmdComments(Map noPmdComments) { + this.noPmdComments = noPmdComments; + } } diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolation.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolation.java deleted file mode 100644 index b5019a908e..0000000000 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolation.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.apex.rule; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.apex.ast.CanSuppressWarnings; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; - -/** - * This is an Apex RuleViolation. It knows how to try to extract the following - * extra information from the violation node: - *
    - *
  • Package name
  • - *
  • Class name
  • - *
  • Method name
  • - *
  • Variable name
  • - *
  • Suppression indicator
  • - *
- * @param - */ -@SuppressWarnings("PMD.UseUtilityClass") // we inherit non-static methods... -public class ApexRuleViolation extends ParametricRuleViolation { - - public ApexRuleViolation(Rule rule, RuleContext ctx, Node node, String message, int beginLine, int endLine) { - this(rule, ctx, node, message); - - setLines(beginLine, endLine); - } - - public ApexRuleViolation(Rule rule, RuleContext ctx, Node node, String message) { - super(rule, ctx, node, message); - - if (node != null) { - if (!suppressed) { - suppressed = isSupressed(node, getRule()); - } - } - } - - /** - * Check for suppression on this node, on parents, and on contained types - * for ASTCompilationUnit - * - * @deprecated Is internal API, not useful, there's a typo. See #1927 - */ - @Deprecated - public static boolean isSupressed(Node node, Rule rule) { - boolean result = suppresses(node, rule); - - if (!result) { - Node parent = node.jjtGetParent(); - while (!result && parent != null) { - result = suppresses(parent, rule); - parent = parent.jjtGetParent(); - } - } - - return result; - } - - private static boolean suppresses(final Node node, Rule rule) { - return node instanceof CanSuppressWarnings - && ((CanSuppressWarnings) node).hasSuppressWarningsAnnotationFor(rule); - } -} 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 deleted file mode 100644 index 1fd6ed544a..0000000000 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/ApexRuleViolationFactory.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.apex.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; - -public final class ApexRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final ApexRuleViolationFactory INSTANCE = new ApexRuleViolationFactory(); - - private ApexRuleViolationFactory() { - } - - @SuppressWarnings("rawtypes") - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ApexRuleViolation<>(rule, ruleContext, node, message); - } - - @Override - @SuppressWarnings("rawtypes") - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - return new ApexRuleViolation(rule, ruleContext, node, message, beginLine, endLine); - } -} diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/ApexRuleViolationFactory.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/ApexRuleViolationFactory.java new file mode 100644 index 0000000000..40a5e8cfd4 --- /dev/null +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/rule/internal/ApexRuleViolationFactory.java @@ -0,0 +1,71 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.apex.rule.internal; + +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; +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.impl.DefaultRuleViolationFactory; + +public final class ApexRuleViolationFactory extends DefaultRuleViolationFactory { + + public static final ApexRuleViolationFactory INSTANCE = new ApexRuleViolationFactory(); + private static final ViolationSuppressor APEX_ANNOT_SUPPRESSOR = new ViolationSuppressor() { + @Override + public String getId() { + return "@SuppressWarnings"; + } + + @Override + public Report.SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + if (isSuppressed(node, rv.getRule())) { + return new SuppressedViolation(rv, this, null); + } + return null; + } + }; + + private ApexRuleViolationFactory() { + } + + @Override + protected List getSuppressors() { + return Collections.singletonList(APEX_ANNOT_SUPPRESSOR); + } + + /** + * Check for suppression on this node, on parents, and on contained types + * for ASTCompilationUnit + * + * @param node + */ + private static boolean isSuppressed(Node node, Rule rule) { + boolean result = suppresses(node, rule); + + if (!result) { + Node parent = node.jjtGetParent(); + while (!result && parent != null) { + result = suppresses(parent, rule); + parent = parent.jjtGetParent(); + } + } + + return result; + } + + private static boolean suppresses(final Node node, Rule rule) { + return node instanceof CanSuppressWarnings + && ((CanSuppressWarnings) node).hasSuppressWarningsAnnotationFor(rule); + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java index 3ed4b2d9bd..ca702ec471 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/Report.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/Report.java @@ -42,7 +42,6 @@ public class Report implements Iterable { private final List listeners = new ArrayList<>(); private List errors; private List configErrors; - private Map linesToSuppress = new HashMap<>(); private long start; private long end; private List suppressedRuleViolations = new ArrayList<>(); @@ -177,72 +176,6 @@ public class Report implements Iterable { } } - /** - * Represents a violation, that has been suppressed. - */ - public static class SuppressedViolation { - private final RuleViolation rv; - private final boolean isNOPMD; - private final String userMessage; - - /** - * Creates a suppressed violation. - * - * @param rv - * the actual violation, that has been suppressed - * @param isNOPMD - * the suppression mode: true if it is - * suppressed via a NOPMD comment, false if - * suppressed via annotations. - * @param userMessage - * contains the suppressed code line or null - */ - public SuppressedViolation(RuleViolation rv, boolean isNOPMD, String userMessage) { - this.isNOPMD = isNOPMD; - this.rv = rv; - this.userMessage = userMessage; - } - - /** - * Returns true if the violation has been suppressed via a - * NOPMD comment. - * - * @return true if the violation has been suppressed via a - * NOPMD comment. - */ - public boolean suppressedByNOPMD() { - return this.isNOPMD; - } - - /** - * Returns true if the violation has been suppressed via a - * annotation. - * - * @return true if the violation has been suppressed via a - * annotation. - */ - public boolean suppressedByAnnotation() { - return !this.isNOPMD; - } - - public RuleViolation getRuleViolation() { - return this.rv; - } - - public String getUserMessage() { - return userMessage; - } - } - - /** - * Configure the lines, that are suppressed via a NOPMD comment. - * - * @param lines - * the suppressed lines - */ - public void suppress(Map lines) { - linesToSuppress = lines; - } private static String keyFor(RuleViolation rv) { @@ -301,6 +234,46 @@ public class Report implements Iterable { return suppressedRuleViolations; } + /** + * Represents a violation, that has been suppressed. + * TODO this should implement RuleViolation + */ + public static class SuppressedViolation { + private final RuleViolation rv; + private final String userMessage; + private final ViolationSuppressor suppressor; + + /** + * Creates a suppressed violation. + * + * @param rv The violation, that has been suppressed + * @param suppressor The suppressor which suppressed the violation + * @param userMessage Any relevant info given by the suppressor + */ + public SuppressedViolation(RuleViolation rv, ViolationSuppressor suppressor, String userMessage) { + this.suppressor = suppressor; + this.rv = rv; + this.userMessage = userMessage; + } + + public ViolationSuppressor getSuppressor() { + return suppressor; + } + + public RuleViolation getRuleViolation() { + return this.rv; + } + + public String getUserMessage() { + return userMessage; + } + } + + + public void addSuppressedViolation(SuppressedViolation sv) { + suppressedRuleViolations.add(sv); + } + /** * Adds a new rule violation to the report and notify the listeners. * @@ -308,19 +281,6 @@ public class Report implements Iterable { * the violation to add */ public void addRuleViolation(RuleViolation violation) { - - // NOPMD suppress - int line = violation.getBeginLine(); - if (linesToSuppress.containsKey(line)) { - suppressedRuleViolations.add(new SuppressedViolation(violation, true, linesToSuppress.get(line))); - return; - } - - if (violation.isSuppressed()) { - suppressedRuleViolations.add(new SuppressedViolation(violation, false, null)); - return; - } - int index = Collections.binarySearch(violations, violation, RuleViolationComparator.INSTANCE); violations.add(index < 0 ? -index - 1 : index, violation); violationTree.addRuleViolation(violation); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java index 7267ab4e1e..dc36455ba5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleViolation.java @@ -6,7 +6,11 @@ package net.sourceforge.pmd; /** * A RuleViolation is created by a Rule when it identifies a violation of the - * Rule constraints. + * Rule constraints. RuleViolations are simple data holders that are collected + * into a {@link Report}. + * + *

Since PMD 6.21.0, implementations of this interface are considered internal + * API and hence deprecated. Clients should exclusively use this interface. * * @see Rule */ @@ -26,13 +30,6 @@ public interface RuleViolation { */ String getDescription(); - /** - * Indicates whether this violation has been suppressed. - * - * @return true if this violation is suppressed, - * false otherwise. - */ - boolean isSuppressed(); /** * Get the source file name in which this violation was identified. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java index d7dcfd6881..99c192d018 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/SourceCodeProcessor.java @@ -120,9 +120,7 @@ public class SourceCodeProcessor { private Node parse(RuleContext ctx, Reader sourceCode, Parser parser) { try (TimedOperation to = TimeTracker.startOperation(TimedOperationCategory.PARSER)) { - Node rootNode = parser.parse(String.valueOf(ctx.getSourceCodeFile()), sourceCode); - ctx.getReport().suppress(parser.getSuppressMap()); - return rootNode; + return parser.parse(String.valueOf(ctx.getSourceCodeFile()), sourceCode); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java b/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java new file mode 100644 index 0000000000..6537e125d9 --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ViolationSuppressor.java @@ -0,0 +1,104 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +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; + +/** + * 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 { + + /** + * Suppressor for the violationSuppressRegex property. + */ + ViolationSuppressor REGEX_SUPPRESSOR = new ViolationSuppressor() { + @Override + public String getId() { + return "Regex"; + } + + @Override + 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); + } + } + return null; + } + }; + + /** + * Suppressor for the violationSuppressXPath property. + */ + ViolationSuppressor XPATH_SUPPRESSOR = new ViolationSuppressor() { + @Override + public String getId() { + return "XPath"; + } + + @Override + 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); + } + return null; + } + }; + + /** + * 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 getId() { + return "//NOPMD"; + } + + @Override + 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())); + } + return null; + } + }; + + + /** + * A name, for reporting and documentation purposes. + */ + String getId(); + + + /** + * Returns a {@link SuppressedViolation} if the given violation is + * suppressed by this object. The node and the rule are provided + * for context. Returns null if the violation is not suppressed. + */ + @Nullable + SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node); + + +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java index d881ea20ef..346f1f94a7 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/CachedRuleViolation.java @@ -69,11 +69,6 @@ public final class CachedRuleViolation implements RuleViolation { return description; } - @Override - public boolean isSuppressed() { - return false; // By definition, if cached, it was not suppressed - } - @Override public String getFilename() { return fileName; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/AbstractLanguageVersionHandler.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/AbstractLanguageVersionHandler.java index 0ec90bb10a..d038014d62 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/AbstractLanguageVersionHandler.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/AbstractLanguageVersionHandler.java @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang; -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.util.designerbindings.DesignerBindings; @@ -22,11 +21,6 @@ public abstract class AbstractLanguageVersionHandler implements LanguageVersionH return DataFlowHandler.DUMMY; } - @Override - public XPathHandler getXPathHandler() { - return new DefaultASTXPathHandler(); - } - @Override public ParserOptions getDefaultParserOptions() { return new ParserOptions(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java index 23cb3ff095..768ba0d59d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/LanguageRegistry.java @@ -12,6 +12,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.ServiceConfigurationError; import java.util.ServiceLoader; import java.util.Set; import java.util.TreeSet; @@ -34,12 +35,17 @@ public final class LanguageRegistry { // Use current class' classloader instead of the threads context classloader, see https://github.com/pmd/pmd/issues/1377 ServiceLoader languageLoader = ServiceLoader.load(Language.class, getClass().getClassLoader()); Iterator iterator = languageLoader.iterator(); - //noinspection WhileLoopReplaceableByForEach -- https://youtrack.jetbrains.com/issue/IDEA-223743 - while (iterator.hasNext()) { + while (true) { + // this loop is weird, but both hasNext and next may throw ServiceConfigurationError, + // it's more robust that way try { - Language language = iterator.next(); - sortedLangs.add(language); - } catch (UnsupportedClassVersionError e) { + if (iterator.hasNext()) { + Language language = iterator.next(); + sortedLangs.add(language); + } else { + break; + } + } catch (UnsupportedClassVersionError | ServiceConfigurationError e) { // Some languages require java8 and are therefore only available // if java8 or later is used as runtime. System.err.println("Ignoring language for PMD: " + e.toString()); 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 c12bb7da81..08c77a5ae9 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,11 @@ 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.RuleViolationFactory; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; import net.sourceforge.pmd.util.designerbindings.DesignerBindings; import net.sourceforge.pmd.util.designerbindings.DesignerBindings.DefaultDesignerBindings; @@ -32,7 +34,9 @@ public interface LanguageVersionHandler { /** * Get the XPathHandler. */ - XPathHandler getXPathHandler(); + default XPathHandler getXPathHandler() { + return new DefaultASTXPathHandler(); + } /** @@ -63,7 +67,9 @@ public interface LanguageVersionHandler { /** * Get the RuleViolationFactory. */ - RuleViolationFactory getRuleViolationFactory(); + default RuleViolationFactory getRuleViolationFactory() { + return DefaultRuleViolationFactory.defaultInstance(); + } /** diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/Parser.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/Parser.java index a8e02f4fd1..bcbb57241c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/Parser.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/Parser.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang; import java.io.Reader; -import java.util.Map; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.ParseException; @@ -47,21 +46,5 @@ public interface Parser { */ Node parse(String fileName, Reader source) throws ParseException; - /** - * Returns the map of line numbers to suppression / review comments. - * Only single line comments are considered, that start with the configured - * "suppressMarker", which by default is "PMD". The text after the - * suppressMarker is used as a "review comment" and included in this map. - * - *

- * This map is later used to determine, if a violation is being suppressed. - * It is suppressed, if the line of the violation is contained in this suppress map. - * - * @return map of the suppress lines with the corresponding review comments. - * - * @deprecated With 7.0.0, this method will be removed. To support - * suppressing with suppress markers, this method is still needed in PMD 6. - */ - @Deprecated - Map getSuppressMap(); + } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java index 87c1f65453..9603f6447a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/Node.java @@ -12,6 +12,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.checkerframework.checker.nullness.qual.NonNull; import org.jaxen.BaseXPath; import org.jaxen.JaxenException; import org.w3c.dom.Document; @@ -397,4 +398,17 @@ public interface Node { default Iterator getXPathAttributesIterator() { return new AttributeAxisIterator(this); } + + + @NonNull + default RootNode getRoot() { + Node r = this; + while (r != null && !(r instanceof RootNode)) { + r = r.jjtGetParent(); + } + if (r == null) { + throw new IllegalStateException("No root node in tree ?"); + } + return (RootNode) r; + } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/RootNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/RootNode.java index 2b50dabf8d..f90b65b102 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/RootNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/RootNode.java @@ -4,13 +4,35 @@ package net.sourceforge.pmd.lang.ast; +import java.util.Collections; +import java.util.Map; + +import net.sourceforge.pmd.annotation.Experimental; +import net.sourceforge.pmd.annotation.InternalApi; + /** * This interface can be used to tag the root node of various ASTs. */ public interface RootNode extends Node { // that's only a marker interface. - // TODO we could add some utilities here eg to get the file name, - // the language of the node, - // the source code of the file (as recently done in PLSQL - #1728), - // the whole token chain, etc + + + /** + * Returns the map of line numbers to suppression / review comments. + * Only single line comments are considered, that start with the configured + * "suppressMarker", which by default is "PMD". The text after the + * suppressMarker is used as a "review comment" and included in this map. + * + *

+ * This map is later used to determine, if a violation is being suppressed. + * It is suppressed, if the line of the violation is contained in this suppress map. + * + * @return map of the suppress lines with the corresponding review comments. + */ + @InternalApi + @Experimental + default Map getNoPmdComments() { + return Collections.emptyMap(); + } + } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java index f827bc4e1a..7a92e0d9ea 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrBaseParser.java @@ -6,8 +6,6 @@ package net.sourceforge.pmd.lang.ast.impl.antlr4; import java.io.IOException; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import org.antlr.v4.runtime.Lexer; @@ -51,11 +49,6 @@ public abstract class AntlrBaseParser imp } } - @Override - public Map getSuppressMap() { - return new HashMap<>(); - } - protected abstract AntlrBaseNode getRootNode(T parser); protected abstract Lexer getLexer(Reader source) throws IOException; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrRuleViolationFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrRuleViolationFactory.java deleted file mode 100644 index b7d74c45a7..0000000000 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrRuleViolationFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.ast.impl.antlr4; - -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 AntlrRuleViolationFactory extends AbstractRuleViolationFactory { - public static final RuleViolationFactory INSTANCE = new AntlrRuleViolationFactory(); - - private AntlrRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(final Rule rule, final RuleContext ruleContext, final Node node, - final String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (AntlrBaseNode) 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, - (AntlrBaseNode) node, message); - violation.setLines(beginLine, endLine); - return violation; - } -} 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 3f01c4b74b..361111e08c 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 @@ -1,54 +1,15 @@ -/** +/* * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.lang.rule; -import java.text.MessageFormat; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; -import org.apache.commons.lang3.StringUtils; - -import net.sourceforge.pmd.Rule; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.ast.Node; - -public abstract class AbstractRuleViolationFactory implements RuleViolationFactory { - - private static final Object[] NO_ARGS = new Object[0]; - - private String cleanup(String message, Object[] args) { - - if (message != null) { - // Escape PMD specific variable message format, specifically the { - // in the ${, so MessageFormat doesn't bitch. - final String escapedMessage = StringUtils.replace(message, "${", "$'{'"); - return MessageFormat.format(escapedMessage, args != null ? args : NO_ARGS); - } else { - return message; - } - } - - @Override - public void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, Object[] args) { - - String formattedMessage = cleanup(message, args); - - ruleContext.getReport().addRuleViolation(createRuleViolation(rule, ruleContext, node, formattedMessage)); - } - - @Override - public void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, int beginLine, int endLine, - Object[] args) { - - String formattedMessage = cleanup(message, args); - - ruleContext.getReport() - .addRuleViolation(createRuleViolation(rule, ruleContext, node, formattedMessage, beginLine, endLine)); - } - - protected abstract RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message); - - protected abstract RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine); +/** + * @deprecated This is kept for binary compatibility with the 6.x designer, yet will + * go away in 7.0. Use {@link DefaultRuleViolationFactory} + */ +@Deprecated +public class AbstractRuleViolationFactory extends DefaultRuleViolationFactory { } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java index 1e8e4c68f5..8e8073aced 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/ParametricRuleViolation.java @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.rule; import java.io.File; -import java.util.regex.Pattern; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; @@ -18,7 +17,6 @@ public class ParametricRuleViolation implements RuleViolation { protected final Rule rule; protected final String description; - protected boolean suppressed; protected String filename; protected int beginLine; @@ -36,6 +34,7 @@ public class ParametricRuleViolation implements RuleViolation { // must not (to prevent erroneous Rules silently logging w/o a Node). Modify // RuleViolationFactory to support identifying without a Node, and update // Rule base classes too. + // TODO we never need a node. We just have to have a "position", ie line/column, or offset, + file, whatever public ParametricRuleViolation(Rule theRule, RuleContext ctx, T node, String message) { rule = theRule; description = message; @@ -53,28 +52,6 @@ public class ParametricRuleViolation implements RuleViolation { endColumn = node.getEndColumn(); } - // Apply Rule specific suppressions - if (node != null && rule != null) { - setSuppression(rule, node); - } - - } - - private void setSuppression(Rule rule, T node) { - - String regex = rule.getProperty(Rule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR); // Regex - if (regex != null && description != null) { - if (Pattern.matches(regex, description)) { - suppressed = true; - } - } - - if (!suppressed) { // XPath - String xpath = rule.getProperty(Rule.VIOLATION_SUPPRESS_XPATH_DESCRIPTOR); - if (xpath != null) { - suppressed = node.hasDescendantMatchingXPath(xpath); - } - } } protected String expandVariables(String message) { @@ -127,11 +104,6 @@ public class ParametricRuleViolation implements RuleViolation { return expandVariables(description); } - @Override - public boolean isSuppressed() { - return suppressed; - } - @Override public String getFilename() { return filename; 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..f759cf69dd 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,13 +4,20 @@ 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.LanguageVersionHandler; import net.sourceforge.pmd.lang.ast.Node; /** * This class handles of producing a Language specific RuleViolation and adding * to a Report. + * + *

Since PMD 6.21.0, implementations of this interface are considered internal + * API and hence deprecated. Clients should exclusively use this interface and obtain + * instances through {@link LanguageVersionHandler#getRuleViolationFactory()}. */ public interface RuleViolationFactory { /** @@ -27,8 +34,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/main/java/net/sourceforge/pmd/lang/rule/impl/DefaultRuleViolationFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/impl/DefaultRuleViolationFactory.java new file mode 100644 index 0000000000..c5fa2d5e6e --- /dev/null +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/impl/DefaultRuleViolationFactory.java @@ -0,0 +1,124 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.rule.impl; + +import java.text.MessageFormat; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.nullness.qual.Nullable; + +import net.sourceforge.pmd.Report.SuppressedViolation; +import net.sourceforge.pmd.Rule; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.ViolationSuppressor; +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.lang.rule.RuleViolationFactory; + +/** + * 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. + */ +public class DefaultRuleViolationFactory implements RuleViolationFactory { + + private static final Object[] NO_ARGS = new Object[0]; + + private static final DefaultRuleViolationFactory DEFAULT = new DefaultRuleViolationFactory(); + private Set allSuppressors; + + private String cleanup(String message, Object[] args) { + + if (message != null) { + // Escape PMD specific variable message format, specifically the { + // in the ${, so MessageFormat doesn't bitch. + final String escapedMessage = StringUtils.replace(message, "${", "$'{'"); + return MessageFormat.format(escapedMessage, args != null ? args : NO_ARGS); + } else { + return message; + } + } + + + @Override + public void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, Object[] args) { + + String formattedMessage = cleanup(message, args); + + RuleViolation rv = createRuleViolation(rule, ruleContext, node, formattedMessage); + maybeSuppress(ruleContext, node, rv); + } + + @Override + public void addViolation(RuleContext ruleContext, Rule rule, Node node, String message, int beginLine, int endLine, Object[] args) { + + String formattedMessage = cleanup(message, args); + + RuleViolation rv = createRuleViolation(rule, ruleContext, node, formattedMessage, beginLine, endLine); + maybeSuppress(ruleContext, node, rv); + } + + private void maybeSuppress(RuleContext ruleContext, @Nullable Node node, RuleViolation rv) { + + if (node != null) { + // note: no suppression when node is null. + // Node should in fact never be null, this is todo for later + + for (ViolationSuppressor suppressor : getAllSuppressors()) { + SuppressedViolation suppressed = suppressor.suppressOrNull(rv, node); + if (suppressed != null) { + ruleContext.getReport().addSuppressedViolation(suppressed); + return; + } + } + } + + ruleContext.getReport().addRuleViolation(rv); + } + + /** + * Returns a list of additional suppressors for this language. These + * are added to regular //NOPMD, regex and XPath suppression. + */ + protected List getSuppressors() { + return Collections.emptyList(); + } + + protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { + return new ParametricRuleViolation<>(rule, ruleContext, node, message); + } + + protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, + int beginLine, int endLine) { + ParametricRuleViolation rv = new ParametricRuleViolation<>(rule, ruleContext, node, message); + rv.setLines(beginLine, endLine); + return rv; + } + + private Set getAllSuppressors() { + if (allSuppressors == null) { + // lazy loaded because calling getSuppressors in constructor + // is not safe wrt initialization of static constants + // (order dependent otherwise) + this.allSuppressors = new LinkedHashSet<>(getSuppressors()); + allSuppressors.add(ViolationSuppressor.NOPMD_COMMENT_SUPPRESSOR); + allSuppressors.add(ViolationSuppressor.REGEX_SUPPRESSOR); + allSuppressors.add(ViolationSuppressor.XPATH_SUPPRESSOR); + } + return allSuppressors; + } + + /** Returns the default instance (no additional suppressors, creates a ParametricRuleViolation). */ + public static RuleViolationFactory defaultInstance() { + return DEFAULT; + } +} diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/HTMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/HTMLRenderer.java index 49e7551fb1..36a2222c26 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/HTMLRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/HTMLRenderer.java @@ -113,13 +113,13 @@ public class HTMLRenderer extends AbstractIncrementingRenderer { buf.append(" bgcolor=\"lightgrey\""); } colorize = !colorize; - buf.append("> " + PMD.EOL); - buf.append("" + violationCount + "" + PMD.EOL); - buf.append("" - + maybeWrap(StringEscapeUtils.escapeHtml4(determineFileName(rv.getFilename())), - linePrefix == null ? "" : linePrefix + Integer.toString(rv.getBeginLine())) - + "" + PMD.EOL); - buf.append("" + Integer.toString(rv.getBeginLine()) + "" + PMD.EOL); + buf.append("> ").append(PMD.EOL); + buf.append("").append(violationCount).append("").append(PMD.EOL); + buf.append("") + .append(maybeWrap(StringEscapeUtils.escapeHtml4(determineFileName(rv.getFilename())), linePrefix == null ? "" : linePrefix + rv.getBeginLine())) + .append("") + .append(PMD.EOL); + buf.append("").append(rv.getBeginLine()).append("").append(PMD.EOL); String d = StringEscapeUtils.escapeHtml4(rv.getDescription()); @@ -127,8 +127,11 @@ public class HTMLRenderer extends AbstractIncrementingRenderer { if (StringUtils.isNotBlank(infoUrl)) { d = "" + d + ""; } - buf.append("" + d + "" + PMD.EOL); - buf.append("" + PMD.EOL); + buf.append("") + .append(d) + .append("") + .append(PMD.EOL) + .append("").append(PMD.EOL); writer.write(buf.toString()); violationCount++; } @@ -154,10 +157,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer { buf.append(" bgcolor=\"lightgrey\""); } colorize = !colorize; - buf.append("> " + PMD.EOL); - buf.append("" + determineFileName(pe.getFile()) + "" + PMD.EOL); - buf.append("

" + pe.getDetail() + "
" + PMD.EOL); - buf.append("" + PMD.EOL); + buf.append("> ").append(PMD.EOL); + buf.append("").append(determineFileName(pe.getFile())).append("").append(PMD.EOL); + buf.append("
").append(pe.getDetail()).append("
").append(PMD.EOL); + buf.append("").append(PMD.EOL); writer.write(buf.toString()); } writer.write(""); @@ -182,19 +185,19 @@ public class HTMLRenderer extends AbstractIncrementingRenderer { buf.append(" bgcolor=\"lightgrey\""); } colorize = !colorize; - buf.append("> " + PMD.EOL); - buf.append("" + determineFileName(sv.getRuleViolation().getFilename()) + "" + PMD.EOL); - buf.append("" + sv.getRuleViolation().getBeginLine() + "" + PMD.EOL); - buf.append("" + sv.getRuleViolation().getRule().getName() + "" + PMD.EOL); - buf.append("" + (sv.suppressedByNOPMD() ? "NOPMD" : "Annotation") + "" + PMD.EOL); - buf.append("" + (sv.getUserMessage() == null ? "" : sv.getUserMessage()) + "" - + PMD.EOL); - buf.append("" + PMD.EOL); + buf.append("> ").append(PMD.EOL); + buf.append("").append(determineFileName(sv.getRuleViolation().getFilename())).append("").append(PMD.EOL); + buf.append("").append(sv.getRuleViolation().getBeginLine()).append("").append(PMD.EOL); + buf.append("").append(sv.getRuleViolation().getRule().getName()).append("").append(PMD.EOL); + buf.append("").append(sv.getSuppressor().getId()).append("").append(PMD.EOL); + buf.append("").append( + sv.getUserMessage() == null ? "" : sv.getUserMessage()).append("").append(PMD.EOL); + buf.append("").append(PMD.EOL); writer.write(buf.toString()); } writer.write(""); } - + private void glomConfigurationErrors(final Writer writer, final List configErrors) throws IOException { if (configErrors.isEmpty()) { return; @@ -214,10 +217,10 @@ public class HTMLRenderer extends AbstractIncrementingRenderer { buf.append(" bgcolor=\"lightgrey\""); } colorize = !colorize; - buf.append("> " + PMD.EOL); - buf.append("" + ce.rule().getName() + "" + PMD.EOL); - buf.append("" + ce.issue() + "" + PMD.EOL); - buf.append("" + PMD.EOL); + buf.append("> ").append(PMD.EOL); + buf.append("").append(ce.rule().getName()).append("").append(PMD.EOL); + buf.append("").append(ce.issue()).append("").append(PMD.EOL); + buf.append("").append(PMD.EOL); writer.write(buf.toString()); } writer.write(""); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java index f3d3a70eae..e541aad8a1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/TextRenderer.java @@ -35,7 +35,7 @@ public class TextRenderer extends AbstractIncrementingRenderer { buf.setLength(0); RuleViolation rv = violations.next(); buf.append(determineFileName(rv.getFilename())); - buf.append(':').append(Integer.toString(rv.getBeginLine())); + buf.append(':').append(rv.getBeginLine()); buf.append(":\t").append(rv.getDescription()).append(PMD.EOL); writer.write(buf.toString()); } @@ -44,7 +44,7 @@ public class TextRenderer extends AbstractIncrementingRenderer { @Override public void end() throws IOException { StringBuilder buf = new StringBuilder(500); - + for (Report.ProcessingError error : errors) { buf.setLength(0); buf.append(determineFileName(error.getFile())); @@ -54,13 +54,15 @@ public class TextRenderer extends AbstractIncrementingRenderer { for (Report.SuppressedViolation excluded : suppressed) { buf.setLength(0); - buf.append(excluded.getRuleViolation().getRule().getName()); - buf.append(" rule violation suppressed by "); - buf.append(excluded.suppressedByNOPMD() ? "//NOPMD" : "Annotation"); - buf.append(" in ").append(determineFileName(excluded.getRuleViolation().getFilename())).append(PMD.EOL); + buf.append(excluded.getRuleViolation().getRule().getName()) + .append(" rule violation suppressed by ") + .append(excluded.getSuppressor().getId()) + .append(" in ") + .append(determineFileName(excluded.getRuleViolation().getFilename())) + .append(PMD.EOL); writer.write(buf.toString()); } - + for (Report.ConfigurationError error : configErrors) { buf.setLength(0); buf.append(error.rule().getName()); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java index 80e70f9a23..dde1c0c514 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; +import java.util.Locale; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMDVersion; @@ -135,7 +136,7 @@ public class XMLRenderer extends AbstractIncrementingRenderer { buf.append(" m = new HashMap<>(); - m.put(Integer.valueOf(5), ""); - ctx.setReport(new Report()); - ctx.getReport().suppress(m); + m.put(5, ""); ctx.setSourceCodeFile(new File("filename")); - DummyNode n = new DummyNode(1); - n.testingOnlySetBeginColumn(5); - n.testingOnlySetBeginLine(5); - RuleViolation rv = new ParametricRuleViolation<>(r, ctx, n, "specificdescription"); - ctx.getReport().addRuleViolation(rv); + DummyRoot n = new DummyRoot(m); + n.setCoords(5, 1, 6, 0); + DefaultRuleViolationFactory.defaultInstance().addViolation(ctx, r, n, "specificdescription", new Object[0]); + assertTrue(ctx.getReport().isEmpty()); } @@ -210,7 +208,7 @@ public class AbstractRuleTest { assertEquals("Rules with different messages are still equal", r1, r2); assertEquals("Rules that are equal must have the an equal hashcode", r1.hashCode(), r2.hashCode()); } - + @Test public void testDeepCopyRule() { MyRule r1 = new MyRule(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java index 0dea767696..8a5f498594 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java @@ -30,6 +30,7 @@ import net.sourceforge.pmd.lang.Dummy2LanguageModule; 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.Node; import net.sourceforge.pmd.lang.rule.MockRule; import net.sourceforge.pmd.lang.rule.RuleReference; @@ -501,9 +502,8 @@ public class RuleSetTest { private List makeCompilationUnits() { List nodes = new ArrayList<>(); - DummyNode node = new DummyNode(1); - node.testingOnlySetBeginLine(1); - node.testingOnlySetBeginColumn(1); + DummyNode node = new DummyRoot(); + node.setCoords(1, 1, 10, 1); node.setImage("Foo"); nodes.add(node); return nodes; 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 efb79b5ee3..b6b0205419 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 @@ -7,21 +7,19 @@ package net.sourceforge.pmd.lang; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Map; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.ast.DummyAstStages; import net.sourceforge.pmd.lang.ast.DummyNode; +import net.sourceforge.pmd.lang.ast.DummyRoot; 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.ParametricRuleViolation; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; /** * Dummy language used for testing PMD. @@ -80,18 +78,12 @@ public class DummyLanguageModule extends BaseLanguageModule { return new AbstractParser(parserOptions) { @Override public Node parse(String fileName, Reader source) throws ParseException { - DummyNode node = new DummyRootNode(1); - node.testingOnlySetBeginLine(1); - node.testingOnlySetBeginColumn(1); + DummyNode node = new DummyRoot(); + node.setCoords(1, 1, 2, 10); node.setImage("Foo"); return node; } - @Override - public Map getSuppressMap() { - return Collections.emptyMap(); - } - @Override protected TokenManager createTokenManager(Reader source) { return null; @@ -100,15 +92,7 @@ public class DummyLanguageModule extends BaseLanguageModule { } } - private static class DummyRootNode extends DummyNode implements RootNode { - - DummyRootNode(int id) { - super(id); - } - - } - - 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); @@ -118,6 +102,7 @@ public class DummyLanguageModule extends BaseLanguageModule { protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, int beginLine, int endLine) { ParametricRuleViolation rv = new ParametricRuleViolation(rule, ruleContext, node, message) { + @Override public String getPackageName() { this.packageName = "foo"; // just for testing variable expansion return super.getPackageName(); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java index 0304e2d88f..aac0f74494 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyNode.java @@ -20,6 +20,21 @@ public class DummyNode extends AbstractNode { this.findBoundary = findBoundary; } + public void setBeginColumn(int i) { + beginColumn = i; + } + + public void setBeginLine(int i) { + beginLine = i; + } + + public void setCoords(int bline, int bcol, int eline, int ecol) { + beginLine = bline; + beginColumn = bcol; + endLine = eline; + endColumn = ecol; + } + @Override public String toString() { return "dummyNode"; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyRoot.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyRoot.java new file mode 100644 index 0000000000..aa253a51c7 --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/DummyRoot.java @@ -0,0 +1,38 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.ast; + +import java.util.Collections; +import java.util.Map; + +public class DummyRoot extends DummyNode implements RootNode { + + private final Map suppressMap; + + public DummyRoot(Map suppressMap) { + super(0); + this.suppressMap = suppressMap; + } + + public DummyRoot() { + this(Collections.emptyMap()); + } + + @Override + public Map getNoPmdComments() { + return suppressMap; + } + + @Override + public String toString() { + return "dummyNode"; + } + + @Override + public String getXPathNodeName() { + return "dummyNode"; + } + +} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/DocumentNavigatorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/DocumentNavigatorTest.java index f6158c45b6..aa316e9313 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/DocumentNavigatorTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/xpath/DocumentNavigatorTest.java @@ -11,20 +11,14 @@ import static org.junit.Assert.fail; import org.junit.Test; import net.sourceforge.pmd.lang.ast.DummyNode; +import net.sourceforge.pmd.lang.ast.DummyRoot; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.ast.RootNode; /** * Unit test for {@link DocumentNavigator} */ public class DocumentNavigatorTest { - private static class DummyRootNode extends DummyNode implements RootNode { - DummyRootNode(int id) { - super(id); - } - } - @Test public void getDocumentNode() { DocumentNavigator nav = new DocumentNavigator(); @@ -36,7 +30,7 @@ public class DocumentNavigatorTest { assertNotNull(e); } - Node root = new DummyRootNode(1); + Node root = new DummyRoot(); Node n = new DummyNode(1); root.jjtAddChild(n, 0); n.jjtSetParent(root); 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/DefaultRuleViolationFactoryTest.java similarity index 60% rename from pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/AbstractRuleViolationFactoryTest.java rename to pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/DefaultRuleViolationFactoryTest.java index beb48181f5..ee1608520d 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/DefaultRuleViolationFactoryTest.java @@ -10,29 +10,14 @@ 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; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; -public class AbstractRuleViolationFactoryTest { +public class DefaultRuleViolationFactoryTest { 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 RuleViolationFactory factory = DefaultRuleViolationFactory.defaultInstance(); private static class TestRule extends AbstractRule { @Override @@ -44,9 +29,8 @@ public class AbstractRuleViolationFactoryTest { @Before public void setup() { ruleContext = new RuleContext(); - factory = new TestRuleViolationFactory(); } - + @Test public void testMessage() { factory.addViolation(ruleContext, new TestRule(), null, "message with \"'{'\"", null); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java index e3715069e1..3a9b1691ac 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SummaryHTMLRendererTest.java @@ -18,8 +18,8 @@ import net.sourceforge.pmd.Report.ConfigurationError; import net.sourceforge.pmd.Report.ProcessingError; import net.sourceforge.pmd.ReportTest; import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.lang.ast.DummyRoot; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; public class SummaryHTMLRendererTest extends AbstractRendererTest { @@ -98,7 +98,7 @@ public class SummaryHTMLRendererTest extends AbstractRendererTest { + "file" + PMD.EOL + "
" + error.getDetail() + "
" + PMD.EOL + "" + PMD.EOL + "" + PMD.EOL; } - + @Override public String getExpectedError(ConfigurationError error) { return "PMD" + PMD.EOL + "

Summary

" + PMD.EOL @@ -131,7 +131,8 @@ public class SummaryHTMLRendererTest extends AbstractRendererTest { + PMD.EOL + "FileLineRuleNOPMD or AnnotationReason" + PMD.EOL + " " + PMD.EOL + "" + PMD.EOL + "1" + PMD.EOL + "Foo" + PMD.EOL - + "NOPMD" + PMD.EOL + "test" + PMD.EOL + "" + + "//NOPMD" + PMD.EOL + "test" + PMD.EOL + + "" + PMD.EOL + "" + PMD.EOL, actual); } @@ -145,15 +146,12 @@ public class SummaryHTMLRendererTest extends AbstractRendererTest { } private Report createEmptyReportWithSuppression() { - Report rep = new Report(); Map suppressions = new HashMap<>(); suppressions.put(1, "test"); - rep.suppress(suppressions); RuleContext ctx = new RuleContext(); - ParametricRuleViolation violation = new ParametricRuleViolation<>(new FooRule(), ctx, null, - "suppress test"); - violation.setLines(1, 1); - rep.addRuleViolation(violation); - return rep; + DummyRoot root = new DummyRoot(suppressions); + root.setCoords(1, 10, 4, 5); + DefaultRuleViolationFactory.defaultInstance().addViolation(ctx, new FooRule(), root, "suppress test", 1, 1, new Object[0]); + return ctx.getReport(); } } diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index b365610e64..f02ed633fe 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -253,7 +253,7 @@ import net.sourceforge.pmd.lang.ast.CharStream; import net.sourceforge.pmd.lang.ast.TokenMgrError; import net.sourceforge.pmd.lang.ast.Node; -public class JavaParser { +class JavaParser { private int jdkVersion = 0; private boolean preview = false; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java index 13ef017efc..d8df4fab76 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTCompilationUnit.java @@ -4,7 +4,9 @@ package net.sourceforge.pmd.lang.java.ast; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.checkerframework.checker.nullness.qual.NonNull; @@ -19,6 +21,7 @@ public final class ASTCompilationUnit extends AbstractJavaTypeNode implements Ro private ClassTypeResolver classTypeResolver; private List comments; + private Map noPmdComments = Collections.emptyMap(); ASTCompilationUnit(int id) { super(id); @@ -93,4 +96,13 @@ public final class ASTCompilationUnit extends AbstractJavaTypeNode implements Ro public void setClassTypeResolver(ClassTypeResolver classTypeResolver) { this.classTypeResolver = classTypeResolver; } + + @Override + public Map getNoPmdComments() { + return noPmdComments; + } + + void setNoPmdComments(Map noPmdComments) { + this.noPmdComments = noPmdComments; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index 161b2adb1d..374c755c67 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -4,7 +4,12 @@ package net.sourceforge.pmd.lang.java.ast; +import java.io.Reader; + import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.lang.ParserOptions; +import net.sourceforge.pmd.lang.ast.AbstractTokenManager; +import net.sourceforge.pmd.lang.ast.JavaCharStream; import net.sourceforge.pmd.lang.java.qname.JavaOperationQualifiedName; import net.sourceforge.pmd.lang.java.qname.JavaTypeQualifiedName; import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition; @@ -58,5 +63,19 @@ public final class InternalApiBridge { } } + public static ASTCompilationUnit parseInternal(String fileName, Reader source, int jdkVersion, boolean preview, ParserOptions options) { + JavaParser parser = new JavaParser(new JavaCharStream(source)); + String suppressMarker = options.getSuppressMarker(); + if (suppressMarker != null) { + parser.setSuppressMarker(suppressMarker); + } + parser.setJdkVersion(jdkVersion); + parser.setPreview(preview); + + AbstractTokenManager.setFileName(fileName); + ASTCompilationUnit acu = parser.CompilationUnit(); + acu.setNoPmdComments(parser.getSuppressMap()); + return acu; + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java index 9e160a5098..d0c66e3129 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageHandler.java @@ -28,7 +28,7 @@ import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey; import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey; import net.sourceforge.pmd.lang.java.multifile.MultifileVisitorFacade; import net.sourceforge.pmd.lang.java.qname.QualifiedNameResolver; -import net.sourceforge.pmd.lang.java.rule.JavaRuleViolationFactory; +import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleViolationFactory; import net.sourceforge.pmd.lang.java.symboltable.SymbolFacade; import net.sourceforge.pmd.lang.java.typeresolution.TypeResolutionFacade; import net.sourceforge.pmd.lang.java.xpath.GetCommentOnFunction; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageParser.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageParser.java index 0c6faae2cd..41b84e2011 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageParser.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageParser.java @@ -6,16 +6,13 @@ package net.sourceforge.pmd.lang.java.internal; import java.io.Reader; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.AbstractTokenManager; -import net.sourceforge.pmd.lang.ast.JavaCharStream; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.JavaTokenManager; -import net.sourceforge.pmd.lang.java.ast.JavaParser; +import net.sourceforge.pmd.lang.java.ast.InternalApiBridge; import net.sourceforge.pmd.lang.java.ast.ParseException; /** @@ -28,7 +25,6 @@ public class JavaLanguageParser extends AbstractParser { private final int jdkVersion; private final boolean preview; - private JavaParser javaParser; public JavaLanguageParser(int jdkVersion, boolean preview, ParserOptions parserOptions) { super(parserOptions); @@ -41,26 +37,9 @@ public class JavaLanguageParser extends AbstractParser { return new JavaTokenManager(source); } - private JavaParser createJavaParser(Reader source) throws ParseException { - javaParser = new JavaParser(new JavaCharStream(source)); - javaParser.setJdkVersion(jdkVersion); - javaParser.setPreview(preview); - String suppressMarker = getParserOptions().getSuppressMarker(); - if (suppressMarker != null) { - javaParser.setSuppressMarker(suppressMarker); - } - return javaParser; - } - @Override public Node parse(String fileName, Reader source) throws ParseException { - AbstractTokenManager.setFileName(fileName); - return createJavaParser(source).CompilationUnit(); - } - - @Override - public Map getSuppressMap() { - return javaParser.getSuppressMap(); + return InternalApiBridge.parseInternal(fileName, source, jdkVersion, preview, getParserOptions()); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java index 9b45c5b64d..8b1d88ccc9 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolation.java @@ -11,6 +11,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; 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.java.ast.ASTAnyTypeDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; @@ -34,7 +35,9 @@ import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; *
  • Variable name
  • *
  • Suppression indicator
  • * + * @deprecated See {@link RuleViolation} */ +@Deprecated public class JavaRuleViolation extends ParametricRuleViolation { public JavaRuleViolation(Rule rule, RuleContext ctx, JavaNode node, String message, int beginLine, int endLine) { @@ -54,10 +57,6 @@ public class JavaRuleViolation extends ParametricRuleViolation { className = getClassName(node); methodName = getMethodName(node); variableName = getVariableNameIfExists(node); - - if (!suppressed) { - suppressed = AnnotationSuppressionUtil.contextSuppresses(node, getRule()); - } } } 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 deleted file mode 100644 index 0c09a95cde..0000000000 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactory.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.java.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.java.ast.JavaNode; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; - -public final class JavaRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final RuleViolationFactory INSTANCE = new JavaRuleViolationFactory(); - - private JavaRuleViolationFactory() { - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new JavaRuleViolation(rule, ruleContext, (JavaNode) node, message); - } - - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, - int beginLine, int endLine) { - return new JavaRuleViolation(rule, ruleContext, (JavaNode) node, message, beginLine, endLine); - } - -} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DaaRuleViolation.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DaaRuleViolation.java index 40dfc8b977..1ccb8b7dfd 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DaaRuleViolation.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/DaaRuleViolation.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.errorprone; 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.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.rule.JavaRuleViolation; @@ -16,7 +17,9 @@ import net.sourceforge.pmd.lang.java.rule.JavaRuleViolation; * * @author Sven Jacob * @author Brian Remedios + * @deprecated See {@link RuleViolation} */ +@Deprecated public class DaaRuleViolation extends JavaRuleViolation { private final String variableName; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/JavaRuleViolationFactory.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/JavaRuleViolationFactory.java new file mode 100644 index 0000000000..a7f2dc595b --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/internal/JavaRuleViolationFactory.java @@ -0,0 +1,62 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.internal; + +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; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.ViolationSuppressor; +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.java.ast.JavaNode; +import net.sourceforge.pmd.lang.java.rule.JavaRuleViolation; +import net.sourceforge.pmd.lang.rule.RuleViolationFactory; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; + +public final class JavaRuleViolationFactory extends DefaultRuleViolationFactory { + + public static final RuleViolationFactory INSTANCE = new JavaRuleViolationFactory(); + private static final ViolationSuppressor JAVA_ANNOT_SUPPRESSOR = new ViolationSuppressor() { + @Override + public String getId() { + return "@SuppressWarnings"; + } + + @Override + public Report.SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node) { + if (JavaRuleViolation.isSupressed(node, rv.getRule())) { // todo use AnnotationSuppressionUtil + return new SuppressedViolation(rv, this, null); + } + return null; + } + }; + + private JavaRuleViolationFactory() { + // singleton + } + + @Override + protected List getSuppressors() { + return Collections.singletonList(JAVA_ANNOT_SUPPRESSOR); + } + + @Override + protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { + return new JavaRuleViolation(rule, ruleContext, (JavaNode) node, message); + } + + @Override + protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, + int beginLine, int endLine) { + return new JavaRuleViolation(rule, ruleContext, (JavaNode) node, message, beginLine, endLine); + } + +} diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactoryTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactoryTest.java index fab7669e39..1ddbf886a9 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactoryTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/JavaRuleViolationFactoryTest.java @@ -8,6 +8,7 @@ import org.junit.Test; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.java.rule.codestyle.DuplicateImportsRule; +import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleViolationFactory; import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Handler.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Handler.java index ed522cf505..9a6fd84912 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Handler.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Handler.java @@ -7,26 +7,12 @@ package net.sourceforge.pmd.lang.ecmascript; 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.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** * Implementation of LanguageVersionHandler for the ECMAScript Version 3. */ public class Ecmascript3Handler extends AbstractPmdLanguageVersionHandler { - @Override - public XPathHandler getXPathHandler() { - return new DefaultASTXPathHandler(); - } - - @Override - public RuleViolationFactory getRuleViolationFactory() { - return EcmascriptRuleViolationFactory.INSTANCE; - } - @Override public ParserOptions getDefaultParserOptions() { return new EcmascriptParserOptions(); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Parser.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Parser.java index 5ba40dc664..33e05b7e7e 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Parser.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/Ecmascript3Parser.java @@ -5,13 +5,12 @@ package net.sourceforge.pmd.lang.ecmascript; import java.io.Reader; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.TokenManager; -import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.ParseException; +import net.sourceforge.pmd.lang.ecmascript.ast.ASTAstRoot; import net.sourceforge.pmd.lang.ecmascript5.Ecmascript5TokenManager; /** @@ -32,12 +31,8 @@ public class Ecmascript3Parser extends AbstractParser { } @Override - public Node parse(String fileName, Reader source) throws ParseException { + public ASTAstRoot parse(String fileName, Reader source) throws ParseException { return ecmascriptParser.parse(source); } - @Override - public Map getSuppressMap() { - return ecmascriptParser.getSuppressMap(); - } } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java index 219ed2577b..d3786e9a8b 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/EcmascriptLanguageModule.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.ecmascript; import net.sourceforge.pmd.lang.BaseLanguageModule; +import net.sourceforge.pmd.lang.LanguageVersionHandler; import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleChainVisitor; /** @@ -12,12 +13,17 @@ import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleChainVisitor; */ public class EcmascriptLanguageModule extends BaseLanguageModule { + private static final Ecmascript3Handler DEFAULT = new Ecmascript3Handler(); + public static final String NAME = "Ecmascript"; public static final String TERSE_NAME = "ecmascript"; public EcmascriptLanguageModule() { super(NAME, null, TERSE_NAME, EcmascriptRuleChainVisitor.class, "js"); - addVersion("3", new Ecmascript3Handler(), true); + addVersion("3", DEFAULT, true); } + public static LanguageVersionHandler defaultHandler() { + return DEFAULT; + } } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java index b4976f84e1..8edb11ca14 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/ASTAstRoot.java @@ -4,11 +4,17 @@ package net.sourceforge.pmd.lang.ecmascript.ast; +import java.util.Collections; +import java.util.Map; + import org.mozilla.javascript.ast.AstRoot; import net.sourceforge.pmd.lang.ast.RootNode; public class ASTAstRoot extends AbstractEcmascriptNode implements RootNode { + + private Map noPmdComments = Collections.emptyMap(); + public ASTAstRoot(AstRoot astRoot) { super(astRoot); } @@ -25,6 +31,16 @@ public class ASTAstRoot extends AbstractEcmascriptNode implements RootN return node.getComments() != null ? node.getComments().size() : 0; } + + @Override + public Map getNoPmdComments() { + return noPmdComments; + } + + void setNoPmdComments(Map noPmdComments) { + this.noPmdComments = noPmdComments; + } + public ASTComment getComment(int index) { return (ASTComment) jjtGetChild(jjtGetNumChildren() - 1 - getNumComments() + index); } diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java index 0ef196dbb7..b0c16ea59e 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java @@ -58,13 +58,13 @@ public class EcmascriptParser { return astRoot; } - public EcmascriptNode parse(final Reader reader) { + public ASTAstRoot parse(final Reader reader) { try { final List parseProblems = new ArrayList<>(); final String sourceCode = IOUtils.toString(reader); final AstRoot astRoot = parseEcmascript(sourceCode, parseProblems); final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(sourceCode, parseProblems); - EcmascriptNode tree = treeBuilder.build(astRoot); + ASTAstRoot tree = (ASTAstRoot) treeBuilder.build(astRoot); suppressMap = new HashMap<>(); if (astRoot.getComments() != null) { @@ -77,6 +77,7 @@ public class EcmascriptParser { } } } + tree.setNoPmdComments(suppressMap); return tree; } catch (IOException e) { throw new ParseException(e); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/EcmascriptRuleViolationFactory.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/EcmascriptRuleViolationFactory.java deleted file mode 100644 index 3deca0d4e3..0000000000 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/rule/EcmascriptRuleViolationFactory.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.ecmascript.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.ecmascript.ast.EcmascriptNode; -import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; - -public final class EcmascriptRuleViolationFactory extends AbstractRuleViolationFactory { - - public static final EcmascriptRuleViolationFactory INSTANCE = new EcmascriptRuleViolationFactory(); - - private EcmascriptRuleViolationFactory() { - } - - @SuppressWarnings("rawtypes") - @Override - protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) { - return new ParametricRuleViolation<>(rule, ruleContext, (EcmascriptNode) 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-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java index 292cb9d1f6..3dbfa975f0 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/ReportTest.java @@ -13,7 +13,6 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.ecmascript.EcmascriptLanguageModule; import net.sourceforge.pmd.lang.ecmascript.ast.ASTFunctionNode; import net.sourceforge.pmd.lang.ecmascript.rule.AbstractEcmascriptRule; -import net.sourceforge.pmd.lang.ecmascript.rule.EcmascriptRuleViolationFactory; import net.sourceforge.pmd.testframework.RuleTst; public class ReportTest extends RuleTst { @@ -24,7 +23,7 @@ public class ReportTest extends RuleTst { Rule rule = new AbstractEcmascriptRule() { @Override public Object visit(ASTFunctionNode node, Object data) { - EcmascriptRuleViolationFactory.INSTANCE.addViolation((RuleContext) data, this, node, "Test", null); + EcmascriptLanguageModule.defaultHandler().getRuleViolationFactory().addViolation((RuleContext) data, this, node, "Test", null); return super.visit(node, data); } }; diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java index 3c6c300e59..e4f3931c6e 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java @@ -141,21 +141,21 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { * not implemented) with ECMAscript */ @Test - public void testSuppresionComment() { + public void testSuppressionComment() { Ecmascript3Parser parser = new Ecmascript3Parser(new EcmascriptParserOptions()); Reader sourceCode = new StringReader("function(x) {\n" + "x = x; //NOPMD I know what I'm doing\n" + "}\n"); - parser.parse("foo", sourceCode); - assertEquals(" I know what I'm doing", parser.getSuppressMap().get(2)); - assertEquals(1, parser.getSuppressMap().size()); + ASTAstRoot root = parser.parse("foo", sourceCode); + assertEquals(" I know what I'm doing", root.getNoPmdComments().get(2)); + assertEquals(1, root.getNoPmdComments().size()); EcmascriptParserOptions parserOptions = new EcmascriptParserOptions(); parserOptions.setSuppressMarker("FOOOO"); parser = new Ecmascript3Parser(parserOptions); sourceCode = new StringReader( "function(x) {\n" + "y = y; //NOPMD xyz\n" + "x = x; //FOOOO I know what I'm doing\n" + "}\n"); - parser.parse("foo", sourceCode); - assertEquals(" I know what I'm doing", parser.getSuppressMap().get(3)); - assertEquals(1, parser.getSuppressMap().size()); + root = parser.parse("foo", sourceCode); + assertEquals(" I know what I'm doing", root.getNoPmdComments().get(3)); + assertEquals(1, root.getNoPmdComments().size()); } /** 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..4dde455568 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 @@ -7,10 +7,6 @@ package net.sourceforge.pmd.lang.jsp; 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.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.jsp.rule.JspRuleViolationFactory; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; /** * Implementation of LanguageVersionHandler for the JSP parser. @@ -19,16 +15,6 @@ import net.sourceforge.pmd.lang.rule.RuleViolationFactory; */ public class JspHandler extends AbstractPmdLanguageVersionHandler { - @Override - public XPathHandler getXPathHandler() { - return new DefaultASTXPathHandler(); - } - - @Override - public RuleViolationFactory getRuleViolationFactory() { - return JspRuleViolationFactory.INSTANCE; - } - @Override public Parser getParser(ParserOptions parserOptions) { return new JspParser(parserOptions); diff --git a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspParser.java b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspParser.java index 1a83e37450..2906daa765 100644 --- a/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspParser.java +++ b/pmd-jsp/src/main/java/net/sourceforge/pmd/lang/jsp/JspParser.java @@ -5,8 +5,6 @@ package net.sourceforge.pmd.lang.jsp; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; @@ -36,8 +34,4 @@ public class JspParser extends AbstractParser { return new net.sourceforge.pmd.lang.jsp.ast.JspParser(new SimpleCharStream(source)).CompilationUnit(); } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME - } } 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..c14c09803a 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 @@ -9,16 +9,12 @@ import net.sourceforge.pmd.lang.DataFlowHandler; import net.sourceforge.pmd.lang.Parser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.VisitorStarter; -import net.sourceforge.pmd.lang.XPathHandler; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.ast.xpath.DefaultASTXPathHandler; 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 +34,6 @@ public class PLSQLHandler extends AbstractPmdLanguageVersionHandler { return new PLSQLParser(parserOptions); } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return PLSQLRuleViolationFactory.INSTANCE; - } - @Override public DFAGraphRule getDFAGraphRule() { return new DFAPLSQLGraphRule(); @@ -73,11 +64,4 @@ public class PLSQLHandler extends AbstractPmdLanguageVersionHandler { }; } - /** - * Return minimal XPathHandler to cope with Jaxen XPath Rules. - */ - @Override - public XPathHandler getXPathHandler() { - return new DefaultASTXPathHandler(); - } } diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java index 62d0efc4f8..e865e27ba4 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java @@ -7,8 +7,6 @@ package net.sourceforge.pmd.lang.plsql; import java.io.IOException; import java.io.Reader; import java.io.StringReader; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.io.IOUtils; @@ -53,8 +51,4 @@ public class PLSQLParser extends AbstractParser { } } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME - } } 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-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageHandler.java b/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageHandler.java index 06cb3616b0..1a37bb0781 100644 --- a/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageHandler.java +++ b/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaLanguageHandler.java @@ -6,8 +6,6 @@ package net.sourceforge.pmd.lang.scala; import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.ParserOptions; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.scala.rule.ScalaRuleViolationFactory; import scala.meta.Dialect; @@ -20,7 +18,7 @@ public class ScalaLanguageHandler extends AbstractPmdLanguageVersionHandler { /** * Create the Language Handler using the given Scala Dialect. - * + * * @param scalaDialect * the language version to use while parsing etc */ @@ -30,17 +28,13 @@ public class ScalaLanguageHandler extends AbstractPmdLanguageVersionHandler { /** * Get the Scala Dialect used in this language version choice. - * + * * @return the Scala Dialect for this handler */ public Dialect getDialect() { return this.dialect; } - @Override - public RuleViolationFactory getRuleViolationFactory() { - return ScalaRuleViolationFactory.INSTANCE; - } @Override public ScalaParser getParser(ParserOptions parserOptions) { diff --git a/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java b/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java index 933f665718..afc3aa2176 100644 --- a/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java +++ b/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java @@ -6,8 +6,6 @@ package net.sourceforge.pmd.lang.scala; import java.io.IOException; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import org.apache.commons.io.IOUtils; @@ -56,11 +54,6 @@ public class ScalaParser extends AbstractParser { return (ASTSource) new ScalaTreeBuilder().build(src); } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME; - } - @Override protected TokenManager createTokenManager(Reader source) { return null; diff --git a/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/rule/ScalaRuleViolationFactory.java b/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/rule/ScalaRuleViolationFactory.java deleted file mode 100644 index 73ec26099e..0000000000 --- a/pmd-scala/src/main/java/net/sourceforge/pmd/lang/scala/rule/ScalaRuleViolationFactory.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.scala.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; - -/** - * A RuleViolationFactory for Scala. - */ -public class ScalaRuleViolationFactory extends AbstractRuleViolationFactory { - /** - * The shared singleton of this RuleViolationFactory. - */ - public static final RuleViolationFactory INSTANCE = new ScalaRuleViolationFactory(); - - @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 rv = new ParametricRuleViolation<>(rule, ruleContext, node, message); - rv.setLines(beginLine, endLine); - return rv; - } - -} 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..585e3c68ae 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 @@ -7,23 +7,9 @@ package net.sourceforge.pmd.lang.swift; 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 { - @Override - public XPathHandler getXPathHandler() { - 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-test/src/main/java/net/sourceforge/pmd/test/lang/DummyLanguageModule.java b/pmd-test/src/main/java/net/sourceforge/pmd/test/lang/DummyLanguageModule.java index e4f2642990..426c3ace96 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/test/lang/DummyLanguageModule.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/test/lang/DummyLanguageModule.java @@ -7,9 +7,7 @@ package net.sourceforge.pmd.test.lang; import java.io.Reader; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; -import java.util.Map; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleContext; @@ -24,8 +22,8 @@ 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.ParametricRuleViolation; +import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; import net.sourceforge.pmd.test.lang.ast.DummyNode; /** @@ -86,11 +84,6 @@ public class DummyLanguageModule extends BaseLanguageModule { return node; } - @Override - public Map getSuppressMap() { - return Collections.emptyMap(); - } - @Override protected TokenManager createTokenManager(Reader source) { return null; @@ -107,7 +100,8 @@ 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); 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..d46c19f074 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 @@ -7,23 +7,9 @@ package net.sourceforge.pmd.lang.vf; 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.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vf.rule.VfRuleViolationFactory; public class VfHandler extends AbstractPmdLanguageVersionHandler { - @Override - public XPathHandler getXPathHandler() { - 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/VfParser.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfParser.java index e5dcca71b7..9a3dd235ab 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfParser.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/VfParser.java @@ -5,8 +5,6 @@ package net.sourceforge.pmd.lang.vf; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; @@ -35,8 +33,4 @@ public class VfParser extends AbstractParser { return new net.sourceforge.pmd.lang.vf.ast.VfParser(new VfSimpleCharStream(source)).CompilationUnit(); } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME - } } 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..4ec4aff3fa 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 @@ -7,10 +7,6 @@ package net.sourceforge.pmd.lang.vm; 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.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.vm.rule.VmRuleViolationFactory; /** * Implementation of LanguageVersionHandler for the VM parser. @@ -18,15 +14,6 @@ import net.sourceforge.pmd.lang.vm.rule.VmRuleViolationFactory; */ public class VmHandler extends AbstractPmdLanguageVersionHandler { - @Override - public XPathHandler getXPathHandler() { - 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/VmParser.java b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmParser.java index 40c6893be2..812d924b86 100644 --- a/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmParser.java +++ b/pmd-vm/src/main/java/net/sourceforge/pmd/lang/vm/VmParser.java @@ -5,8 +5,6 @@ package net.sourceforge.pmd.lang.vm; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; @@ -36,8 +34,4 @@ public class VmParser extends AbstractParser { return new net.sourceforge.pmd.lang.vm.ast.VmParser(new VelocityCharStream(source, 1, 1)).process(); } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME - } } 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..97d79e8b5d 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 @@ -7,26 +7,12 @@ package net.sourceforge.pmd.lang.xml; 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.xpath.DefaultASTXPathHandler; -import net.sourceforge.pmd.lang.rule.RuleViolationFactory; -import net.sourceforge.pmd.lang.xml.rule.XmlRuleViolationFactory; /** * Implementation of LanguageVersionHandler for the XML. */ public class XmlHandler extends AbstractPmdLanguageVersionHandler { - @Override - public XPathHandler getXPathHandler() { - 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/XmlParser.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java index 6962b69d02..94ddd56f30 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/XmlParser.java @@ -5,8 +5,6 @@ package net.sourceforge.pmd.lang.xml; import java.io.Reader; -import java.util.HashMap; -import java.util.Map; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; @@ -34,8 +32,4 @@ public class XmlParser extends AbstractParser { return new XmlParserImpl((XmlParserOptions) parserOptions).parse(source); } - @Override - public Map getSuppressMap() { - return new HashMap<>(); // FIXME - } } 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 - } -}