Class SuppressWarningsFilter
- All Implemented Interfaces:
Configurable,Contextualizable,Filter
Filter SuppressWarningsFilter uses annotation
SuppressWarnings to suppress audit events.
Rationale: Same as for SuppressionCommentFilter. In the contrary to it here,
comments are not used comments but the builtin syntax of @SuppressWarnings.
This can be perceived as a more elegant solution than using comments.
Also this approach maybe supported by various IDE.
Usage: This filter only works in conjunction with a
SuppressWarningsHolder,
since that check finds the annotations in the Java files and makes them available for the filter.
Because of that, a configuration that includes this filter must also include
SuppressWarningsHolder as a child module of the TreeWalker.
Name of check in annotation is case-insensitive and should be written with
any dotted prefix or "Check" suffix removed.
SuppressWarningsFilter can suppress Checks that have Treewalker or Checker as parent module.
To configure the check that makes tha annotations available to the filter.
<module name="TreeWalker">
...
<module name="SuppressWarningsHolder" />
...
</module>
To configure filter to suppress audit events for annotations add:
<module name="SuppressWarningsFilter" />
@SuppressWarnings({"memberName"})
private int J; // should NOT fail MemberNameCheck
@SuppressWarnings({"MemberName"})
@SuppressWarnings({"NoWhitespaceAfter"})
private int [] ARRAY; // should NOT fail MemberNameCheck and NoWhitespaceAfterCheck
It is possible to specify an ID of checks, so that it can be leveraged by
the SuppressWarningsFilter to skip validations. The following examples show how to
skip validations near code that has @SuppressWarnings("checkstyle:<ID>")
or just @SuppressWarnings("<ID>") annotation, where ID is the ID
of checks you want to suppress.
Example of Checkstyle check configuration:
<module name="RegexpSinglelineJava">
<property name="id" value="systemout"/>
<property name="format" value="^.*System\.(out|err).*$"/>
<property name="message"
value="Don't use System.out/err, use SLF4J instead."/>
</module>
To make the annotations available to the filter.
<module name="TreeWalker"> ... <module name="SuppressWarningsHolder" /> ... </module>
To configure filter to suppress audit events for annotations add:
<module name="SuppressWarningsFilter" />
@SuppressWarnings("checkstyle:systemout")
public static void foo() {
System.out.println("Debug info."); // should NOT fail RegexpSinglelineJava
}
Parent is com.puppycrawl.tools.checkstyle.Checker
- Since:
- 5.7
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(AuditEvent event) Determines whether or not a filtered AuditEvent is accepted.protected voidProvides a hook to finish the part of this component's setup that was not handled by the bean introspection.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Constructor Details
-
SuppressWarningsFilter
public SuppressWarningsFilter()
-
-
Method Details
-
finishLocalSetup
protected void finishLocalSetup()Description copied from class:AutomaticBeanProvides 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 classAutomaticBean
-
accept
Description copied from interface:FilterDetermines whether or not a filtered AuditEvent is accepted.
-