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 aViolationSuppressorthat uses annotations of the source language to suppress some warnings.- Since:
- 7.14.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceAbstractAnnotationSuppressor.AnnotationWalkCallbacksCallbacks 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 Modifier Constructor Description protectedAbstractAnnotationSuppressor(Class<A> annotationClass)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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>getAnnotations(Node n)Return the annotations attached to the given node.StringgetId()A name, for reporting and documentation purposes.Set<ViolationSuppressor.UnusedSuppressorNode>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.Report.SuppressedViolationsuppressOrNull(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).
-
-
-
Method Detail
-
getId
public String getId()
Description copied from interface:ViolationSuppressorA name, for reporting and documentation purposes.- Specified by:
getIdin interfaceViolationSuppressor
-
suppressOrNull
public Report.SuppressedViolation suppressOrNull(RuleViolation rv, @NonNull Node node)
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
public Set<ViolationSuppressor.UnusedSuppressorNode> getUnusedSuppressors(RootNode tree)
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
protected abstract NodeStream<A> getAnnotations(Node n)
Return the annotations attached to the given node.
-
getAnnotationName
protected String getAnnotationName(A annotation)
Return a nice toString for the given annotation.
-
annotationParamSuppresses
protected boolean annotationParamSuppresses(String stringVal, Rule rule)
Return whether one of the annotation params suppresses the given rule. The default implementation uses sensible values, so call super.
-
isSuppressingNonPmdWarnings
protected OptionalBool isSuppressingNonPmdWarnings(String stringVal, A annotation)
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.
-
-