Class SuppressWithNearbyTextFilter

java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyTextFilter
All Implemented Interfaces:
Configurable, Contextualizable, Filter

Filter SuppressWithNearbyTextFilter uses plain text to suppress nearby audit events. The filter can suppress all checks which have Checker as a parent module.

Notes: Setting .* value to nearbyTextPattern property will see any text as a suppression and will likely suppress all audit events in the file. It is best to set this to a key phrase not commonly used in the file to help denote it out of the rest of the file as a suppression. See the default value as an example.

Since:
10.10.0
  • Field Details

  • Constructor Details

  • Method Details

    • setNearbyTextPattern

      public final void setNearbyTextPattern(Pattern pattern)
      Setter to specify nearby text pattern to trigger filter to begin suppression.
      Parameters:
      pattern - a Pattern value.
      Since:
      10.10.0
    • setCheckPattern

      public final void setCheckPattern(String pattern)
      Setter to specify check name pattern to suppress. Property can also be a RegExp group index at nearbyTextPattern in format of $x and be picked from line that matches nearbyTextPattern. The pattern is matched against the fully qualified class name of the Check.
      Parameters:
      pattern - a String value.
      Since:
      10.10.0
    • setMessagePattern

      public void setMessagePattern(String pattern)
      Setter to specify check violation message pattern to suppress.
      Parameters:
      pattern - a String value.
      Since:
      10.10.0
    • setIdPattern

      public void setIdPattern(String pattern)
      Setter to specify check ID pattern to suppress.
      Parameters:
      pattern - a String value.
      Since:
      10.10.0
    • setLineRange

      public final void setLineRange(String format)
      Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text. Property can also be a RegExp group index at nearbyTextPattern in format of $x and be picked from line that matches nearbyTextPattern.
      Parameters:
      format - a String value.
      Since:
      10.10.0
    • 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.
    • finishLocalSetup

      protected void finishLocalSetup()
      Description copied from class: AbstractAutomaticBean
      Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.

      The default implementation does nothing.

      Specified by:
      finishLocalSetup in class AbstractAutomaticBean
    • getFileText

      private static FileText getFileText(String fileName)
      Returns FileText instance created based on the given file name.
      Parameters:
      fileName - the name of the file.
      Returns:
      FileText instance.
      Throws:
      IllegalStateException - if the file could not be read.
    • collectSuppressions

      private void collectSuppressions(FileText fileText)
      Collets all SuppressWithNearbyTextFilter.Suppression instances retrieved from the given FileText.
      Parameters:
      fileText - FileText instance.
    • getSuppression

      Tries to extract the suppression from the given line.
      Parameters:
      fileText - FileText instance.
      lineNo - line number.
      Returns:
      SuppressWithNearbyTextFilter.Suppression instance.
    • getNearestSuppression

      Finds the nearest SuppressWithNearbyTextFilter.Suppression instance which can suppress the given AuditEvent. The nearest suppression is the suppression which scope is before the line and column of the event.
      Parameters:
      suppressions - collection of Suppression instances.
      event - AuditEvent instance.
      Returns:
      Suppression instance.