public class RequireThisCheck extends Check
Checks that code doesn't rely on the "this" default. That is references to instance variables and methods of the present object are explicitly of the form "this.varName" or "this.methodName(args)".
Examples of use:
<module name="RequireThis"/>An example of how to configure to check
this
qualifier for
methods only:
<module name="RequireThis"> <property name="checkFields" value="false"/> <property name="checkMethods" value="true"/> </module>
Limitations: I'm not currently doing anything about static variables or catch-blocks. Static methods invoked on a class name seem to be OK; both the class name and the method name have a DOT parent. Non-static methods invoked on either this or a variable name seem to be OK, likewise.
Much of the code for this check was cribbed from Rick Giles's
HiddenFieldCheck
.
Modifier and Type | Field and Description |
---|---|
static String |
MSG_METHOD
A key is pointing to the warning message text in "messages.properties"
file.
|
static String |
MSG_VARIABLE
A key is pointing to the warning message text in "messages.properties"
file.
|
Constructor and Description |
---|
RequireThisCheck() |
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.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
void |
setCheckFields(boolean checkFields)
Setter for checkFields property.
|
void |
setCheckMethods(boolean checkMethods)
Setter for checkMethods property.
|
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 String MSG_METHOD
public static final String MSG_VARIABLE
public RequireThisCheck()
public void setCheckFields(boolean checkFields)
checkFields
- should we check fields usage or not.public void setCheckMethods(boolean checkMethods)
checkMethods
- should we check methods usage or not.public int[] getDefaultTokens()
Check
getDefaultTokens
in class Check
TokenTypes
public int[] getRequiredTokens()
Check
getRequiredTokens
in class Check
TokenTypes
public int[] getAcceptableTokens()
Check
getAcceptableTokens
in class Check
TokenTypes
public void beginTree(DetailAST rootAST)
Check
public void visitToken(DetailAST ast)
Check
visitToken
in class Check
ast
- the token to processCopyright © 2001–2016. All rights reserved.