|
|||||||||
Home >> All >> com >> puppycrawl >> tools >> checkstyle >> [ checks overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |
com.puppycrawl.tools.checkstyle.checks
Class DescendantTokenCheck

java.lang.Objectcom.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.Check
com.puppycrawl.tools.checkstyle.checks.DescendantTokenCheck
- All Implemented Interfaces:
- com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable
- public class DescendantTokenCheck
- extends com.puppycrawl.tools.checkstyle.api.Check
Checks for restricted tokens beneath other tokens.
Examples of how to configure the check:
<!-- String literal equality check --> <module name="DescendantToken"> <property name="tokens" value="EQUAL,NOT_EQUAL"/> <property name="limitedTokens" value="STRING_LITERAL"/> <property name="maximumNumber" value="0"/> <property name="maximumDepth" value="1"/&dt; </module> <!-- Switch with no default --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="maximumDepth" value="2"/> <property name="limitedTokens" value="LITERAL_DEFAULT"/> <property name="minimumNumber" value="1"/> </module> <!-- Assert statement may have side effects --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_ASSERT"/> <property name="limitedTokens" value="ASSIGN,DEC,INC,POST_DEC, POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN, BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN, METHOD_CALL"/> <property name="maximumNumber" value="0"/> </module> <!-- Initialiser in for performs no setup - use while instead? --> <module name="DescendantToken"> <property name="tokens" value="FOR_INIT"/> <property name="limitedTokens" value="EXPR"/> <property name="minimumNumber" value="1"/> </module> <!-- Condition in for performs no check --> <module name="DescendantToken"> <property name="tokens" value="FOR_CONDITION"/> <property name="limitedTokens" value="EXPR"/> <property name="minimumNumber" value="1"/> </module> <!-- Switch within switch --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="limitedTokens" value="LITERAL_SWITCH"/> <property name="maximumNumber" value="0"/> <property name="minimumDepth" value="1"/> </module> <!-- Return from within a catch or finally block --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_FINALLY,LITERAL_CATCH"/> <property name="limitedTokens" value="LITERAL_RETURN"/> <property name="maximumNumber" value="0"/> </module> <!-- Try within catch or finally block --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_CATCH,LITERAL_FINALLY"/> <property name="limitedTokens" value="LITERAL_TRY"/> <property name="maximumNumber" value="0"/> </module> <!-- Too many cases within a switch --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="limitedTokens" value="LITERAL_CASE"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> <!-- Too many local variables within a method --> <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> <!-- Too many returns from within a method --> <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="LITERAL_RETURN"/> <property name="maximumNumber" value="3"/> </module> <!-- Too many fields within an interface --> <module name="DescendantToken"> <property name="tokens" value="INTERFACE_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="0"/> </module> <!-- Limit the number of exceptions a method can throw --> <module name="DescendantToken"> <property name="tokens" value="LITERAL_THROWS"/> <property name="limitedTokens" value="IDENT"/> <property name="maximumNumber" value="1"/> </module> <!-- Limit the number of expressions in a method --> <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="EXPR"/> <property name="maximumNumber" value="200"/> </module> <!-- Disallow empty statements --> <module name="DescendantToken"> <property name="tokens" value="EMPTY_STAT"/> <property name="limitedTokens" value="EMPTY_STAT"/> <property name="maximumNumber" value="0"/> <property name="maximumDepth" value="0"/> <property name="maximumMessage" value="Empty statement is not allowed."/> </module> <!-- Too many fields within a class --> <module name="DescendantToken"> <property name="tokens" value="CLASS_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module>
Field Summary | |
private int[] |
mCounts
Counts of descendant tokens. |
private int[] |
mLimitedTokens
limited tokens |
private int |
mMaximumDepth
maximum depth |
private java.lang.String |
mMaximumMessage
error message when maximum count exceeded |
private int |
mMaximumNumber
maximum number |
private int |
mMinimumDepth
minimum depth |
private java.lang.String |
mMinimumMessage
error message when minimum count not reached |
private int |
mMinimumNumber
minimum number |
Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check |
|
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter |
|
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
|
Constructor Summary | |
DescendantTokenCheck()
|
Method Summary | |
private void |
countTokens(antlr.collections.AST aAST,
int aDepth)
Counts the number of occurrences of descendant tokens. |
int[] |
getAcceptableTokens()
The configurable token set. |
int[] |
getDefaultTokens()
Returns the default token a check is interested in. |
void |
setLimitedTokens(java.lang.String[] aLimitedTokens)
Sets the tokens which occurance as descendant is limited. |
void |
setMaximumDepth(int aMaximumDepth)
Sets the maximum depth for descendant counts. |
void |
setMaximumMessage(java.lang.String aMessage)
Sets the error message for maximum count exceeded. |
void |
setMaximumNumber(int aMaximumNumber)
Sets a maximum count for descendants. |
void |
setMinimumDepth(int aMinimumDepth)
Sets the mimimum depth for descendant counts. |
void |
setMinimumMessage(java.lang.String aMessage)
Sets the error message for minimum count not reached. |
void |
setMinimumNumber(int aMinimumNumber)
Sets a minimum count for descendants. |
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
Called to process a token. |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check |
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter |
getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, setSeverity |
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
configure, contextualize, finishLocalSetup, getConfiguration, setupChild |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
mMinimumDepth
private int mMinimumDepth
- minimum depth
mMaximumDepth
private int mMaximumDepth
- maximum depth
mMinimumNumber
private int mMinimumNumber
- minimum number
mMaximumNumber
private int mMaximumNumber
- maximum number
mLimitedTokens
private int[] mLimitedTokens
- limited tokens
mMinimumMessage
private java.lang.String mMinimumMessage
- error message when minimum count not reached
mMaximumMessage
private java.lang.String mMaximumMessage
- error message when maximum count exceeded
mCounts
private int[] mCounts
- Counts of descendant tokens.
Indexed by (token ID - 1) for performance.
Constructor Detail |
DescendantTokenCheck
public DescendantTokenCheck()
Method Detail |
getDefaultTokens
public int[] getDefaultTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- Returns the default token a check is interested in. Only used if the
configuration for a check does not define the tokens.
visitToken
public void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- Called to process a token.
countTokens
private void countTokens(antlr.collections.AST aAST, int aDepth)
- Counts the number of occurrences of descendant tokens.
getAcceptableTokens
public int[] getAcceptableTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- The configurable token set.
Used to protect Checks against malicious users who specify an
unacceptable token set in the configuration file.
The default implementation returns the check's default tokens.
setLimitedTokens
public void setLimitedTokens(java.lang.String[] aLimitedTokens)
- Sets the tokens which occurance as descendant is limited.
setMinimumDepth
public void setMinimumDepth(int aMinimumDepth)
- Sets the mimimum depth for descendant counts.
setMaximumDepth
public void setMaximumDepth(int aMaximumDepth)
- Sets the maximum depth for descendant counts.
setMinimumNumber
public void setMinimumNumber(int aMinimumNumber)
- Sets a minimum count for descendants.
setMaximumNumber
public void setMaximumNumber(int aMaximumNumber)
- Sets a maximum count for descendants.
setMinimumMessage
public void setMinimumMessage(java.lang.String aMessage)
- Sets the error message for minimum count not reached.
setMaximumMessage
public void setMaximumMessage(java.lang.String aMessage)
- Sets the error message for maximum count exceeded.
|
|||||||||
Home >> All >> com >> puppycrawl >> tools >> checkstyle >> [ checks overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: ![]() ![]() ![]() |
DETAIL: FIELD | CONSTR | METHOD |