blob: 62b991025e2f9c51bd7f860065376098811932df [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<document xmlns="http://maven.apache.org/XDOC/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
<head>
<title>Metrics</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
<script type="text/javascript" src="js/anchors.js"/>
<script type="text/javascript" src="js/google-analytics.js"/>
<link rel="icon" href="images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
</head>
<body>
<section name="Content">
<macro name="toc">
<param name="fromDepth" value="1"/>
<param name="toDepth" value="1"/>
</macro>
</section>
<section name="BooleanExpressionComplexity">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
Restrict the number of number of <code>&#x26;&#x26;</code>, <code>||</code>,
<code>&#x26;</code>, <code>|</code>
and <code>^</code> in an expression.
</p>
<p>
Rationale: Too many conditions leads to code that is difficult
to read and hence debug and maintain.
</p>
<p>
Note that the operators <code>&#x26;</code> and
<code>|</code> are not only integer bitwise operators, they are also the
<a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22.2">
non-shortcut versions</a> of the boolean operators.
<code>&#x26;&#x26;</code> and <code>||</code>.
</p>
<p>
Note that <code>&#x26;</code>, <code>|</code> and <code>^</code> are not checked
if they are part of constructor or method call
because they can be applied to non boolean variables and
Checkstyle does not know types of methods from different classes.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>
the maximum allowed number of boolean operations in one
expression.
</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>3</code></td>
<td>3.4</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND">BAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR">BOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR">BXOR</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND">BAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR">BOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR">BXOR</a>.
</td>
<td>3.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;BooleanExpressionComplexity&quot;/&gt;
</source>
<p>
To configure the check with 7 allowed operation in boolean
expression:
</p>
<source>
&lt;module name=&quot;BooleanExpressionComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;7&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check to ignore <code>&#x26;</code> and
<code>|</code>:
</p>
<source>
&lt;module name="BooleanExpressionComplexity"&gt;
&lt;property name="tokens" value="BXOR,LAND,LOR"/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+BooleanExpressionComplexity">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22booleanExpressionComplexity%22">
booleanExpressionComplexity</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ClassDataAbstractionCoupling">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
This metric measures the number of instantiations of other
classes within the given class. This type of coupling is not
caused by inheritance or the object oriented
paradigm. Generally speaking, any data type with other data
types as members or local variable that is an instantiation
(object) of another class has data abstraction coupling (DAC).
The higher the DAC, the more complex the structure of the class.
</p>
<p>
This check processes files in the following way:
<ol>
<li>
Iterates over the list of tokens (defined below) and counts all mentioned classes.
<ul>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">PACKAGE_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">IMPORT</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">ENUM_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">LITERAL_NEW</a>
</li>
</ul>
</li>
<li>
If a class was imported with direct import (i.e. <code>import java.math.BigDecimal</code>),
or the class was referenced with the package name (i.e. <code>java.math.BigDecimal value</code>)
and the package was added to the <code>excludedPackages</code> parameter,
the class does not increase complexity.
</li>
<li>
If a class name was added to the <code>excludedClasses</code> parameter,
the class does not increase complexity.
</li>
</ol>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>the maximum threshold allowed</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>7</code></td>
<td>3.4</td>
</tr>
<tr>
<td>excludedClasses</td>
<td>User-configured class names to ignore</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>boolean, byte, char, double, float, int,
long, short, void, Boolean, Byte, Character, Double, Float,
Integer, Long, Short, Void,
Object, Class, String, StringBuffer, StringBuilder,
ArrayIndexOutOfBoundsException, Exception,
RuntimeException, IllegalArgumentException,
IllegalStateException, IndexOutOfBoundsException,
NullPointerException, Throwable, SecurityException,
UnsupportedOperationException,
List, ArrayList, Deque, Queue, LinkedList,
Set, HashSet, SortedSet, TreeSet,
Map, HashMap, SortedMap, TreeMap</td>
<td>5.7</td>
</tr>
<tr>
<td>excludeClassesRegexps</td>
<td>User-configured regular expressions to ignore classes</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td><code>"^$"</code></td>
<td>7.7</td>
</tr>
<tr>
<td>excludedPackages</td>
<td>User-configured packages to ignore</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>{}</td>
<td>7.7</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;/&gt;
</source>
<p>
To configure the check with a threshold of 5:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;5&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check with two excluded classes <code>HashMap</code> and <code>HashSet</code>:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedClasses&quot; value=&quot;HashMap, HashSet&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check with two regular expressions <code>^Array.*</code> and <code>.*Exception$</code>:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludeClassesRegexps&quot; value=&quot;^Array.*, .*Exception$&quot;/&gt;
&lt;/module&gt;
</source>
<p>
The following example demonstrates usage of <b>excludedClasses</b> and <b>excludeClassesRegexps</b> properties
</p>
<p>
Expected result is one class <code>Date</code>
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedClasses&quot; value=&quot;ArrayList&quot;/&gt;
&lt;property name=&quot;excludeClassesRegexps&quot; value=&quot;^Hash.*&quot;/&gt;
&lt;/module&gt;
</source>
<source>
public class InputClassCoupling {
public Set _set = new HashSet();
public Map _map = new HashMap();
public List&lt;String&gt; _list = new ArrayList&lt;&gt;();
public Date _date = new Date();
}
</source>
<p>
To configure the check with two excluded classes <code>HashMap</code> and <code>HashSet</code>:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedClasses&quot; value=&quot;HashMap, HashSet&quot;/&gt;
&lt;/module&gt;
</source>
<p>
To configure the check with two regular expressions <code>^Array.*</code> and <code>.*Exception$</code>:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludeClassesRegexps&quot; value=&quot;^Array.*, .*Exception$&quot;/&gt;
&lt;/module&gt;
</source>
<p>
The following example demonstrates usage of <b>excludedClasses</b> and <b>excludeClassesRegexps</b> properties
</p>
<p>
Expected result is one class <code>Date</code>
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedClasses&quot; value=&quot;ArrayList&quot;/&gt;
&lt;property name=&quot;excludeClassesRegexps&quot; value=&quot;^Hash.*&quot;/&gt;
&lt;/module&gt;
</source>
<source>
public class InputClassCoupling {
public Set _set = new HashSet();
public Map _map = new HashMap();
public List&lt;String&gt; _list = new ArrayList&lt;&gt;();
public Date _date = new Date();
}
</source>
<p>
Override property <code>excludedPackages</code> to mark some packages as excluded.
Each member of <code>excludedPackages</code> should be a valid identifier:
<ul>
<li>
<code>java.util</code> - valid, excludes all classes inside <code>java.util</code>,
but not from the subpackages.
</li>
<li>
<code>java.util.</code> - invalid, should not end with a dot.
</li>
<li>
<code>java.util.*</code> - invalid, should not end with a star.
</li>
</ul>
</p>
<p>
Note, that checkstyle will ignore all classes from the <code>java.lang</code> package and its subpackages,
even if the <code>java.lang</code> was not listed in the <code>excludedPackages</code> parameter.
</p>
<p>
Also node, that <code>excludedPackages</code> will not exclude classes, imported via wildcard
(e.g. <code>import java.math.*</code>). Instead of wildcard import you should use direct import
(e.g. <code>import java.math.BigDecimal</code>).
</p>
<p>
Also note, that checkstyle will not exlude classes within the same file
even if it was listed in the <code>excludedPackages</code> parameter. For example, assuming the config is
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedPackages&quot; value=&quot;a.b&quot;/&gt;
&lt;/module&gt;
</source>
And the file <code>a.b.Foo.java</code> is:
<source>
package a.b;
import a.b.Bar;
import a.b.c.Baz;
public class Foo {
public Bar bar; // Will be ignored, located inside ignored a.b package
public Baz baz; // Will not be ignored, located inside a.b.c package
public Data data; // Will not be ignored, same file
class Data {
public Foo foo; // Will not be ignored, same file
}
}
</source>
The <code>bar</code> member will not be counted,
since the <code>a.b</code> added to the <code>excludedPackages</code>.
The <code>baz</code> member will be counted,
since the <code>a.b.c</code> was not added to the <code>excludedPackages</code>.
The <code>data</code> and <code>foo</code> members will be counted, as they are inside same file.
</p>
<p>
Example of usage:
</p>
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedPackages&quot; value=&quot;java.util, java.math&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ClassDataAbstractionCoupling">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22classDataAbstractionCoupling%22">
classDataAbstractionCoupling</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="ClassFanOutComplexity">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
The number of other classes a given class relies on. Also the
square of this has been shown to indicate the amount of
maintenance required in functional programs (on a file basis)
at least.
</p>
<p>
This check processes files in the following way:
<ol>
<li>
Iterates over the list of tokens (defined below) and counts all mentioned classes.
<ul>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#PACKAGE_DEF">PACKAGE_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#IMPORT">IMPORT</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CLASS_DEF">CLASS_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#INTERFACE_DEF">INTERFACE_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ENUM_DEF">ENUM_DEF</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#TYPE">TYPE</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">LITERAL_NEW</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_THROWS">
LITERAL_THROWS
</a>
</li>
<li>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#ANNOTATION_DEF">
ANNOTATION_DEF
</a>
</li>
</ul>
</li>
<li>
If a class was imported with direct import (i.e. <code>import java.math.BigDecimal</code>),
or the class was referenced with the package name (i.e. <code>java.math.BigDecimal value</code>)
and the package was added to the <code>excludedPackages</code> parameter,
the class does not increase complexity.
</li>
<li>
If a class name was added to the <code>excludedClasses</code> parameter,
the class does not increase complexity.
</li>
</ol>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>the maximum threshold allowed</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>20</code></td>
<td>3.4</td>
</tr>
<tr>
<td>excludedClasses</td>
<td>User-configured class names to ignore</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>boolean, byte, char, double, float, int,
long, short, void, Boolean, Byte, Character, Double, Float,
Integer, Long, Short, Void,
Object, Class, String, StringBuffer, StringBuilder,
ArrayIndexOutOfBoundsException, Exception,
RuntimeException, IllegalArgumentException,
IllegalStateException, IndexOutOfBoundsException,
NullPointerException, Throwable, SecurityException,
UnsupportedOperationException,
List, ArrayList, Deque, Queue, LinkedList,
Set, HashSet, SortedSet, TreeSet,
Map, HashMap, SortedMap, TreeMap</td>
<td>5.7</td>
</tr>
<tr>
<td>excludeClassesRegexps</td>
<td>User-configured regular expressions to ignore classes</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td><code>"^$"</code></td>
<td>7.7</td>
</tr>
<tr>
<td>excludedPackages</td>
<td>User-configured packages to ignore</td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td>{}</td>
<td>7.7</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;ClassFanOutComplexity&quot;/&gt;
</source>
<p>
To configure the check with a threshold of 10:
</p>
<source>
&lt;module name=&quot;ClassFanOutComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;10&quot;/&gt;
&lt;/module&gt;
</source>
<p>
Override property <code>excludedPackages</code> to mark some packages as excluded.
Each member of <code>excludedPackages</code> should be a valid identifier:
<ul>
<li>
<code>java.util</code> - valid, excludes all classes inside <code>java.util</code>,
but not from the subpackages.
</li>
<li>
<code>java.util.</code> - invalid, should not end with a dot.
</li>
<li>
<code>java.util.*</code> - invalid, should not end with a star.
</li>
</ul>
</p>
<p>
Note, that checkstyle will ignore all classes from the <code>java.lang</code> package and its subpackages,
even if the <code>java.lang</code> was not listed in the <code>excludedPackages</code> parameter.
</p>
<p>
Also node, that <code>excludedPackages</code> will not exclude classes, imported via wildcard
(e.g. <code>import java.math.*</code>). Instead of wildcard import you should use direct import
(e.g. <code>import java.math.BigDecimal</code>).
</p>
<p>
Also note, that checkstyle will not exlude classes within the same file
even if it was listed in the <code>excludedPackages</code> parameter. For example, assuming the config is
<source>
&lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
&lt;property name=&quot;excludedPackages&quot; value=&quot;a.b&quot;/&gt;
&lt;/module&gt;
</source>
And the file <code>a.b.Foo.java</code> is:
<source>
package a.b;
import a.b.Bar;
import a.b.c.Baz;
public class Foo {
public Bar bar; // Will be ignored, located inside ignored a.b package
public Baz baz; // Will not be ignored, located inside a.b.c package
public Data data; // Will not be ignored, same file
class Data {
public Foo foo; // Will not be ignored, same file
}
}
</source>
The <code>bar</code> member will not be counted,
since the <code>a.b</code> added to the <code>excludedPackages</code>.
The <code>baz</code> member will be counted,
since the <code>a.b.c</code> was not added to the <code>excludedPackages</code>.
The <code>data</code> and <code>foo</code> members will be counted, as they are inside same file.
</p>
<p>
Example of usage:
</p>
<source>
&lt;module name=&quot;ClassFanOutComplexity&quot;&gt;
&lt;property name=&quot;excludedPackages&quot; value=&quot;java.util, java.math&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+ClassFanOutComplexity">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22classFanOutComplexity%22">
classFanOutComplexity</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="CyclomaticComplexity">
<subsection name="Description">
<p>Since Checkstyle 3.2</p>
<p>
Checks cyclomatic complexity against a specified limit.
It is a measure of the minimum number of
possible paths through the source and therefore the number of
required tests, it is not a about quality of code!
It is only applied to methods, c-tors,
<a href="https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html">static initializers and instance initializers</a>.
<br/>
The complexity is equal to the number of decision points <code> + 1</code>
Decision points: <code>if</code>, <code>while</code>
, <code>do</code>, <code>for</code>, <code>?:</code>, <code>catch</code>
, <code>switch</code>, <code>case</code>
statements, and operators <code>&#x26;&#x26;</code> and <code>||</code>
in the body of target.
<br/>By pure theory level 1-4 is considered easy to test, 5-7 OK, 8-10
consider re-factoring to ease testing, and 11+ re-factor now as testing will be painful.
<br/>When it comes to code quality measurement by this metric
level 10 is very good level as a ultimate target (that is hard to archive).
Do not be ashamed to have complexity level 15 or even higher,
but keep it below 20 to catch really bad designed code automatically.
<br/>Please use Suppression to avoid violations on cases that could not be split in few
methods without damaging readability of code or encapsulation.
<br/>
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>the maximum threshold allowed</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>10</code></td>
<td>3.2</td>
</tr>
<tr>
<td>switchBlockAsSingleDecisionPoint</td>
<td>whether to treat the whole switch block as a single decision point</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><code>false</code></td>
<td>6.11</td>
</tr>
<tr>
<td>tokens</td>
<td>tokens to check</td>
<td>
subset of tokens
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">LITERAL_WHILE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">LITERAL_DO</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">LITERAL_FOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">LITERAL_IF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">LITERAL_SWITCH</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">LITERAL_CASE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#QUESTION">QUESTION</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>.
</td>
<td>
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_WHILE">LITERAL_WHILE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_DO">LITERAL_DO</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_FOR">LITERAL_FOR</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_IF">LITERAL_IF</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_SWITCH">LITERAL_SWITCH</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">LITERAL_CASE</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CATCH">LITERAL_CATCH</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#QUESTION">QUESTION</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
<a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>.
</td>
<td>3.2</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;CyclomaticComplexity&quot;/&gt;
</source>
<p>
To configure the check with a threshold of 15:
</p>
<source>
&lt;module name=&quot;CyclomaticComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;15&quot;/&gt;
&lt;/module&gt;
</source>
<p>
Explanation on how complexity is calculated (switchBlockAsSingleDecisionPoint is set to false):
</p>
<source>
class CC {
// Cyclomatic Complexity = 12
public void doSmth() { // 1
if (a == b) { // 2
if (a1 == b1 // 3
&amp;&amp; c1 == d1) { // 4
fiddle();
}
else if (a2 == b2 // 5
|| c1 &lt; d1) { // 6
fiddle();
}
else {
fiddle();
}
}
else if (c == d) { // 7
while (c == d) { // 8
fiddle();
}
}
else if (e == f) {
for (n = 0; n &lt; h // 9
|| n &lt; 6; n++) { // 10
fiddle();
}
}
else {
switch (z) {
case 1: // 11
fiddle();
break;
case 2: // 12
fiddle();
break;
default:
fiddle();
break;
}
}
}
} </source>
<p>
Explanation on how complexity is calculated (switchBlockAsSingleDecisionPoint is set to true):
</p>
<source>
class SwitchExample {
// Cyclomatic Complexity = 2
public void doSmth() { // 1
int z = 1;
switch (z) { // 2
case 1:
foo1();
break;
case 2:
foo2();
break;
default:
fooDefault();
break;
}
}
} </source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+CyclomaticComplexity">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22cyclomaticComplexity%22">
cyclomaticComplexity</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="JavaNCSS">
<subsection name="Description">
<p>Since Checkstyle 3.5</p>
<p>
Determines complexity of methods, classes and files by
counting the Non Commenting Source Statements (NCSS). This
check adheres to the <a
href="http://www.kclee.de/clemens/java/javancss/#specification">
specification</a> for the
<a href="http://www.kclee.de/clemens/java/javancss/">JavaNCSS-Tool</a>
written by <b>Chr. Clemens Lee</b>.<br/>
Roughly said the NCSS metric is calculated by
counting the source lines which are not comments, (nearly)
equivalent to counting the semicolons and opening curly
braces.<br/> The NCSS for a class is summarized from the NCSS
of all its methods, the NCSS of its nested classes and the
number of member variable declarations.<br/> The NCSS for a
file is summarized from the ncss of all its top level classes,
the number of imports and the package declaration.
</p>
<p>
Rationale: Too large methods and classes are hard to read and
costly to maintain. A large NCSS number often means that a
method or class has too many responsibilities and/or
functionalities which should be decomposed into smaller units.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>methodMaximum</td>
<td>
the maximum allowed number of non commenting lines in a
method.
</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>50</code></td>
<td>3.5</td>
</tr>
<tr>
<td>classMaximum</td>
<td>
the maximum allowed number of non commenting lines in a
class.
</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>1500</code></td>
<td>3.5</td>
</tr>
<tr>
<td>fileMaximum</td>
<td>
the maximum allowed number of non commenting lines in a
file including all top level and nested classes.
</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>2000</code></td>
<td>3.5</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;JavaNCSS&quot;/&gt;
</source>
<p>
To configure the check with 40 allowed non commenting lines
for a method:
</p>
<source>
&lt;module name=&quot;JavaNCSS&quot;&gt;
&lt;property name=&quot;methodMaximum&quot; value=&quot;40&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+JavaNCSS">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22ncss.class%22">
ncss.class</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22ncss.file%22">
ncss.file</a>
</li>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22ncss.method%22">
ncss.method</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
<section name="NPathComplexity">
<subsection name="Description">
<p>Since Checkstyle 3.4</p>
<p>
The NPATH metric computes the number of possible execution
paths through a function(method). It takes into account the nesting of
conditional statements and multi-part boolean expressions
(A &amp;&amp; B, C || D, E ? F :G and their combinations).
<br/>
The NPATH metric was designed base on Cyclomatic complexity to
avoid problem of Cyclomatic complexity metric like nesting level within a function(method).
</p>
<p>
Metric was described at <a href="http://dl.acm.org/citation.cfm?id=42379">"NPATH: a measure of execution pathcomplexity and its applications"</a>. If you need detailed description of algorithm, please read that article,
it is well written and have number of examples and details.
</p>
<p>Here is some quotes:</p>
<blockquote>An NPATH threshold value of 200 has been established
for a function. The value 200 is based on studies done
at AT&amp;T Bell Laboratories [1988 year].
</blockquote>
<blockquote>
Some of the most effective methods of reducing the NPATH value include<br/>
- distributing functionality,<br/>
- implementing multiple if statements as a switch statement<br/>
- creating a separate function for logical expressions with a high count of and (&amp;&amp;) and or (||) operators.
</blockquote>
<blockquote>
Although strategies to reduce the NPATH complexity
of functions are important, care must be taken not to
distort the logical clarity of the software by applying a
strategy to reduce the complexity of functions. That is,
there is a point of diminishing return beyond which a
further attempt at reduction of complexity distorts the
logical clarity of the system structure.
</blockquote>
<table>
<thead><tr><th>Structure</th><th> Complexity expression </th></tr></thead>
<tr><td>if ([expr]) { [if-range] }</td><td>NP(if-range) + 1 + NP(expr)</td></tr>
<tr><td>if ([expr]) { [if-range] } else { [else-range] }</td><td>NP(if-range) + NP(else-range) + NP(expr)</td></tr>
<tr><td>while ([expr]) { [while-range] } </td><td>NP(while-range) + NP(expr) + 1</td></tr>
<tr><td>do { [do-range] } while ([expr])</td><td>NP(do-range) + NP(expr) + 1</td></tr>
<tr><td>for([expr1]; [expr2]; [expr3]) { [for-range] }</td><td>NP(for-range) + NP(expr1) + NP(expr2) + NP(expr3) + 1</td></tr>
<tr><td>switch ([expr]) { case : [case-range] default: [default-range] }</td><td>S(i=1:i=n)NP(case-range[i]) + NP(default-range) + NP(expr)</td></tr>
<tr><td>[expr1] ? [expr2] : [expr3]</td><td>NP(expr1) + NP(expr2) + NP(expr3) + 2</td></tr>
<tr><td>goto label</td><td>1</td></tr>
<tr><td>break</td><td>1</td></tr>
<tr><td>Expressions</td><td>Number of &amp;&amp; and || operators in expression. No operators - 0</td></tr>
<tr><td>continue</td><td>1</td></tr>
<tr><td>return</td><td>1</td></tr>
<tr><td>Statement (even sequential statements)</td><td>1</td></tr>
<tr><td>Empty block {}</td><td>1</td></tr>
<tr><td>Function call</td><td>1</td></tr>
<tr><td>Function(Method) declaration or Block</td><td>P(i=1:i=N)NP(Statement[i])</td></tr>
</table>
<p>
<b>Rationale:</b> Nejmeh says that his group had an informal NPATH
limit of 200 on individual routines; functions(methods) that exceeded
this value were candidates for further decomposition - or at
least a closer look.
<b>Please do not be fanatic with limit 200</b>
- choose number that suites your project style. Limit 200 is
empirical number base on some sources of at AT&amp;T Bell Laboratories
of 1988 year.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
<th>since</th>
</tr>
<tr>
<td>max</td>
<td>the maximum threshold allowed</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td><code>200</code></td>
<td>3.4</td>
</tr>
</table>
</subsection>
<subsection name="Examples">
<p>
To configure the check:
</p>
<source>
&lt;module name=&quot;NPathComplexity&quot;/&gt;
</source>
<p>
To configure the check with a threshold of 1000:
</p>
<source>
&lt;module name=&quot;NPathComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;1000&quot;/&gt;
&lt;/module&gt;
</source>
</subsection>
<subsection name="Example of Usage">
<ul>
<li>
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+NPathComplexity">
Checkstyle Style</a>
</li>
</ul>
</subsection>
<subsection name="Error Messages">
<ul>
<li>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fmetrics+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22npathComplexity%22">
npathComplexity</a>
</li>
</ul>
<p>
All messages can be customized if the default message doesn't suit you.
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
</p>
</subsection>
<subsection name="Package">
<p>
com.puppycrawl.tools.checkstyle.checks.metrics
</p>
</subsection>
<subsection name="Parent Module">
<p>
<a href="config.html#TreeWalker">TreeWalker</a>
</p>
</subsection>
</section>
</body>
</document>