public class SuppressWarningsCheck extends AbstractFormatCheck
This check allows you to specify what warnings that
SuppressWarnings
is not
allowed to suppress. You can also specify a list
of TokenTypes that the configured warning(s) cannot
be suppressed on.
The warnings
property is a
regex pattern. Any warning being suppressed matching
this pattern will be flagged.
By default, any warning specified will be disallowed on
all legal TokenTypes unless otherwise specified via
the
tokens
property.
Also, by default warnings that are empty strings or all
whitespace (regex: ^$|^\s+$) are flagged. By specifying,
the format property these defaults no longer apply.
Limitations: This check does not consider conditionals
inside the SuppressWarnings annotation.
For example:
@SuppressWarnings((false) ? (true) ? "unchecked" : "foo" : "unused")
According to the above example, the "unused" warning is being suppressed
not the "unchecked" or "foo" warnings. All of these warnings will be
considered and matched against regardless of what the conditional
evaluates to.
This check can be configured so that the "unchecked" and "unused" warnings cannot be suppressed on anything but variable and parameter declarations. See below of an example.
<module name="SuppressWarnings"> <property name="format" value="^unchecked$|^unused$"/> <property name="tokens" value=" CLASS_DEF,INTERFACE_DEF,ENUM_DEF, ANNOTATION_DEF,ANNOTATION_FIELD_DEF, ENUM_CONSTANT_DEF,METHOD_DEF,CTOR_DEF "/> </module>
Modifier and Type | Field and Description |
---|---|
static String |
MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
SuppressWarningsCheck()
Ctor that specifies the default for the format property
as specified in the class javadocs.
|
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
getFormat, getRegexp, setCompileFlags, setFormat
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public static final String MSG_KEY_SUPPRESSED_WARNING_NOT_ALLOWED
public SuppressWarningsCheck()
public final int[] getDefaultTokens()
getDefaultTokens
in class Check
TokenTypes
public final int[] getAcceptableTokens()
getAcceptableTokens
in class Check
TokenTypes
public void visitToken(DetailAST ast)
visitToken
in class Check
ast
- the token to processCopyright © 2001–2015. All rights reserved.