public class HiddenFieldCheck extends Check
Checks that a local variable or a parameter does not shadow a field that is defined in the same class.
An example of how to configure the check is:
<module name="HiddenField"/>
An example of how to configure the check so that it checks variables but not parameters is:
<module name="HiddenField">
<property name="tokens" value="VARIABLE_DEF"/>
</module>
An example of how to configure the check so that it ignores the parameter of a setter method is:
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
</module>
A method is recognized as a setter if it is in the following form
${returnType} set${Name}(${anyType} ${name}) { ... }
where ${anyType} is any primitive type, class or interface name;
${name} is name of the variable that is being set and ${Name} its
capitalized form that appears in the method name. By default it is expected
that setter returns void, i.e. ${returnType} is 'void'. For example
void setTime(long time) { ... }
Any other return types will not let method match a setter pattern. However,
by setting setterCanReturnItsClass property to true
definition of a setter is expanded, so that setter return type can also be
a class in which setter is declared. For example
class PageBuilder {
PageBuilder setName(String name) { ... }
}
Such methods are known as chain-setters and a common when Builder-pattern
is used. Property setterCanReturnItsClass has effect only if
ignoreSetter is set to true.
An example of how to configure the check so that it ignores the parameter of either a setter that returns void or a chain-setter.
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
<property name="setterCanReturnItsClass" value="true"/>
</module>
An example of how to configure the check so that it ignores constructor parameters is:
<module name="HiddenField">
<property name="ignoreConstructorParameter" value="true"/>
</module>
| Constructor and Description |
|---|
HiddenFieldCheck() |
| Modifier and Type | Method and Description |
|---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
Pattern |
getRegexp() |
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
void |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
void |
setIgnoreAbstractMethods(boolean ignoreAbstractMethods)
Set whether to ignore parameters of abstract methods.
|
void |
setIgnoreConstructorParameter(boolean ignoreConstructorParameter)
Set whether to ignore constructor parameters.
|
void |
setIgnoreFormat(String format)
Set the ignore format to the specified regular expression.
|
void |
setIgnoreSetter(boolean ignoreSetter)
Set whether to ignore the parameter of a property setter method.
|
void |
setSetterCanReturnItsClass(boolean aSetterCanReturnItsClass)
Controls if setter can return only void (default behavior) or it
can also return class in which it is declared.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokensgetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverityconfigure, contextualize, finishLocalSetup, getConfiguration, setupChildpublic HiddenFieldCheck()
public int[] getDefaultTokens()
CheckgetDefaultTokens in class CheckTokenTypespublic int[] getAcceptableTokens()
CheckgetAcceptableTokens in class CheckTokenTypespublic int[] getRequiredTokens()
CheckgetRequiredTokens in class CheckTokenTypespublic void beginTree(DetailAST rootAST)
Checkpublic void visitToken(DetailAST ast)
CheckvisitToken in class Checkast - the token to processpublic void leaveToken(DetailAST ast)
CheckleaveToken in class Checkast - the token leavingpublic void setIgnoreFormat(String format) throws org.apache.commons.beanutils.ConversionException
format - a String valueorg.apache.commons.beanutils.ConversionException - unable to parse formatpublic void setIgnoreSetter(boolean ignoreSetter)
ignoreSetter - decide whether to ignore the parameter of
a property setter method.public void setSetterCanReturnItsClass(boolean aSetterCanReturnItsClass)
aSetterCanReturnItsClass - if true then setter can return
either void or class in which it is declared. If false then
in order to be recognized as setter method (otherwise
already recognized as a setter) must return void. Later is
the default behavior.public void setIgnoreConstructorParameter(boolean ignoreConstructorParameter)
ignoreConstructorParameter - decide whether to ignore
constructor parameters.public void setIgnoreAbstractMethods(boolean ignoreAbstractMethods)
ignoreAbstractMethods - decide whether to ignore
parameters of abstract methods.Copyright © 2001–2015. All rights reserved.