Class CyclomaticComplexityCheck

  • All Implemented Interfaces:
    Configurable, Contextualizable

    public class CyclomaticComplexityCheck
    extends AbstractCheck
    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!

    Check has following properties:

    switchBlockAsSingleDecisionPoint - controls whether to treat the whole switch block as a single decision point. Default value is false

    Author:
    Simon Harris, Oliver Burn, Andrei Selkin
    • Method Detail

      • setSwitchBlockAsSingleDecisionPoint

        public void setSwitchBlockAsSingleDecisionPoint​(boolean switchBlockAsSingleDecisionPoint)
        Sets whether to treat the whole switch block as a single decision point.
        Parameters:
        switchBlockAsSingleDecisionPoint - whether to treat the whole switch block as a single decision point.
      • setMax

        public final void setMax​(int max)
        Set the maximum threshold allowed.
        Parameters:
        max - the maximum threshold
      • getAcceptableTokens

        public int[] getAcceptableTokens()
        Description copied from class: AbstractCheck
        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.
        Specified by:
        getAcceptableTokens in class AbstractCheck
        Returns:
        the token set this check is designed for.
        See Also:
        TokenTypes
      • visitTokenHook

        protected final void visitTokenHook​(DetailAST ast)
        Hook called when visiting a token. Will not be called the method definition tokens.
        Parameters:
        ast - the token being visited
      • incrementCurrentValue

        protected final void incrementCurrentValue​(BigInteger amount)
        Increments the current value by a specified amount.
        Parameters:
        amount - the amount to increment by
      • pushValue

        protected final void pushValue()
        Push the current value on the stack.
      • popValue

        protected final BigInteger popValue()
        Pops a value off the stack and makes it the current value.
        Returns:
        pop a value off the stack and make it the current value