public final class ParameterAssignmentCheck extends AbstractCheck
Disallow assignment of parameters.
Rationale: Parameter assignment is often considered poor programming practice. Forcing developers to declare parameters as final is often onerous. Having a check ensure that parameters are never assigned would give the best of both worlds.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
private java.util.Set<java.lang.String> |
parameterNames
Current set of parameters.
|
private java.util.Deque<java.util.Set<java.lang.String>> |
parameterNamesStack
Stack of methods' parameters.
|
Constructor and Description |
---|
ParameterAssignmentCheck() |
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
private void |
checkIdent(DetailAST ast)
Check if ident is parameter.
|
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.
|
private void |
leaveMethodDef()
Restores old set of parameters.
|
void |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
private void |
visitAssign(DetailAST ast)
Checks if this is assignments of parameter.
|
private void |
visitIncDec(DetailAST ast)
Checks if this is increment/decrement of parameter.
|
private void |
visitMethodDef(DetailAST ast)
Creates new set of parameters and store old one in stack.
|
private void |
visitMethodParameters(DetailAST ast)
Creates new parameter set for given method.
|
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, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public static final java.lang.String MSG_KEY
private final java.util.Deque<java.util.Set<java.lang.String>> parameterNamesStack
private java.util.Set<java.lang.String> parameterNames
public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public void beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treepublic void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void leaveToken(DetailAST ast)
AbstractCheck
leaveToken
in class AbstractCheck
ast
- the token leavingprivate void visitAssign(DetailAST ast)
ast
- assignment to check.private void visitIncDec(DetailAST ast)
ast
- dec/inc to check.private void checkIdent(DetailAST ast)
ast
- ident to check.private void visitMethodDef(DetailAST ast)
ast
- a method to process.private void leaveMethodDef()
private void visitMethodParameters(DetailAST ast)
ast
- a method for process.