com.puppycrawl.tools.checkstyle.checks.coding

Class RequireThisCheck

Implemented Interfaces:
Configurable, Contextualizable

public class RequireThisCheck
extends Check

Checks that code doesn't rely on the "this." default, i.e. 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.

Authors:
Stephen Bloch
o_sukhodolsky

Constructor Summary

RequireThisCheck()
Creates new instance of the check.

Method Summary

void
beginTree(DetailAST aRootAST)
boolean
getCheckFields()
boolean
getCheckMethods()
int[]
getDefaultTokens()
int[]
getRequiredTokens()
void
leaveToken(DetailAST aAST)
void
setCheckFields(boolean aCheckFields)
Setter for checkFields property.
void
setCheckMethods(boolean aCheckMethods)
Setter for checkMethods property.
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

RequireThisCheck

public RequireThisCheck()
Creates new instance of the check.

Method Details

beginTree

public void beginTree(DetailAST aRootAST)
Overrides:
beginTree in interface Check


getCheckFields

public boolean getCheckFields()

Returns:
true if we should check fields usage false overwise.


getCheckMethods

public boolean getCheckMethods()

Returns:
true if we should check methods usage false overwise.


getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check


getRequiredTokens

public int[] getRequiredTokens()
Overrides:
getRequiredTokens in interface Check


leaveToken

public void leaveToken(DetailAST aAST)
Overrides:
leaveToken in interface Check


setCheckFields

public void setCheckFields(boolean aCheckFields)
Setter for checkFields property.

Parameters:
aCheckFields - should we check fields usage or not.


setCheckMethods

public void setCheckMethods(boolean aCheckMethods)
Setter for checkMethods property.

Parameters:
aCheckMethods - should we check methods usage or not.


visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check