Class SuppressionXpathFilter

  • All Implemented Interfaces:
    Configurable, Contextualizable, ExternalResourceHolder, TreeWalkerFilter

    public class SuppressionXpathFilter
    extends AbstractAutomaticBean
    implements TreeWalkerFilter, ExternalResourceHolder

    Filter SuppressionXpathFilter works as SuppressionFilter. Additionally, filter processes suppress-xpath elements, which contains xpath-expressions. Xpath-expressions are queries for suppressed nodes inside the AST tree.

    Currently, filter does not support the following checks:

    • NoCodeInFile (reason is that AST is not generated for a file not containing code)
    • Regexp (reason is at #7759)
    • RegexpSinglelineJava (reason is at #7759)

    Also, the filter does not support suppressions inside javadoc reported by Javadoc checks:

    • AtclauseOrder
    • JavadocBlockTagLocation
    • JavadocMethod
    • JavadocMissingLeadingAsterisk
    • JavadocMissingWhitespaceAfterAsterisk
    • JavadocParagraph
    • JavadocStyle
    • JavadocTagContinuationIndentation
    • JavadocType
    • MissingDeprecated
    • NonEmptyAtclauseDescription
    • RequireEmptyLineBeforeBlockTagGroup
    • SingleLineJavadoc
    • SummaryJavadoc
    • WriteTag

    Note, that support for these Checks will be available after resolving issue #5770.

    Currently, filter supports the following xpath axes:

    • ancestor
    • ancestor-or-self
    • attribute
    • child
    • descendant
    • descendant-or-self
    • following
    • following-sibling
    • parent
    • preceding
    • preceding-sibling
    • self

    You can use the command line helper tool to generate xpath suppressions based on your configuration file and input files. See here for more details.

    The suppression file location is checked in following order:

    1. as a filesystem location
    2. if no file found, and the location starts with either http:// or https://, then it is interpreted as a URL
    3. if no file found, then passed to the ClassLoader.getResource() method.

    SuppressionXpathFilter can suppress Checks that have Treewalker as parent module.

    • Property file - Specify the location of the suppressions XML document file. Type is java.lang.String. Default value is null.
    • Property optional - Control what to do when the file is not existing. If optional is set to false the file must exist, or else it ends with error. On the other hand if optional is true and file is not found, the filter accepts all audit events. Type is boolean. Default value is false.

    Parent is com.puppycrawl.tools.checkstyle.TreeWalker

    Since:
    8.6
    • Field Detail

      • file

        private String file
        Specify the location of the suppressions XML document file.
      • optional

        private boolean optional
        Control what to do when the file is not existing. If optional is set to false the file must exist, or else it ends with error. On the other hand if optional is true and file is not found, the filter accepts all audit events.
    • Method Detail

      • setFile

        public void setFile​(String fileName)
        Setter to specify the location of the suppressions XML document file.
        Parameters:
        fileName - name of the suppressions file.
        Since:
        8.6
      • setOptional

        public void setOptional​(boolean optional)
        Setter to control what to do when the file is not existing. If optional is set to false the file must exist, or else it ends with error. On the other hand if optional is true and file is not found, the filter accepts all audit events.
        Parameters:
        optional - tells if config file existence is optional.
        Since:
        8.6
      • accept

        public boolean accept​(TreeWalkerAuditEvent treeWalkerAuditEvent)
        Description copied from interface: TreeWalkerFilter
        Determines whether or not a filtered TreeWalkerAuditEvent is accepted.
        Specified by:
        accept in interface TreeWalkerFilter
        Parameters:
        treeWalkerAuditEvent - the TreeWalkerAuditEvent to filter.
        Returns:
        true if the event is accepted.