java.lang.Object
com.puppycrawl.tools.checkstyle.api.AutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.Check
com.puppycrawl.tools.checkstyle.checks.design.ThrowsCountCheck
- All Implemented Interfaces:
- com.puppycrawl.tools.checkstyle.api.Configurable, com.puppycrawl.tools.checkstyle.api.Contextualizable
- public final class ThrowsCountCheck
- extends com.puppycrawl.tools.checkstyle.api.Check
Restricts throws statements to a specified count (default = 1).
Rationale:
Exceptions form part of a methods interface. Declaring
a method to throw too many differently rooted
exceptions makes exception handling onerous and leads
to poor programming practices such as catch
(Exception). This check forces developers to put
exceptions into a heirachy such that in the simplest
case, only one type of exception need be checked for by
a caller but allows any sub-classes to be caught
specifically if necessary.
|
Field Summary |
private static int |
DEFAULT_MAX
default value of max property |
private int |
mMax
maximum allowed throws statments |
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.Check |
|
| Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean |
|
| Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check |
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_MAX
private static final int DEFAULT_MAX
- default value of max property
- See Also:
- Constant Field Values
mMax
private int mMax
- maximum allowed throws statments
ThrowsCountCheck
public ThrowsCountCheck()
- Creates new instance of the check.
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.
getRequiredTokens
public int[] getRequiredTokens()
- Description copied from class:
com.puppycrawl.tools.checkstyle.api.Check
- The tokens that this check must be registered for.
getMax
public int getMax()
- Getter for max property.
setMax
public void setMax(int aMax)
- Setter for max property.
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.
visitLiteralThrows
private void visitLiteralThrows(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
- Checks number of throws statments.