public final class MethodCountCheck extends AbstractCheck
| Modifier and Type | Class and Description |
|---|---|
private static class |
MethodCountCheck.MethodCounter
Marker class used to collect data about the number of methods per
class.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.Deque<MethodCountCheck.MethodCounter> |
counters
Maintains stack of counters, to support inner types.
|
private static int |
DEFAULT_MAX_METHODS
Default maximum number of methods.
|
private int |
maxPackage
Maximum package methods.
|
private int |
maxPrivate
Maximum private methods.
|
private int |
maxProtected
Maximum protected methods.
|
private int |
maxPublic
Maximum public methods.
|
private int |
maxTotal
Maximum total number of methods.
|
static java.lang.String |
MSG_MANY_METHODS
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_PACKAGE_METHODS
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_PRIVATE_METHODS
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_PROTECTED_METHODS
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_PUBLIC_METHODS
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
MethodCountCheck() |
| Modifier and Type | Method and Description |
|---|---|
private void |
checkCounters(MethodCountCheck.MethodCounter counter,
DetailAST ast)
Check the counters and report violations.
|
private void |
checkMax(int max,
int value,
java.lang.String msg,
DetailAST ast)
Utility for reporting if a maximum has been exceeded.
|
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 |
leaveToken(DetailAST ast)
Called after all the child nodes have been process.
|
private void |
raiseCounter(DetailAST method)
Determine the visibility modifier and raise the corresponding counter.
|
void |
setMaxPackage(int value)
Sets the maximum allowed
package methods per type. |
void |
setMaxPrivate(int value)
Sets the maximum allowed
private methods per type. |
void |
setMaxProtected(int value)
Sets the maximum allowed
protected methods per type. |
void |
setMaxPublic(int value)
Sets the maximum allowed
public methods per type. |
void |
setMaxTotal(int value)
Sets the maximum total methods per type.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokensgetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverityconfigure, contextualize, finishLocalSetup, getConfiguration, setupChildpublic static final java.lang.String MSG_PRIVATE_METHODS
public static final java.lang.String MSG_PACKAGE_METHODS
public static final java.lang.String MSG_PROTECTED_METHODS
public static final java.lang.String MSG_PUBLIC_METHODS
public static final java.lang.String MSG_MANY_METHODS
private static final int DEFAULT_MAX_METHODS
private final java.util.Deque<MethodCountCheck.MethodCounter> counters
private int maxPrivate
private int maxPackage
private int maxProtected
private int maxPublic
private int maxTotal
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 processpublic void leaveToken(DetailAST ast)
AbstractCheckleaveToken in class AbstractCheckast - the token leavingprivate void raiseCounter(DetailAST method)
method - The method-subtree from the AbstractSyntaxTree.private void checkCounters(MethodCountCheck.MethodCounter counter, DetailAST ast)
counter - the method counters to checkast - to report errors against.private void checkMax(int max,
int value,
java.lang.String msg,
DetailAST ast)
max - the maximum allowed valuevalue - the actual valuemsg - the message to log. Takes two arguments of value and maximum.ast - the AST to associate with the message.public void setMaxPrivate(int value)
private methods per type.value - the maximum allowed.public void setMaxPackage(int value)
package methods per type.value - the maximum allowed.public void setMaxProtected(int value)
protected methods per type.value - the maximum allowed.public void setMaxPublic(int value)
public methods per type.value - the maximum allowed.public void setMaxTotal(int value)
value - the maximum allowed.