Package net.sourceforge.pmd.reporting
Class AbstractAnnotationSuppressor<A extends Node>
java.lang.Object
net.sourceforge.pmd.reporting.AbstractAnnotationSuppressor<A>
- Type Parameters:
A- Class of the node type that models annotations in the AST of the language
- All Implemented Interfaces:
ViolationSuppressor
public abstract class AbstractAnnotationSuppressor<A extends Node>
extends Object
implements ViolationSuppressor
Base class for a
ViolationSuppressor that uses annotations
of the source language to suppress some warnings.- Since:
- 7.14.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceCallbacks for a walk over an annotation.Nested classes/interfaces inherited from interface net.sourceforge.pmd.reporting.ViolationSuppressor
ViolationSuppressor.SuppressionCommentWrapper, ViolationSuppressor.UnusedSuppressorNode -
Field Summary
Fields inherited from interface net.sourceforge.pmd.reporting.ViolationSuppressor
NOPMD_COMMENT_SUPPRESSOR, REGEX_SUPPRESSOR, XPATH_SUPPRESSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanannotationParamSuppresses(String stringVal, Rule rule) Return whether one of the annotation params suppresses the given rule.protected StringgetAnnotationName(A annotation) Return a nice toString for the given annotation.protected abstract NodeStream<A>Return the annotations attached to the given node.getId()A name, for reporting and documentation purposes.getUnusedSuppressors(RootNode tree) Return the set of suppressor nodes related to this suppressor that were not used during the analysis.protected OptionalBoolisSuppressingNonPmdWarnings(String stringVal, A annotation) Return whether the annotation param may be suppressing warnings from other tools.suppressOrNull(RuleViolation rv, @NonNull Node node) Returns aReport.SuppressedViolationif the given violation is suppressed by this object.protected abstract booleanwalkAnnotation(A annotation, AbstractAnnotationSuppressor.AnnotationWalkCallbacks callbacks) Walk the individual suppression specifications of an annotation (usually strings within the annotation).
-
Constructor Details
-
AbstractAnnotationSuppressor
-
-
Method Details
-
getId
Description copied from interface:ViolationSuppressorA name, for reporting and documentation purposes.- Specified by:
getIdin interfaceViolationSuppressor
-
suppressOrNull
Description copied from interface:ViolationSuppressorReturns aReport.SuppressedViolationif 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.- Specified by:
suppressOrNullin interfaceViolationSuppressor
-
getUnusedSuppressors
Description copied from interface:ViolationSuppressorReturn the set of suppressor nodes related to this suppressor that were not used during the analysis. For instance, for an annotation suppressor, the set contains suppressor nodes wrapping annotations. This must be implemented if this suppressor wants to play well with the unused PMD suppression rule.- Specified by:
getUnusedSuppressorsin interfaceViolationSuppressor- Parameters:
tree- Root node of a file- Returns:
- A set
-
walkAnnotation
protected abstract boolean walkAnnotation(A annotation, AbstractAnnotationSuppressor.AnnotationWalkCallbacks callbacks) Walk the individual suppression specifications of an annotation (usually strings within the annotation). For each of those, call the callback. If the callback returns true, interrupt the walk and return true. Otherwise, continue the walk.- Parameters:
annotation- An annotationcallbacks- Callback object- Returns:
- True if the callback returned true once
-
getAnnotations
Return the annotations attached to the given node. -
getAnnotationName
Return a nice toString for the given annotation. -
annotationParamSuppresses
Return whether one of the annotation params suppresses the given rule. The default implementation uses sensible values, so call super. -
isSuppressingNonPmdWarnings
Return whether the annotation param may be suppressing warnings from other tools. If this returns NO, then the parameter may be marked as unused and reported by the ruleUnnecessaryPmdSuppressionRule.
-