Groovy Documentation

org.codenarc.rule.size
Class CyclomaticComplexityRule

java.lang.Object
  org.codenarc.rule.AbstractRule
      org.codenarc.rule.AbstractAstVisitorRule
          org.codenarc.rule.size.CyclomaticComplexityRule

class CyclomaticComplexityRule
extends AbstractAstVisitorRule

Rule that calculates the Cyclomatic Complexity for methods/classes and checks against configured threshold values.

The maxMethodComplexity property holds the threshold value for the cyclomatic complexity value for each method. If this value is non-zero, a method with a cyclomatic complexity value greater than this value is considered a violation. The maxMethodComplexity property defaults to 20.

The maxClassAverageMethodComplexity property holds the threshold value for the average cyclomatic complexity value for each class. If this value is non-zero, a class with an average cyclomatic complexity value greater than this value is considered a violation. The maxMethodComplexity property defaults to 20.

The ignoreMethodNames property optionally specifies one or more (comma-separated) method names that should be ignored (i.e., that should not cause a rule violation). The name(s) may optionally include wildcard characters ('*' or '?'). Note that the ignored methods still contribute to the class complexity value.

This rule treats "closure fields" as methods. If a class field is initialized to a Closure (ClosureExpression), then that Closure is analyzed and checked just like a method.

see:
Cyclomatic Complexity Wikipedia entry.
see:
The original paper describing Cyclomatic Complexity.
see:
GMetrics Cyclomatic Complexity metric.
author:
Chris Mair
version:
$Revision: 338 $ - $Date: 2010-05-03 22:23:57 -0400 (Mon, 03 May 2010) $


Property Summary
Class astVisitorClass

String ignoreMethodNames

int maxClassAverageMethodComplexity

int maxMethodComplexity

String name

int priority

 
Constructor Summary
CyclomaticComplexityRule()

 
Method Summary
 
Methods inherited from class AbstractAstVisitorRule
shouldApplyThisRuleTo
 
Methods inherited from class AbstractRule
applyTo, createViolation, createViolation, createViolationForImport, createViolationForImport, getImportsSortedByLineNumber, getName, getPriority, packageNameForImport, setName, setPriority, sourceLineAndNumberForImport, sourceLineAndNumberForImport
 

Property Detail

astVisitorClass

Class astVisitorClass


ignoreMethodNames

String ignoreMethodNames


maxClassAverageMethodComplexity

int maxClassAverageMethodComplexity


maxMethodComplexity

int maxMethodComplexity


name

String name


priority

int priority


 
Constructor Detail

CyclomaticComplexityRule

CyclomaticComplexityRule()


 

Groovy Documentation