Class SuppressWithNearbyCommentFilter
- All Implemented Interfaces:
Configurable,Contextualizable,TreeWalkerFilter
SuppressWithNearbyCommentFilter uses nearby comments to suppress audit events.
Rationale: Same as SuppressionCommentFilter.
Whereas the SuppressionCommentFilter uses matched pairs of filters to turn
on/off comment matching, SuppressWithNearbyCommentFilter uses single comments.
This requires fewer lines to mark a region, and may be aesthetically preferable in some contexts.
Attention: This filter may only be specified within the TreeWalker module
(<module name="TreeWalker"/>) and only applies to checks which are also
defined within this module. To filter non-TreeWalker checks like RegexpSingleline,
a
SuppressWithPlainTextCommentFilter or similar filter must be used.
Notes: SuppressWithNearbyCommentFilter can suppress Checks that have Treewalker as parent module.
- Since:
- 5.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classA Tag holds a suppression comment and its location.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanControl whether to check C style comments (/* ... */).private booleanControl whether to check C++ style comments (//).private StringSpecify check pattern to suppress.private PatternSpecify comment pattern to trigger filter to begin suppression.private static final StringDefault regex for checks that should be suppressed.private static final StringFormat to turn checkstyle reporting off.private static final StringDefault regex for lines that should be suppressed.private WeakReference<FileContents>References the current FileContents for this filter.private StringSpecify check ID pattern to suppress.private StringSpecify negative/zero/positive value that defines the number of lines preceding/at/following the suppression comment.private StringDefine message pattern to suppress.private final List<SuppressWithNearbyCommentFilter.Tag>Tagged comments. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(TreeWalkerAuditEvent event) Determines whether or not a filteredTreeWalkerAuditEventis accepted.private voidAdds a comment suppressionTagto the list of all tags.protected voidProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.private FileContentsReturns FileContents for this filter.private booleanmatchesTag(TreeWalkerAuditEvent event) Whether current event matches any tag fromtags.voidsetCheckC(boolean checkC) Setter to control whether to check C style comments (/* ... */).voidsetCheckCPP(boolean checkCpp) Setter to control whether to check C++ style comments (//).final voidsetCheckFormat(String format) Setter to specify check pattern to suppress.final voidsetCommentFormat(Pattern pattern) Setter to specify comment pattern to trigger filter to begin suppression.private voidsetFileContents(FileContents fileContents) Set the FileContents for this filter.voidsetIdFormat(String format) Setter to specify check ID pattern to suppress.final voidsetInfluenceFormat(String format) Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppression comment.voidsetMessageFormat(String format) Setter to define message pattern to suppress.private voidtagCommentLine(String text, int line) Tags a string if it matches the format for turning checkstyle reporting on or the format for turning reporting off.private voidCollects all the suppression tags for all comments into a list and sorts the list.private voidtagSuppressions(Collection<TextBlock> comments) Appends the suppressions in a collection of comments to the full set of suppression tags.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
DEFAULT_COMMENT_FORMAT
Format to turn checkstyle reporting off.- See Also:
-
DEFAULT_CHECK_FORMAT
Default regex for checks that should be suppressed.- See Also:
-
DEFAULT_INFLUENCE_FORMAT
Default regex for lines that should be suppressed.- See Also:
-
tags
Tagged comments. -
checkC
Control whether to check C style comments (/* ... */). -
checkCPP
Control whether to check C++ style comments (//). -
commentFormat
Specify comment pattern to trigger filter to begin suppression. -
checkFormat
Specify check pattern to suppress. -
messageFormat
Define message pattern to suppress. -
idFormat
Specify check ID pattern to suppress. -
influenceFormat
Specify negative/zero/positive value that defines the number of lines preceding/at/following the suppression comment. -
fileContentsReference
References the current FileContents for this filter. Since this is a weak reference to the FileContents, the FileContents can be reclaimed as soon as the strong references in TreeWalker are reassigned to the next FileContents, at which time filtering for the current FileContents is finished.
-
-
Constructor Details
-
SuppressWithNearbyCommentFilter
public SuppressWithNearbyCommentFilter()
-
-
Method Details
-
setCommentFormat
Setter to specify comment pattern to trigger filter to begin suppression.- Parameters:
pattern- a pattern.- Since:
- 5.0
-
getFileContents
Returns FileContents for this filter.- Returns:
- the FileContents for this filter.
-
setFileContents
Set the FileContents for this filter.- Parameters:
fileContents- the FileContents for this filter.
-
setCheckFormat
Setter to specify check pattern to suppress.- Parameters:
format- aStringvalue- Since:
- 5.0
-
setMessageFormat
Setter to define message pattern to suppress.- Parameters:
format- aStringvalue- Since:
- 5.0
-
setIdFormat
Setter to specify check ID pattern to suppress.- Parameters:
format- aStringvalue- Since:
- 8.24
-
setInfluenceFormat
Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppression comment.- Parameters:
format- aStringvalue- Since:
- 5.0
-
setCheckCPP
Setter to control whether to check C++ style comments (//).- Parameters:
checkCpp-trueif C++ comments are checked.- Since:
- 5.0
-
setCheckC
Setter to control whether to check C style comments (/* ... */).- Parameters:
checkC-trueif C comments are checked.- Since:
- 5.0
-
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
-
accept
Description copied from interface:TreeWalkerFilterDetermines whether or not a filteredTreeWalkerAuditEventis accepted.- Specified by:
acceptin interfaceTreeWalkerFilter- Parameters:
event- the TreeWalkerAuditEvent to filter.- Returns:
- true if the event is accepted.
-
matchesTag
Whether current event matches any tag fromtags. -
tagSuppressions
Collects all the suppression tags for all comments into a list and sorts the list. -
tagSuppressions
Appends the suppressions in a collection of comments to the full set of suppression tags.- Parameters:
comments- the set of comments.
-
tagCommentLine
Tags a string if it matches the format for turning checkstyle reporting on or the format for turning reporting off.- Parameters:
text- the string to tag.line- the line number of text.
-
addTag
Adds a comment suppressionTagto the list of all tags.- Parameters:
text- the text of the tag.line- the line number of the tag.
-