Class SuppressFilterElement

java.lang.Object
com.puppycrawl.tools.checkstyle.filters.SuppressFilterElement
All Implemented Interfaces:
Filter

public class SuppressFilterElement extends Object implements Filter
This filter element is immutable and processes AuditEvent objects based on the criteria of file, check, module id, line, and column. It rejects an AuditEvent if the following match:
  • the event's file name; and
  • the check name or the module identifier; and
  • (optionally) the event's line is in the filter's line CSV; and
  • (optionally) the check's columns is in the filter's column CSV.
  • Field Details

    • fileRegexp

      private final Pattern fileRegexp
      The regexp to match file names against.
    • checkRegexp

      private final Pattern checkRegexp
      The regexp to match check names against.
    • messageRegexp

      private final Pattern messageRegexp
      The regexp to match message names against.
    • moduleId

      private final String moduleId
      Module id filter.
    • lineFilter

      private final CsvFilterElement lineFilter
      Line number filter.
    • linesCsv

      private final String linesCsv
      CSV for line number filter.
    • columnFilter

      private final CsvFilterElement columnFilter
      Column number filter.
    • columnsCsv

      private final String columnsCsv
      CSV for column number filter.
  • Constructor Details

    • SuppressFilterElement

      public SuppressFilterElement(Pattern files, Pattern checks, Pattern message, String moduleId, String lines, String columns)
      Creates a SuppressFilterElement instance.
      Parameters:
      files - regular expression for filtered file names
      checks - regular expression for filtered check classes
      message - regular expression for messages.
      moduleId - the module id
      lines - CSV for lines
      columns - CSV for columns
    • SuppressFilterElement

      public SuppressFilterElement(String files, String checks, String message, String modId, String lines, String columns)
      Constructs a SuppressFilterElement using regular expressions as Strings. These are internally compiled into Pattern objects and passed to the main constructor.
      Parameters:
      files - regular expression for names of filtered files.
      checks - regular expression for filtered check classes.
      message - regular expression for messages.
      modId - the id
      lines - lines CSV values and ranges for line number filtering.
      columns - columns CSV values and ranges for column number filtering.
  • Method Details

    • toPattern

      private static Pattern toPattern(String regex)
      Converts a string into a compiled Pattern, or return null if input is null.
      Parameters:
      regex - the regular expression as a string, may be null.
      Returns:
      the compiled Pattern, or null if input is null.
    • 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.
    • isFileNameAndModuleNameMatching

      private boolean isFileNameAndModuleNameMatching(AuditEvent event)
      Is matching by file name, module id, and Check name.
      Parameters:
      event - event
      Returns:
      true if it is matching
    • isMessageNameMatching

      private boolean isMessageNameMatching(AuditEvent event)
      Is matching by message.
      Parameters:
      event - event
      Returns:
      true if it is matching or not set.
    • isLineAndColumnMatching

      private boolean isLineAndColumnMatching(AuditEvent event)
      Whether line and column match.
      Parameters:
      event - event to process.
      Returns:
      true if line and column are matching or not set.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • getPatternSafely

      @Nullable private static String getPatternSafely(Pattern pattern)
      Util method to get pattern String value from Pattern object safely, return null if pattern object is null.
      Parameters:
      pattern - pattern object
      Returns:
      value of pattern or null