Calculates the ABC Metric for a class or method. ABC is a metric of size/complexity that counts the number of Assignments (A), Branches (B) and Conditions (C) and assigns a single numerical score calculated as:
Implemented by the
The ABC Metric calculation rules for Groovy:
Add one to the assignment count for each occurrence of an assignment operator, excluding constant declarations:
= *= /= %= += \<\<= \>\>= &= |= ^= \>\>\>= ?=
Add one to the assignment count for each occurrence of an increment or decrement operator (prefix or postfix):
Add one to the branch count for each function call or class method call.
Add one to the branch count for each occurrence of the new operator.
Add one to the branch count for each occurrence of the null-safe dereference (e.g.
x?.y) or the null-safe indexing (e.g.
Add one to the condition count for each use of a conditional operator:
== != \<= \>= \< \> \<=\> =~ ==~ === !== instanceof !instanceof in !in
Add one to the condition count for each use of the following keywords:
else case default try catch ?
Add one to the condition count for each unary conditional expression.
These are cases where a single variable/field/value is treated as a boolean value.
if (x) and
A property access is treated like a method call (and thus increments the branch count).
If a class field is initialized to a Closure (ClosureExpression), then that Closure is analyzed just like a method.
A frequently-referenced blog post by Jake Scruggs () offers the following guidelines for interpreting an ABC score. Note that these values refer to the score (magnitude) calculated for a single method:
The following properties can be configured for this metric within a MetricSet. See Creating a MetricSet for information on the syntax of setting a metric property.
 The ABC Metric specification.
 The The C2 Wiki page for the ABC Metric.
 Groovy Code Metrics: ABC - Discusses using GMetrics and CodeNarc for measuring and enforcing the ABC metric on Groovy code.
 Flog is the popular Ruby tool that uses ABC.
 This blog post describes some guidelines for interpreting the ABC score. The post refers to the Flog tool, but the ABC score is calculated similarly (though adapted somewhat to account for language specifics) and the guidelines should be transferable.