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
Filter
SuppressWithNearbyTextFilteruses plain text to suppress nearby audit events. The filter can suppress all checks which have Checker as a parent module.Setting
.*value tonearbyTextPatternproperty 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 atnearbyTextPatternin format of$xand 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 atnearbyTextPatternin format of$xand 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 classSuppressWithNearbyTextFilter.SuppressionThe 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 java.lang.StringcachedFileAbsolutePathThe absolute path to the currently processed file.private java.lang.StringcheckPatternSpecify check name pattern to suppress.private static java.lang.StringDEFAULT_CHECK_PATTERNDefault regex for checks that should be suppressed.private static java.lang.StringDEFAULT_LINE_RANGEDefault number of lines that should be suppressed.private static java.lang.StringDEFAULT_NEARBY_TEXT_PATTERNDefault nearby text pattern to turn check reporting off.private java.lang.StringidPatternSpecify check ID pattern to suppress.private java.lang.StringlineRangeSpecify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.private java.lang.StringmessagePatternSpecify check violation message pattern to suppress.private java.util.regex.PatternnearbyTextPatternSpecify nearby text pattern to trigger filter to begin suppression.private java.util.List<SuppressWithNearbyTextFilter.Suppression>suppressionsSuppressions 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 booleanaccept(AuditEvent event)Determines whether or not a filtered AuditEvent is accepted.private voidcollectSuppressions(FileText fileText)Collets allSuppressWithNearbyTextFilter.Suppressioninstances retrieved from the givenFileText.protected voidfinishLocalSetup()Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.private static FileTextgetFileText(java.lang.String fileName)ReturnsFileTextinstance created based on the given file name.private static java.util.Optional<SuppressWithNearbyTextFilter.Suppression>getNearestSuppression(java.util.Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event)Finds the nearestSuppressWithNearbyTextFilter.Suppressioninstance which can suppress the givenAuditEvent.private SuppressWithNearbyTextFilter.SuppressiongetSuppression(FileText fileText, int lineNo)Tries to extract the suppression from the given line.voidsetCheckPattern(java.lang.String pattern)Setter to specify check name pattern to suppress.voidsetIdPattern(java.lang.String pattern)Setter to specify check ID pattern to suppress.voidsetLineRange(java.lang.String format)Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.voidsetMessagePattern(java.lang.String pattern)Setter to specify check violation message pattern to suppress.voidsetNearbyTextPattern(java.util.regex.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 java.lang.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 java.lang.String DEFAULT_CHECK_PATTERN
Default regex for checks that should be suppressed.- See Also:
- Constant Field Values
-
DEFAULT_LINE_RANGE
private static final java.lang.String DEFAULT_LINE_RANGE
Default number of lines that should be suppressed.- See Also:
- Constant Field Values
-
suppressions
private final java.util.List<SuppressWithNearbyTextFilter.Suppression> suppressions
Suppressions encountered in current file.
-
nearbyTextPattern
private java.util.regex.Pattern nearbyTextPattern
Specify nearby text pattern to trigger filter to begin suppression.
-
checkPattern
private java.lang.String checkPattern
Specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPatternin format of$xand be picked from line that matchesnearbyTextPattern.
-
messagePattern
private java.lang.String messagePattern
Specify check violation message pattern to suppress.
-
idPattern
private java.lang.String idPattern
Specify check ID pattern to suppress.
-
lineRange
private java.lang.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 atnearbyTextPatternin format of$xand be picked from line that matchesnearbyTextPattern.
-
cachedFileAbsolutePath
private java.lang.String cachedFileAbsolutePath
The absolute path to the currently processed file.
-
-
Constructor Detail
-
SuppressWithNearbyTextFilter
public SuppressWithNearbyTextFilter()
-
-
Method Detail
-
setNearbyTextPattern
public final void setNearbyTextPattern(java.util.regex.Pattern pattern)
Setter to specify nearby text pattern to trigger filter to begin suppression.- Parameters:
pattern- aPatternvalue.- Since:
- 10.10.0
-
setCheckPattern
public final void setCheckPattern(java.lang.String pattern)
Setter to specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPatternin format of$xand be picked from line that matchesnearbyTextPattern.- Parameters:
pattern- aStringvalue.- Since:
- 10.10.0
-
setMessagePattern
public void setMessagePattern(java.lang.String pattern)
Setter to specify check violation message pattern to suppress.- Parameters:
pattern- aStringvalue.- Since:
- 10.10.0
-
setIdPattern
public void setIdPattern(java.lang.String pattern)
Setter to specify check ID pattern to suppress.- Parameters:
pattern- aStringvalue.- Since:
- 10.10.0
-
setLineRange
public final void setLineRange(java.lang.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 atnearbyTextPatternin format of$xand be picked from line that matchesnearbyTextPattern.- Parameters:
format- aStringvalue.- Since:
- 10.10.0
-
accept
public boolean accept(AuditEvent event)
Description copied from interface:FilterDetermines whether or not a filtered AuditEvent is accepted.
-
finishLocalSetup
protected void finishLocalSetup()
Description copied from class:AbstractAutomaticBeanProvides 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:
finishLocalSetupin classAbstractAutomaticBean
-
getFileText
private static FileText getFileText(java.lang.String fileName)
ReturnsFileTextinstance created based on the given file name.- Parameters:
fileName- the name of the file.- Returns:
FileTextinstance.- Throws:
java.lang.IllegalStateException- if the file could not be read.
-
collectSuppressions
private void collectSuppressions(FileText fileText)
Collets allSuppressWithNearbyTextFilter.Suppressioninstances retrieved from the givenFileText.- Parameters:
fileText-FileTextinstance.
-
getSuppression
private SuppressWithNearbyTextFilter.Suppression getSuppression(FileText fileText, int lineNo)
Tries to extract the suppression from the given line.- Parameters:
fileText-FileTextinstance.lineNo- line number.- Returns:
SuppressWithNearbyTextFilter.Suppressioninstance.
-
getNearestSuppression
private static java.util.Optional<SuppressWithNearbyTextFilter.Suppression> getNearestSuppression(java.util.Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event)
Finds the nearestSuppressWithNearbyTextFilter.Suppressioninstance 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.Suppressioninstances.event-AuditEventinstance.- Returns:
SuppressWithNearbyTextFilter.Suppressioninstance.
-
-