Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.puppycrawl.tools.checkstyle.checks.design
Class ThrowsCountCheck  view ThrowsCountCheck download ThrowsCountCheck.java

java.lang.Object
  extended bycom.puppycrawl.tools.checkstyle.api.AutomaticBean
      extended bycom.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
          extended bycom.puppycrawl.tools.checkstyle.api.Check
              extended bycom.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.AbstractViolationReporter
 
Fields inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
 
Constructor Summary
ThrowsCountCheck()
          Creates new instance of the check.
 
Method Summary
 int[] getDefaultTokens()
          Returns the default token a check is interested in.
 int getMax()
          Getter for max property.
 int[] getRequiredTokens()
          The tokens that this check must be registered for.
 void setMax(int aMax)
          Setter for max property.
private  void visitLiteralThrows(com.puppycrawl.tools.checkstyle.api.DetailAST aAST)
          Checks number of throws statments.
 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, getAcceptableTokens, getClassLoader, getFileContents, getLines, 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

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

Constructor Detail

ThrowsCountCheck

public ThrowsCountCheck()
Creates new instance of the check.

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.


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.