Class SuppressWithNearbyTextFilter
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
-
- com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyTextFilter
-
- All Implemented Interfaces:
Configurable
,Contextualizable
,Filter
public class SuppressWithNearbyTextFilter extends AbstractAutomaticBean implements Filter
FilterSuppressWithNearbyTextFilter
uses plain text to suppress nearby audit events. The filter can suppress all checks which have Checker as a parent module.Setting
.*
value tonearbyTextPattern
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.-
Property
checkPattern
- Specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. Type isjava.util.regex.Pattern
. Default value is".*"
. -
Property
idPattern
- Specify check ID pattern to suppress. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
lineRange
- 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 atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. Type isjava.lang.String
. Default value is"0"
. -
Property
messagePattern
- Specify check violation message pattern to suppress. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
nearbyTextPattern
- Specify nearby text pattern to trigger filter to begin suppression. Type isjava.util.regex.Pattern
. Default value is"SUPPRESS CHECKSTYLE (\w+)"
.
Parent is
com.puppycrawl.tools.checkstyle.Checker
- Since:
- 10.10.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SuppressWithNearbyTextFilter.Suppression
The class which represents the suppression.-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private String
cachedFileAbsolutePath
The absolute path to the currently processed file.private String
checkPattern
Specify check name pattern to suppress.private static String
DEFAULT_CHECK_PATTERN
Default regex for checks that should be suppressed.private static String
DEFAULT_LINE_RANGE
Default number of lines that should be suppressed.private static String
DEFAULT_NEARBY_TEXT_PATTERN
Default nearby text pattern to turn check reporting off.private String
idPattern
Specify check ID pattern to suppress.private String
lineRange
Specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.private String
messagePattern
Specify check violation message pattern to suppress.private Pattern
nearbyTextPattern
Specify nearby text pattern to trigger filter to begin suppression.private List<SuppressWithNearbyTextFilter.Suppression>
suppressions
Suppressions encountered in current file.
-
Constructor Summary
Constructors Constructor Description SuppressWithNearbyTextFilter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(AuditEvent event)
Determines whether or not a filtered AuditEvent is accepted.private void
collectSuppressions(FileText fileText)
Collets allSuppressWithNearbyTextFilter.Suppression
instances retrieved from the givenFileText
.protected void
finishLocalSetup()
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.private static FileText
getFileText(String fileName)
ReturnsFileText
instance created based on the given file name.private static Optional<SuppressWithNearbyTextFilter.Suppression>
getNearestSuppression(Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event)
Finds the nearestSuppressWithNearbyTextFilter.Suppression
instance which can suppress the givenAuditEvent
.private SuppressWithNearbyTextFilter.Suppression
getSuppression(FileText fileText, int lineNo)
Tries to extract the suppression from the given line.void
setCheckPattern(String pattern)
Setter to specify check name pattern to suppress.void
setIdPattern(String pattern)
Setter to specify check ID pattern to suppress.void
setLineRange(String format)
Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.void
setMessagePattern(String pattern)
Setter to specify check violation message pattern to suppress.void
setNearbyTextPattern(Pattern pattern)
Setter to specify nearby text pattern to trigger filter to begin suppression.-
Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
DEFAULT_NEARBY_TEXT_PATTERN
private static final String DEFAULT_NEARBY_TEXT_PATTERN
Default nearby text pattern to turn check reporting off.- See Also:
- Constant Field Values
-
DEFAULT_CHECK_PATTERN
private static final String DEFAULT_CHECK_PATTERN
Default regex for checks that should be suppressed.- See Also:
- Constant Field Values
-
DEFAULT_LINE_RANGE
private static final String DEFAULT_LINE_RANGE
Default number of lines that should be suppressed.- See Also:
- Constant Field Values
-
suppressions
private final List<SuppressWithNearbyTextFilter.Suppression> suppressions
Suppressions encountered in current file.
-
nearbyTextPattern
private Pattern nearbyTextPattern
Specify nearby text pattern to trigger filter to begin suppression.
-
checkPattern
private String checkPattern
Specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.
-
messagePattern
private String messagePattern
Specify check violation message pattern to suppress.
-
lineRange
private String lineRange
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 atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.
-
cachedFileAbsolutePath
private String cachedFileAbsolutePath
The absolute path to the currently processed file.
-
-
Constructor Detail
-
SuppressWithNearbyTextFilter
public SuppressWithNearbyTextFilter()
-
-
Method Detail
-
setNearbyTextPattern
public final void setNearbyTextPattern(Pattern pattern)
Setter to specify nearby text pattern to trigger filter to begin suppression.- Parameters:
pattern
- aPattern
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 atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.- Parameters:
pattern
- aString
value.- Since:
- 10.10.0
-
setMessagePattern
public void setMessagePattern(String pattern)
Setter to specify check violation message pattern to suppress.- Parameters:
pattern
- aString
value.- Since:
- 10.10.0
-
setIdPattern
public void setIdPattern(String pattern)
Setter to specify check ID pattern to suppress.- Parameters:
pattern
- aString
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 atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.- Parameters:
format
- aString
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.
-
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 classAbstractAutomaticBean
-
getFileText
private static FileText getFileText(String fileName)
ReturnsFileText
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 allSuppressWithNearbyTextFilter.Suppression
instances retrieved from the givenFileText
.- Parameters:
fileText
-FileText
instance.
-
getSuppression
private SuppressWithNearbyTextFilter.Suppression getSuppression(FileText fileText, int lineNo)
Tries to extract the suppression from the given line.- Parameters:
fileText
-FileText
instance.lineNo
- line number.- Returns:
SuppressWithNearbyTextFilter.Suppression
instance.
-
getNearestSuppression
private static Optional<SuppressWithNearbyTextFilter.Suppression> getNearestSuppression(Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event)
Finds the nearestSuppressWithNearbyTextFilter.Suppression
instance which can suppress the givenAuditEvent
. The nearest suppression is the suppression which scope is before the line and column of the event.- Parameters:
suppressions
- collection ofSuppressWithNearbyTextFilter.Suppression
instances.event
-AuditEvent
instance.- Returns:
SuppressWithNearbyTextFilter.Suppression
instance.
-
-