public class ParameterNameCheck extends AbstractNameCheck
Checks that method and catch
parameter names conform to a format specified
by the format property. The format is a
regular expression
and defaults to
^[a-z][a-zA-Z0-9]*$.
The check has the following options:
ignoreOverridden - allows to skip methods with Override annotation from validation. Default values is false .
accessModifiers - access modifiers of methods which should to be checked. Default value is public, protected, package, private .
An example of how to configure the check:<module name="ParameterName"/>
An example of how to configure the check for names that begin with a lower case letter, followed by letters, digits, and underscores:
<module name="ParameterName"> <property name="format" value="^[a-z][_a-zA-Z0-9]+$"/> </module>
An example of how to configure the check to skip methods with Override annotation from validation:
<module name="ParameterName"> <property name="ignoreOverridden" value="true"/> </module>
Modifier and Type | Field and Description |
---|---|
private AccessModifier[] |
accessModifiers
Access modifiers of methods which should be checked.
|
private boolean |
ignoreOverridden
Allows to skip methods with Override annotation from validation.
|
MSG_INVALID_PATTERN
Constructor and Description |
---|
ParameterNameCheck()
Creates a new
ParameterNameCheck instance. |
Modifier and Type | Method and Description |
---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
private static AccessModifier |
getAccessModifier(DetailAST ast)
Returns the access modifier of the method/constructor at the specified AST.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
private static boolean |
isOverriddenMethod(DetailAST ast)
Checks whether a method is annotated with Override annotation.
|
private boolean |
matchAccessModifiers(AccessModifier accessModifier)
Checks whether a method has the correct access modifier to be checked.
|
protected boolean |
mustCheckName(DetailAST ast)
Decides whether the name of an AST should be checked against
the format regexp.
|
void |
setAccessModifiers(AccessModifier... accessModifiers)
Sets access modifiers of methods which should be checked.
|
void |
setIgnoreOverridden(boolean ignoreOverridden)
Sets whether to skip methods with Override annotation from validation.
|
setFormat, visitToken
beginTree, 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
private boolean ignoreOverridden
private AccessModifier[] accessModifiers
public ParameterNameCheck()
ParameterNameCheck
instance.public void setIgnoreOverridden(boolean ignoreOverridden)
ignoreOverridden
- Flag for skipping methods with Override annotation.public void setAccessModifiers(AccessModifier... accessModifiers)
accessModifiers
- access modifiers of methods which should be checked.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
protected boolean mustCheckName(DetailAST ast)
AbstractNameCheck
mustCheckName
in class AbstractNameCheck
ast
- the AST to check.private static AccessModifier getAccessModifier(DetailAST ast)
ast
- the token of the method/constructor.private boolean matchAccessModifiers(AccessModifier accessModifier)
accessModifier
- the access modifier of the method.private static boolean isOverriddenMethod(DetailAST ast)
ast
- method parameter definition token.