public class FinalParametersCheck extends AbstractCheck
Checks that parameters for methods, constructors, catch and for-each blocks are final. Interface, abstract, and native methods are not checked: the final keyword does not make sense for interface, abstract, and native method parameters as there is no code that could modify the parameter.
Rationale: Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final.
ignorePrimitiveTypes - Ignore primitive types as parameters.
Type is boolean.
Default value is false.
tokens - tokens to check
Type is int[].
Default value is:
METHOD_DEF,
CTOR_DEF.
To configure the check to enforce final parameters for methods and constructors:
<module name="FinalParameters"/>
To configure the check to enforce final parameters only for constructors:
<module name="FinalParameters"> <property name="tokens" value="CTOR_DEF"/> </module>
To configure the check to allow ignoring primitive datatypes as parameters:
<module name="FinalParameters"> <property name="ignorePrimitiveTypes" value="true"/> </module>
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
final.parameter
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
FinalParametersCheck() |
| Modifier and Type | Method and Description |
|---|---|
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 |
setIgnorePrimitiveTypes(boolean ignorePrimitiveTypes)
Setter to ignore primitive types as parameters.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_KEY
public FinalParametersCheck()
public void setIgnorePrimitiveTypes(boolean ignorePrimitiveTypes)
ignorePrimitiveTypes - true or false.public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processCopyright © 2001–2020. All rights reserved.