checkstyle/src/xdocs/config_metrics.xml

505 lines
16 KiB
XML

<?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">
<properties>
<title>Metrics</title>
<author>Checkstyle Development Team</author>
</properties>
<body>
<section name="BooleanExpressionComplexity">
<subsection name="Description">
<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="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#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>
</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>
</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>
</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="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>
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 abstract data type with
other abstract data types as members has data abstraction
coupling; therefore, if a class has a local variable that is
an instantiation (object) of another class, there is data
abstraction coupling. The higher the DAC, the more complex the
data structure (classes) of the system.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</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>
</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>
</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>
</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>
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>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</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>
</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>
</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>
</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>
Checks cyclomatic complexity against a specified limit. The
complexity is measured by the number of <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> (plus one) in the body of a
constructor, method, static initializer, or instance
initializer. It is a measure of the minimum number of
possible paths through the source and therefore the number of
required tests. Generally 1-4 is considered good, 5-7 OK, 8-10
consider re-factoring, and 11+ re-factor now!
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</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>
</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 7:
</p>
<source>
&lt;module name=&quot;CyclomaticComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;7&quot;/&gt;
&lt;/module&gt;
</source>
</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>
The NPATH metric computes the number of possible execution
paths through a function. It takes into account the nesting of
conditional statements and multi-part boolean expressions
(e.g., A &amp;&amp; B, C || D, etc.).
</p>
<p>
Rationale: Nejmeh says that his group had an informal NPATH
limit of 200 on individual routines; functions that exceeded
this value were candidates for further decomposition - or at
least a closer look.
</p>
</subsection>
<subsection name="Properties">
<table>
<tr>
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</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>
</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 20:
</p>
<source>
&lt;module name=&quot;NPathComplexity&quot;&gt;
&lt;property name=&quot;max&quot; value=&quot;20&quot;/&gt;
&lt;/module&gt;
</source>
</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>
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>
</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>
</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>
</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>
</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="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>