public class SuppressWarningsHolder extends AbstractCheck
SuppressWarnings
annotations.Modifier and Type | Class and Description |
---|---|
private static class |
SuppressWarningsHolder.Entry
Records a particular suppression for a region of a file.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ALL_WARNING_MATCHING_ID
Special warning id for matching all the warnings.
|
private static java.util.Map<java.lang.String,java.lang.String> |
CHECK_ALIAS_MAP
A map from check source names to suppression aliases.
|
private static java.lang.String |
CHECK_SUFFIX
Suffix to be removed from subclasses of Check.
|
static java.lang.String |
CHECKSTYLE_PREFIX
Optional prefix for warning suppressions that are only intended to be
recognized by checkstyle.
|
private static java.lang.ThreadLocal<java.util.List<SuppressWarningsHolder.Entry>> |
ENTRIES
A thread-local holder for the list of suppression entries for the last
file parsed.
|
private static java.lang.String |
JAVA_LANG_PREFIX
Java.lang namespace prefix, which is stripped from SuppressWarnings
|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
SuppressWarningsHolder() |
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
private static java.util.List<java.lang.String> |
findAllExpressionsInChildren(DetailAST parent)
Method looks at children and returns list of expressions in strings.
|
private static DetailAST |
getAcceptableParent(DetailAST child)
Returns parent of given ast if parent has one of the following types:
ANNOTATION_DEF, PACKAGE_DEF, CLASS_DEF, ENUM_DEF, ENUM_CONSTANT_DEF, CTOR_DEF,
METHOD_DEF, PARAMETER_DEF, VARIABLE_DEF, ANNOTATION_FIELD_DEF, TYPE, LITERAL_NEW,
LITERAL_THROWS, TYPE_ARGUMENT, IMPLEMENTS_CLAUSE, DOT.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
static java.lang.String |
getAlias(java.lang.String sourceName)
Returns the alias for the source name of a check.
|
private static java.util.List<java.lang.String> |
getAllAnnotationValues(DetailAST ast)
Get all annotation values.
|
private static DetailAST |
getAnnotationTarget(DetailAST ast)
Get target of annotation.
|
private static java.util.List<java.lang.String> |
getAnnotationValues(DetailAST ast)
Returns the annotation values represented by an AST.
|
static java.lang.String |
getDefaultAlias(java.lang.String sourceName)
Returns the default alias for the source name of a check, which is the
source name in lower case with any dotted prefix or "Check" suffix
removed.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
private static java.lang.String |
getIdentifier(DetailAST ast)
Returns the Java identifier represented by an AST.
|
private static DetailAST |
getNthChild(DetailAST ast,
int index)
Returns the n'th child of an AST node.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
private static java.lang.String |
getStringExpr(DetailAST ast)
Returns the literal string expression represented by an AST.
|
private static boolean |
isAnnotationEmpty(java.util.List<java.lang.String> values)
Checks that annotation is empty.
|
static boolean |
isSuppressed(AuditEvent event)
Checks for a suppression of a check with the given source name and
location in the last file processed.
|
private static boolean |
isSuppressedAfterEventStart(int line,
int column,
SuppressWarningsHolder.Entry entry)
Checks whether suppression entry position is after the audit event occurrence position
in the source file.
|
private static boolean |
isSuppressedBeforeEventEnd(int line,
int column,
SuppressWarningsHolder.Entry entry)
Checks whether suppression entry position is before the audit event occurrence position
in the source file.
|
static void |
registerAlias(java.lang.String sourceName,
java.lang.String checkAlias)
Registers an alias for the source name of a check.
|
private static java.lang.String |
removeCheckstylePrefixIfExists(java.lang.String checkName)
Method removes checkstyle prefix (checkstyle:) from check name if exists.
|
void |
setAliasList(java.lang.String... aliasList)
Registers a list of source name aliases based on a comma-separated list
of
source=alias items, such as com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=
paramnum . |
void |
visitToken(DetailAST ast)
Called to process a token.
|
destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, 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 java.lang.String MSG_KEY
public static final java.lang.String CHECKSTYLE_PREFIX
FallThroughCheck
only in checkstyle (and not in javac), use the
suppression "checkstyle:fallthrough"
or "checkstyle:FallThrough"
.
To suppress the warning in both tools, just use "fallthrough"
.private static final java.lang.String JAVA_LANG_PREFIX
private static final java.lang.String CHECK_SUFFIX
private static final java.lang.String ALL_WARNING_MATCHING_ID
private static final java.util.Map<java.lang.String,java.lang.String> CHECK_ALIAS_MAP
private static final java.lang.ThreadLocal<java.util.List<SuppressWarningsHolder.Entry>> ENTRIES
public static java.lang.String getDefaultAlias(java.lang.String sourceName)
sourceName
- the source name of the check (generally the class
name)public static java.lang.String getAlias(java.lang.String sourceName)
registerAlias(String, String)
, that
alias is returned; otherwise, the default alias is used.sourceName
- the source name of the check (generally the class
name)public static void registerAlias(java.lang.String sourceName, java.lang.String checkAlias)
sourceName
- the source name of the check (generally the class
name)checkAlias
- the alias used in SuppressWarnings
annotationspublic void setAliasList(java.lang.String... aliasList)
source=alias
items, such as com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=
paramnum
.aliasList
- the list of comma-separated alias assignmentspublic static boolean isSuppressed(AuditEvent event)
event
- audit event.private static boolean isSuppressedAfterEventStart(int line, int column, SuppressWarningsHolder.Entry entry)
line
- the line number in the source file where the event occurred.column
- the column number in the source file where the event occurred.entry
- suppression entry.private static boolean isSuppressedBeforeEventEnd(int line, int column, SuppressWarningsHolder.Entry entry)
line
- the line number in the source file where the event occurred.column
- the column number in the source file where the event occurred.entry
- suppression entry.public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treepublic void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processprivate static java.lang.String removeCheckstylePrefixIfExists(java.lang.String checkName)
checkName
- - name of the checkprivate static java.util.List<java.lang.String> getAllAnnotationValues(DetailAST ast)
ast
- annotation tokenprivate static boolean isAnnotationEmpty(java.util.List<java.lang.String> values)
values
- list of values in the annotationprivate static DetailAST getAnnotationTarget(DetailAST ast)
ast
- the AST node to get the child ofprivate static DetailAST getAcceptableParent(DetailAST child)
child
- an astprivate static DetailAST getNthChild(DetailAST ast, int index)
ast
- the AST node to get the child ofindex
- the index of the child to getnull
if noneprivate static java.lang.String getIdentifier(DetailAST ast)
ast
- an AST node for an IDENT or DOTjava.lang.IllegalArgumentException
- if the AST is invalidprivate static java.lang.String getStringExpr(DetailAST ast)
ast
- an AST node for an EXPRjava.lang.IllegalArgumentException
- if the AST is invalidprivate static java.util.List<java.lang.String> getAnnotationValues(DetailAST ast)
ast
- an AST node for an EXPR or ANNOTATION_ARRAY_INITjava.lang.IllegalArgumentException
- if the AST is invalidprivate static java.util.List<java.lang.String> findAllExpressionsInChildren(DetailAST parent)
parent
- ast, that contains children