## com.puppycrawl.tools.checkstyle.checks.metrics
Class CyclomaticComplexityCheck

    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.metrics.AbstractComplexityCheck
                      com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck

All Implemented Interfaces:
  Configurable, Contextualizable

    public class CyclomaticComplexityCheck

extends AbstractComplexityCheck

Checks cyclomatic complexity against a specified limit. The complexity is measured by the number of "if", "while", "do", "for", "?:", "catch", "switch", "case", "&&" and "||" statements (plus one) in the body of the member. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests. Generally 1-4 is considered good, 5-7 ok, 8-10 consider re-factoring, and 11+ re-factor now!

Author:
  Simon Harris, Oliver Burn

Constructor Summary
`CyclomaticComplexityCheck()` Create an instance.

Method Summary
`int[]` `getDefaultTokens()` Returns the default token a check is interested in.
`protected String` `getMessageID()`
`protected void` `visitTokenHook(DetailAST aAST)` Hook called when visiting a token.

Methods inherited from class com.puppycrawl.tools.checkstyle.checks.metrics.AbstractComplexityCheck
`getCurrentValue, getMax, getRequiredTokens, incrementCurrentValue, leaveToken, leaveTokenHook, popValue, pushValue, setCurrentValue, setMax, visitToken`

Methods inherited from class com.puppycrawl.tools.checkstyle.api.Check
`beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLines, getTabWidth, getTokenNames, init, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens`

Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
`getId, getMessageBundle, getSeverity, getSeverityLevel, 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`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### CyclomaticComplexityCheck

    public CyclomaticComplexityCheck()

  Create an instance.

Method Detail

### getDefaultTokens

    public int[] getDefaultTokens()

  Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.

  Specified by:
    `getDefaultTokens` in class `Check`
  Returns:
    the default tokens
  See Also:
    `TokenTypes`

### visitTokenHook

    protected final void visitTokenHook(DetailAST aAST)

  Hook called when visiting a token. Will not be called the method definition tokens.

  Overrides:
    `visitTokenHook` in class `AbstractComplexityCheck`
  Parameters:
    `aAST` - the token being visited

### getMessageID

    protected final String getMessageID()

  Specified by:
    `getMessageID` in class `AbstractComplexityCheck`
  Returns:
    the message ID to log violations with

Back to the Checkstyle Home Page