#336 Cyclomatic complexity should have an option to ignore 'case'

Check (274)

I've been working with CheckStyle for over a year now.
Very useful tool.

Recently I discovered the metrics checks.

All my "most complex" methods in terms of cyclomatic
complexity contain large switch statements with lots of
cases, usually converting some enum like values into
Strings or so. There's absolutely no way to reduce the
complexity as it is counted now.

It would be useful to have an option in the cyclomatic
complexity rule to disable the counting of "case"
statements. (See http://www.testersedge.com/ezmetrics.htm).


  • Jason Bennett

    Jason Bennett - 2006-05-16

    Logged In: YES


    This web page has a good set of rules to calculate CC in
    switch statements:

    Each if-statement introduces a new branch to the program and
    therefore increases v(G) by one.
    Iteration constructs such as for- and while-loops also
    introduce branches. Each case ...: part in the
    switch-statement increase the v(G) by one.
    Case branch does not increase v(G), because it does not
    increase the number of branches in the control flow. If
    there are two or more case ...: parts that have no code in
    between, the McCabe measure is increased only with one for
    all those case ...: parts.
    Each catch (...) part in a try-block increases v(G) by one.
    Construction exprl ? expr2 : expr3 increases v(G) by one.

  • Oliver Burn

    Oliver Burn - 2006-05-17

    Logged In: YES

    Interesting idea - care to submit a patch?

  • Jason Bennett

    Jason Bennett - 2006-05-17

    Logged In: YES

    Well, yes, I would like to, but looking over the code it
    appears that you can only enable certainn token types (say,

    What we need here is "CASE, except when there's been no code
    since the last one." I'm not sure if the current structure
    really supports that.

  • Jason Bennett

    Jason Bennett - 2006-09-07

    Logged In: YES

    Patch ready. It now ignores case statements that have
    another case as a sibling (e.g. in case groups)

  • Roman Ivanov

    Roman Ivanov - 2016-06-25
    • status: open --> closed
    • Group: --> Future

Log in to post a comment.