com.puppycrawl.tools.checkstyle.checks.coding

Class ReturnCountCheck

Implemented Interfaces:
Configurable, Contextualizable

public final class ReturnCountCheck
extends AbstractFormatCheck

Restricts return statements to a specified count (default = 2). Ignores specified methods (equals() by default).

Rationale: Too many return points can be indication that code is attempting to do too much or may be difficult to understand.

Author:
Simon Harris TODO: Test for inside a static block

Constructor Summary

ReturnCountCheck()
Creates new instance of the checks.

Method Summary

void
beginTree(DetailAST aRootAST)
int[]
getDefaultTokens()
int
getMax()
Getter for max property.
int[]
getRequiredTokens()
void
leaveToken(DetailAST aAST)
void
setMax(int aMax)
Setter for max property.
void
visitToken(DetailAST aAST)

Methods inherited from class com.puppycrawl.tools.checkstyle.checks.AbstractFormatCheck

getFormat, getRegexp, setCompileFlags, setFormat

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check

beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getDefaultTokens, getFileContents, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens, visitToken

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter

getId, getMessageBundle, getSeverity, getSeverityLevel, log, log, log, log, log, log, log, log, log, log, log, setId, setSeverity

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean

configure, contextualize, finishLocalSetup, getConfiguration, setupChild

Constructor Details

ReturnCountCheck

public ReturnCountCheck()
Creates new instance of the checks.

Method Details

beginTree

public void beginTree(DetailAST aRootAST)
Overrides:
beginTree in interface Check

getDefaultTokens

public int[] getDefaultTokens()
Overrides:
getDefaultTokens in interface Check

getMax

public int getMax()
Getter for max property.
Returns:
maximum allowed number of return statements.

getRequiredTokens

public int[] getRequiredTokens()
Overrides:
getRequiredTokens in interface Check

leaveToken

public void leaveToken(DetailAST aAST)
Overrides:
leaveToken in interface Check

setMax

public void setMax(int aMax)
Setter for max property.
Parameters:
aMax - maximum allowed number of return statements.

visitToken

public void visitToken(DetailAST aAST)
Overrides:
visitToken in interface Check