org.gmetrics.metric.cyclomatic
Class CyclomaticComplexityMetric
java.lang.Object
org.gmetrics.metric.AbstractMetric
org.gmetrics.metric.AbstractMethodMetric
org.gmetrics.metric.cyclomatic.CyclomaticComplexityMetric
- All Implemented Interfaces:
- groovy.lang.GroovyObject, Metric
public class CyclomaticComplexityMetric
- extends AbstractMethodMetric
- implements groovy.lang.GroovyObject
Metric for counting the (McCabe) Cyclomatic Complexity for methods and closure fields.
The counting rules for Groovy:
1. Each method starts with a complexity count of one.
2. Add one to the complexity count for each occurrence of:
if while for case catch && || ?: (ternary-operator) ?: (elvis-operator) ?. (null-check)
Additional notes:
- If a class field is initialized to a Closure (ClosureExpression), then that Closure is
analyzed just like a method.
See http://en.wikipedia.org/wiki/Cyclomatic_complexity
- Version:
- $Revision: 101 $ - $Date: 2010-03-10 19:17:23 -0500 (Wed, 10 Mar 2010) $
- Author:
- Chris Mair
|
Method Summary |
java.lang.Object |
calculate(org.codehaus.groovy.ast.expr.ClosureExpression closureExpression,
SourceCode sourceCode)
|
java.lang.Object |
calculate(org.codehaus.groovy.ast.MethodNode methodNode,
SourceCode sourceCode)
|
groovy.lang.MetaClass |
getMetaClass()
|
java.lang.String |
getName()
|
java.lang.Object |
getProperty(java.lang.String name)
|
java.lang.Object |
invokeMethod(java.lang.String name,
java.lang.Object args)
|
void |
setMetaClass(groovy.lang.MetaClass metaClass)
|
void |
setProperty(java.lang.String name,
java.lang.Object value)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
CyclomaticComplexityMetric
public CyclomaticComplexityMetric()
getName
public final java.lang.String getName()
- Specified by:
getName in interface Metric
calculate
public java.lang.Object calculate(org.codehaus.groovy.ast.MethodNode methodNode,
SourceCode sourceCode)
- Specified by:
calculate in class AbstractMethodMetric
calculate
public java.lang.Object calculate(org.codehaus.groovy.ast.expr.ClosureExpression closureExpression,
SourceCode sourceCode)
- Specified by:
calculate in class AbstractMethodMetric
getMetaClass
public groovy.lang.MetaClass getMetaClass()
- Specified by:
getMetaClass in interface groovy.lang.GroovyObject- Overrides:
getMetaClass in class AbstractMethodMetric
setMetaClass
public void setMetaClass(groovy.lang.MetaClass metaClass)
- Specified by:
setMetaClass in interface groovy.lang.GroovyObject- Overrides:
setMetaClass in class AbstractMethodMetric
invokeMethod
public java.lang.Object invokeMethod(java.lang.String name,
java.lang.Object args)
- Specified by:
invokeMethod in interface groovy.lang.GroovyObject- Overrides:
invokeMethod in class AbstractMethodMetric
getProperty
public java.lang.Object getProperty(java.lang.String name)
- Specified by:
getProperty in interface groovy.lang.GroovyObject- Overrides:
getProperty in class AbstractMethodMetric
setProperty
public void setProperty(java.lang.String name,
java.lang.Object value)
- Specified by:
setProperty in interface groovy.lang.GroovyObject- Overrides:
setProperty in class AbstractMethodMetric
Copyright © 2010. All Rights Reserved.