Class AbstractAnnotationSuppressor<A extends Node>

  • 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
    • Constructor Detail

      • AbstractAnnotationSuppressor

        protected AbstractAnnotationSuppressor​(Class<A> annotationClass)
    • Method Detail

      • getUnusedSuppressors

        public Set<ViolationSuppressor.UnusedSuppressorNode> getUnusedSuppressors​(RootNode tree)
        Description copied from interface: ViolationSuppressor
        Return 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:
        getUnusedSuppressors in interface ViolationSuppressor
        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 annotation
        callbacks - 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 rule UnnecessaryPmdSuppressionRule.