SourceForge: checkstyle/checkstyle: src/xdocs/config_metrics.xml@769708c5ee9f
src/xdocs/config_metrics.xml
author oburn
Mon Dec 22 22:31:40 2008 +0000 (2008-12-22)
changeset 2361 769708c5ee9f
parent 2197 742923956f44
child 2456 5dfe5afe6481
permissions -rwxr-xr-x
part of refactoring to consolidate all the regexp checks.
     1 <?xml version="1.0" encoding="ISO-8859-1"?>
     2 
     3 <document>
     4 
     5   <properties>
     6     <title>Metrics</title>
     7     <author>Checkstyle Development Team</author>
     8   </properties>
     9 
    10   <body>
    11 
    12     <section name="BooleanExpressionComplexity">
    13       <subsection name="Description">
    14         <p>
    15           Restrict the number of number of <span
    16           class="code">&#x26;&#x26;</span>, <span class="code">||</span>,
    17           <span class="code">&#x26;</span>, <span class="code">|</span>
    18           and <span class="code">^</span> in an expression.
    19         </p>
    20 
    21         <p>
    22           Rationale: Too many conditions leads to code that is difficult
    23           to read and hence debug and maintain.
    24         </p>
    25 
    26         <p>
    27           Note that the operators <span class="code">&#x26;</span> and
    28           <span class="code">|</span> are not only integer bitwise operators, they are also the
    29           <a href="http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.22.2">
    30           non-shortcut versions</a> of the boolean operators
    31           <span class="code">&#x26;&#x26;</span> and <span class="code">||</span>.
    32         </p>
    33       </subsection>
    34 
    35       <subsection name="Properties">
    36         <table>
    37           <tr>
    38             <th>name</th>
    39             <th>description</th>
    40             <th>type</th>
    41             <th>default value</th>
    42           </tr>
    43           <tr>
    44             <td>max</td>
    45             <td>
    46               the maximum allowed number of boolean operations in one
    47               expression.
    48             </td>
    49             <td><a href="property_types.html#integer">integer</a></td>
    50             <td><span class="default">3</span></td>
    51           </tr>
    52           <tr>
    53             <td>tokens</td>
    54             <td>tokens to check</td>
    55             <td>
    56               subset of tokens
    57               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
    58               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND">BAND</a>,
    59               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>,
    60               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR">BOR</a>,
    61               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR">BXOR</a>
    62             </td>
    63             <td>
    64               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAND">LAND</a>,
    65               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BAND">BAND</a>,
    66               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LOR">LOR</a>,
    67               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BOR">BOR</a>,
    68               <a href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#BXOR">BXOR</a>
    69             </td>
    70           </tr>
    71         </table>
    72       </subsection>
    73 
    74       <subsection name="Examples">
    75         <p>
    76           To configure the check:
    77         </p>
    78         <source>
    79 &lt;module name=&quot;BooleanExpressionComplexity&quot;/&gt;
    80         </source>
    81 
    82         <p>
    83           To configure the check with 7 allowed operation in boolean
    84           expression:
    85         </p>
    86         <source>
    87 &lt;module name=&quot;BooleanExpressionComplexity&quot;&gt;
    88     &lt;property name=&quot;max&quot; value=&quot;7&quot;/&gt;
    89 &lt;/module&gt;
    90         </source>
    91 
    92         <p>
    93           To configure the check to ignore <span class="code">&#x26;</span> and
    94           <span class="code">|</span>:
    95         </p>
    96         <source>
    97 &lt;module name="BooleanExpressionComplexity"&gt;
    98     &lt;property name="tokens" value="BXOR,LAND,LOR"/&gt;
    99 &lt;/module&gt;
   100         </source>
   101 
   102       </subsection>
   103 
   104       <subsection name="Package">
   105         <p>
   106           com.puppycrawl.tools.checkstyle.checks.metrics
   107         </p>
   108       </subsection>
   109 
   110       <subsection name="Parent Module">
   111         <p>
   112           <a href="config.html#treewalker">TreeWalker</a>
   113         </p>
   114       </subsection>
   115     </section>
   116 
   117     <section name="ClassDataAbstractionCoupling">
   118       <subsection name="Description">
   119         <p>
   120           This metric measures the number of instantiations of other
   121           classes within the given class. This type of coupling is not
   122           caused by inheritance or the object oriented
   123           paradigm. Generally speaking, any abstract data type with
   124           other abstract data types as members has data abstraction
   125           coupling; therefore, if a class has a local variable that is
   126           an instantiation (object) of another class, there is data
   127           abstraction coupling. The higher the DAC, the more complex the
   128           data structure (classes) of the system.
   129         </p>
   130       </subsection>
   131 
   132       <subsection name="Properties">
   133         <table>
   134           <tr>
   135             <th>name</th>
   136             <th>description</th>
   137             <th>type</th>
   138             <th>default value</th>
   139           </tr>
   140           <tr>
   141             <td>max</td>
   142             <td>the maximum threshold allowed</td>
   143             <td><a href="property_types.html#integer">integer</a></td>
   144             <td><span class="default">7</span></td>
   145           </tr>
   146         </table>
   147       </subsection>
   148 
   149       <subsection name="Examples">
   150         <p>
   151           To configure the check:
   152         </p>
   153         <source>
   154 &lt;module name=&quot;ClassDataAbstractionCoupling&quot;/&gt;
   155         </source>
   156 
   157         <p>
   158           To configure the check with a threshold of 5:
   159         </p>
   160         <source>
   161 &lt;module name=&quot;ClassDataAbstractionCoupling&quot;&gt;
   162     &lt;property name=&quot;max&quot; value=&quot;5&quot;/&gt;
   163 &lt;/module&gt;
   164         </source>
   165       </subsection>
   166 
   167       <subsection name="Package">
   168         <p>
   169           com.puppycrawl.tools.checkstyle.checks.metrics
   170         </p>
   171       </subsection>
   172 
   173       <subsection name="Parent Module">
   174         <p>
   175           <a href="config.html#treewalker">TreeWalker</a>
   176         </p>
   177       </subsection>
   178     </section>
   179 
   180     <section name="ClassFanOutComplexity">
   181       <subsection name="Description">
   182         <p>
   183           The number of other classes a given class relies on. Also the
   184           square of this has been shown to indicate the amount of
   185           maintenence required in functional programs (on a file basis)
   186           at least.
   187         </p>
   188       </subsection>
   189 
   190       <subsection name="Properties">
   191         <table>
   192           <tr>
   193             <th>name</th>
   194             <th>description</th>
   195             <th>type</th>
   196             <th>default value</th>
   197           </tr>
   198           <tr>
   199             <td>max</td>
   200             <td>the maximum threshold allowed</td>
   201             <td><a href="property_types.html#integer">integer</a></td>
   202             <td><span class="default">20</span></td>
   203           </tr>
   204         </table>
   205       </subsection>
   206 
   207       <subsection name="Examples">
   208         <p>
   209           To configure the check:
   210         </p>
   211         <source>
   212 &lt;module name=&quot;ClassFanOutComplexity&quot;/&gt;
   213         </source>
   214 
   215         <p>
   216           To configure the check with a threshold of 10:
   217         </p>
   218         <source>
   219 &lt;module name=&quot;ClassFanOutComplexity&quot;&gt;
   220     &lt;property name=&quot;max&quot; value=&quot;10&quot;/&gt;
   221 &lt;/module&gt;
   222         </source>
   223       </subsection>
   224 
   225       <subsection name="Package">
   226         <p>
   227           com.puppycrawl.tools.checkstyle.checks.metrics
   228         </p>
   229       </subsection>
   230 
   231       <subsection name="Parent Module">
   232         <p>
   233           <a href="config.html#treewalker">TreeWalker</a>
   234         </p>
   235       </subsection>
   236     </section>
   237 
   238     <section name="CyclomaticComplexity">
   239       <subsection name="Description">
   240         <p>
   241           Checks cyclomatic complexity against a specified limit. The
   242           complexity is measured by the number of <span
   243           CLASS="code">if</span>, <span CLASS="code">while</span>, <span
   244           CLASS="code">do</span>, <span CLASS="code">for</span>, <span
   245           CLASS="code">?:</span>, <span CLASS="code">catch</span>, <span
   246           CLASS="code">switch</span>, <span CLASS="code">case</span>
   247           statements, and operators <span
   248           CLASS="code">&#x26;&#x26;</span> and <span
   249           CLASS="code">||</span> (plus one) in the body of a
   250           constructor, method, static initializer, or instance
   251           initializer.  It is a measure of the minimum number of
   252           possible paths through the source and therefore the number of
   253           required tests. Generally 1-4 is considered good, 5-7 ok, 8-10
   254           consider re-factoring, and 11+ re-factor now!
   255         </p>
   256       </subsection>
   257 
   258       <subsection name="Properties">
   259         <table>
   260           <tr>
   261             <th>name</th>
   262             <th>description</th>
   263             <th>type</th>
   264             <th>default value</th>
   265           </tr>
   266           <tr>
   267             <td>max</td>
   268             <td>the maximum threshold allowed</td>
   269             <td><a href="property_types.html#integer">integer</a></td>
   270             <td><span class="default">10</span></td>
   271           </tr>
   272         </table>
   273       </subsection>
   274 
   275       <subsection name="Examples">
   276         <p>
   277           To configure the check:
   278         </p>
   279         <source>
   280 &lt;module name=&quot;CyclomaticComplexity&quot;/&gt;
   281         </source>
   282 
   283         <p>
   284           To configure the check with a threshold of 7:
   285         </p>
   286         <source>
   287 &lt;module name=&quot;CyclomaticComplexity&quot;&gt;
   288     &lt;property name=&quot;max&quot; value=&quot;7&quot;/&gt;
   289 &lt;/module&gt;
   290         </source>
   291       </subsection>
   292 
   293       <subsection name="Package">
   294         <p>
   295           com.puppycrawl.tools.checkstyle.checks.metrics
   296         </p>
   297       </subsection>
   298 
   299       <subsection name="Parent Module">
   300         <p>
   301           <a href="config.html#treewalker">TreeWalker</a>
   302         </p>
   303       </subsection>
   304     </section>
   305 
   306     <section name="NPathComplexity">
   307       <subsection name="Description">
   308         <p>
   309           The NPATH metric computes the number of possible execution
   310           paths through a function. It takes into account the nesting of
   311           conditional statements and multi-part boolean expressions
   312           (e.g., A &amp;&amp; B, C || D, etc.).
   313         </p>
   314 
   315         <p>
   316           Rationale: Nejmeh says that his group had an informal NPATH
   317           limit of 200 on individual routines; functions that exceeded
   318           this value were candidates for further decomposition - or at
   319           least a closer look.
   320         </p>
   321       </subsection>
   322 
   323       <subsection name="Properties">
   324         <table>
   325           <tr>
   326             <th>name</th>
   327             <th>description</th>
   328             <th>type</th>
   329             <th>default value</th>
   330           </tr>
   331           <tr>
   332             <td>max</td>
   333             <td>the maximum threshold allowed</td>
   334             <td><a href="property_types.html#integer">integer</a></td>
   335             <td><span class="default">200</span></td>
   336           </tr>
   337         </table>
   338       </subsection>
   339 
   340       <subsection name="Examples">
   341         <p>
   342           To configure the check:
   343         </p>
   344         <source>
   345 &lt;module name=&quot;NPathComplexity&quot;/&gt;
   346         </source>
   347 
   348         <p>
   349           To configure the check with a threshold of 20:
   350         </p>
   351         <source>
   352 &lt;module name=&quot;NPathComplexity&quot;&gt;
   353     &lt;property name=&quot;max&quot; value=&quot;20&quot;/&gt;
   354 &lt;/module&gt;
   355         </source>
   356       </subsection>
   357 
   358       <subsection name="Package">
   359         <p>
   360           com.puppycrawl.tools.checkstyle.checks.metrics
   361         </p>
   362       </subsection>
   363 
   364       <subsection name="Parent Module">
   365         <p>
   366           <a href="config.html#treewalker">TreeWalker</a>
   367         </p>
   368       </subsection>
   369     </section>
   370 
   371     <section name="JavaNCSS">
   372       <subsection name="Description">
   373         <p>
   374           Determines complexity of methods, classes and files by
   375           counting the Non Commenting Source Statements (NCSS).  This
   376           check adheres to the <a
   377           href="http://www.kclee.de/clemens/java/javancss/#specification">
   378           specification</a> for the
   379           <a href="http://www.kclee.de/clemens/java/javancss/">JavaNCSS-Tool</a>
   380           written by <b>Chr. Clemens Lee</b>.<br/>
   381           Rougly said the NCSS metric is calculated by
   382           counting the source lines which are not comments, (nearly)
   383           equivalent to counting the semicolons and opening curly
   384           braces.<br/> The NCSS for a class is summarized from the NCSS
   385           of all its methods, the NCSS of its nested classes and the
   386           number of member variable declarations.<br/> The NCSS for a
   387           file is summarized from the ncss of all its top level classes,
   388           the number of imports and the package declaration.
   389         </p>
   390 
   391         <p>
   392           Rationale: Too large methods and classes are hard to read and
   393           costly to maintain. A large NCSS number often means that a
   394           method or class has too many responsabilities and/or
   395           functionalities which should be decomposed into smaller units.
   396         </p>
   397       </subsection>
   398 
   399       <subsection name="Properties">
   400         <table>
   401           <tr>
   402             <th>name</th>
   403             <th>description</th>
   404             <th>type</th>
   405             <th>default value</th>
   406           </tr>
   407           <tr>
   408             <td>methodMaximum</td>
   409             <td>
   410               the maximum allowed number of non commenting lines in a
   411               method.
   412             </td>
   413             <td><a href="property_types.html#integer">integer</a></td>
   414             <td><span class="default">50</span></td>
   415           </tr>
   416           <tr>
   417             <td>classMaximum</td>
   418             <td>
   419               the maximum allowed number of non commenting lines in a
   420               class.
   421             </td>
   422             <td><a href="property_types.html#integer">integer</a></td>
   423             <td><span class="default">1500</span></td>
   424           </tr>
   425           <tr>
   426             <td>fileMaximum</td>
   427             <td>
   428               the maximum allowed number of non commenting lines in a
   429               file including all top level and nested classes.
   430             </td>
   431             <td><a href="property_types.html#integer">integer</a></td>
   432             <td><span class="default">2000</span></td>
   433           </tr>
   434         </table>
   435       </subsection>
   436 
   437       <subsection name="Examples">
   438         <p>
   439           To configure the check:
   440         </p>
   441         <source>
   442 &lt;module name=&quot;JavaNCSS&quot;/&gt;
   443         </source>
   444 
   445         <p>
   446           To configure the check with 40 allowed non commenting lines
   447           for a method:
   448         </p>
   449         <source>
   450 &lt;module name=&quot;JavaNCSS&quot;&gt;
   451     &lt;property name=&quot;methodMaximum&quot; value=&quot;40&quot;/&gt;
   452 &lt;/module&gt;
   453         </source>
   454       </subsection>
   455 
   456       <subsection name="Package">
   457         <p>
   458           com.puppycrawl.tools.checkstyle.checks.metrics
   459         </p>
   460       </subsection>
   461 
   462       <subsection name="Parent Module">
   463         <p>
   464           <a href="config.html#treewalker">TreeWalker</a>
   465         </p>
   466       </subsection>
   467     </section>
   468   </body>
   469 </document>