All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.puppycrawl.tools.checkstyle.meta.checks.metrics.CyclomaticComplexityCheck.xml Maven / Gradle / Ivy

Go to download

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard

The newest version!
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle-metadata>
   <module>
      <check fully-qualified-name="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck"
             name="CyclomaticComplexity"
             parent="com.puppycrawl.tools.checkstyle.TreeWalker">
         <description>&lt;div&gt;
 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 about quality of code! It is only
 applied to methods, c-tors,
 &lt;a href="https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html"&gt;
 static initializers and instance initializers&lt;/a&gt;.
 &lt;/div&gt;

 &lt;p&gt;
 The complexity is equal to the number of decision points {@code + 1}.
 Decision points:
 &lt;/p&gt;
 &lt;ul&gt;
 &lt;li&gt;
 {@code if}, {@code while}, {@code do}, {@code for},
 {@code ?:}, {@code catch}, {@code switch}, {@code case} statements.
 &lt;/li&gt;
 &lt;li&gt;
  Operators {@code &amp;amp;&amp;amp;} and {@code ||} in the body of target.
 &lt;/li&gt;
 &lt;li&gt;
  {@code when} expression in case labels, also known as guards.
 &lt;/li&gt;
 &lt;/ul&gt;

 &lt;p&gt;
 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.
 &lt;/p&gt;

 &lt;p&gt;
 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.
 &lt;/p&gt;

 &lt;p&gt;
 Please use Suppression to avoid violations on cases that could not be split
 in few methods without damaging readability of code or encapsulation.
 &lt;/p&gt;</description>
         <properties>
            <property default-value="10" name="max" type="int">
               <description>Specify the maximum threshold allowed.</description>
            </property>
            <property default-value="false"
                      name="switchBlockAsSingleDecisionPoint"
                      type="boolean">
               <description>Control whether to treat
 the whole switch block as a single decision point.</description>
            </property>
            <property default-value="LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_CASE,LITERAL_CATCH,QUESTION,LAND,LOR,LITERAL_WHEN"
                      name="tokens"
                      type="java.lang.String[]"
                      validation-type="tokenSet">
               <description>tokens to check</description>
            </property>
         </properties>
         <message-keys>
            <message-key key="cyclomaticComplexity"/>
         </message-keys>
      </check>
   </module>
</checkstyle-metadata>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy