Class SuppressWithNearbyCommentFilter

  • All Implemented Interfaces:
    Configurable, Contextualizable, Filter

    public class SuppressWithNearbyCommentFilter
    extends AutomaticBean
    implements Filter

    A filter that uses nearby comments to suppress audit events.

    This check is philosophically similar to SuppressionCommentFilter. Unlike SuppressionCommentFilter, this filter does not require pairs of comments. This check may be used to suppress warnings in the current line:

        offendingLine(for, whatever, reason); // SUPPRESS ParameterNumberCheck
     
    or it may be configured to span multiple lines, either forward:
        // PERMIT MultipleVariableDeclarations NEXT 3 LINES
        double x1 = 1.0, y1 = 0.0, z1 = 0.0;
        double x2 = 0.0, y2 = 1.0, z2 = 0.0;
        double x3 = 0.0, y3 = 0.0, z3 = 1.0;
     
    or reverse:
       try {
         thirdPartyLibrary.method();
       } catch (RuntimeException ex) {
         // ALLOW ILLEGAL CATCH BECAUSE third party API wraps everything
         // in RuntimeExceptions.
         ...
       }
     

    See SuppressionCommentFilter for usage notes.

    Author:
    Mick Killianey
    • Method Detail

      • setCommentFormat

        public final void setCommentFormat​(Pattern pattern)
        Set the format for a comment that turns off reporting.
        Parameters:
        pattern - a pattern.
      • getFileContents

        public FileContents getFileContents()
        Returns FileContents for this filter.
        Returns:
        the FileContents for this filter.
      • setFileContents

        public void setFileContents​(FileContents fileContents)
        Set the FileContents for this filter.
        Parameters:
        fileContents - the FileContents for this filter.
      • setCheckFormat

        public final void setCheckFormat​(String format)
        Set the format for a check.
        Parameters:
        format - a String value
      • setMessageFormat

        public void setMessageFormat​(String format)
        Set the format for a message.
        Parameters:
        format - a String value
      • setInfluenceFormat

        public final void setInfluenceFormat​(String format)
        Set the format for the influence of this check.
        Parameters:
        format - a String value
      • setCheckCPP

        public void setCheckCPP​(boolean checkCpp)
        Set whether to look in C++ comments.
        Parameters:
        checkCpp - true if C++ comments are checked.
      • setCheckC

        public void setCheckC​(boolean checkC)
        Set whether to look in C comments.
        Parameters:
        checkC - true if C comments are checked.
      • accept

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