public class RequireThisCheck extends DeclarationCollector
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.
| Constructor and Description |
|---|
RequireThisCheck()
Creates new instance of the check.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
getCheckFields() |
boolean |
getCheckMethods() |
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 aCheckFields)
Setter for checkFields property.
|
void |
setCheckMethods(boolean aCheckMethods)
Setter for checkMethods property.
|
void |
visitToken(DetailAST aAST)
Called to process a token.
|
beginTree, isClassFielddestroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokensgetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverityconfigure, contextualize, finishLocalSetup, getConfiguration, setupChildpublic void setCheckFields(boolean aCheckFields)
aCheckFields - should we check fields usage or not.public boolean getCheckFields()
public void setCheckMethods(boolean aCheckMethods)
aCheckMethods - should we check methods usage or not.public boolean getCheckMethods()
public int[] getDefaultTokens()
CheckgetDefaultTokens in class CheckTokenTypespublic int[] getRequiredTokens()
CheckgetRequiredTokens in class CheckTokenTypespublic void visitToken(DetailAST aAST)
CheckvisitToken in class DeclarationCollectoraAST - the token to processCopyright © 2001-2014. All Rights Reserved.