public class MethodLengthCheck extends AbstractCheck
Checks for long methods.
Rationale: If a method becomes very long it is hard to understand. Therefore long methods should usually be refactored into several individual methods that focus on a specific task.
The default maximum method length is 150 lines. To change the maximum number of lines, set property max.
An example of how to configure the check is:
<module name="MethodLength"/>
An example of how to configure the check so that it accepts methods with at most 60 lines is:
<module name="MethodLength"> <property name="max" value="60"/> </module>
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 |
---|
MethodLengthCheck() |
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 |
setCountEmpty(boolean countEmpty)
Sets countEmpty.
|
void |
setMax(int length)
Sets maximum length of a method.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_KEY
public MethodLengthCheck()
public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void setMax(int length)
length
- the maximum length of a method.public void setCountEmpty(boolean countEmpty)
countEmpty
- whether to count empty and single line comments
of the form //.Copyright © 2001–2018. All rights reserved.