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

com.puppycrawl.tools.checkstyle.meta.checks.coding.MagicNumberCheck.xml Maven / Gradle / Ivy

Go to download

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

There is a newer version: 10.18.1
Show newest version
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle-metadata>
   <module>
      <check fully-qualified-name="com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck"
             name="MagicNumber"
             parent="com.puppycrawl.tools.checkstyle.TreeWalker">
         <description>&lt;p&gt;
 Checks that there are no
 &lt;a href="https://en.wikipedia.org/wiki/Magic_number_%28programming%29"&gt;
 &amp;quot;magic numbers&amp;quot;&lt;/a&gt; where a magic
 number is a numeric literal that is not defined as a constant.
 By default, -1, 0, 1, and 2 are not considered to be magic numbers.
 &lt;/p&gt;

 &lt;p&gt;Constant definition is any variable/field that has 'final' modifier.
 It is fine to have one constant defining multiple numeric literals within one expression:
 &lt;/p&gt;
 &lt;pre&gt;
 static final int SECONDS_PER_DAY = 24 * 60 * 60;
 static final double SPECIAL_RATIO = 4.0 / 3.0;
 static final double SPECIAL_SUM = 1 + Math.E;
 static final double SPECIAL_DIFFERENCE = 4 - Math.PI;
 static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3);
 static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42);
 &lt;/pre&gt;</description>
         <properties>
            <property default-value="-1, 0, 1, 2" name="ignoreNumbers" type="double[]">
               <description>Specify non-magic numbers.</description>
            </property>
            <property default-value="false" name="ignoreHashCodeMethod" type="boolean">
               <description>Ignore magic numbers in hashCode methods.</description>
            </property>
            <property default-value="false" name="ignoreAnnotation" type="boolean">
               <description>Ignore magic numbers in annotation declarations.</description>
            </property>
            <property default-value="false" name="ignoreFieldDeclaration" type="boolean">
               <description>Ignore magic numbers in field declarations.</description>
            </property>
            <property default-value="true"
                      name="ignoreAnnotationElementDefaults"
                      type="boolean">
               <description>Ignore magic numbers in annotation elements defaults.</description>
            </property>
            <property default-value="TYPECAST,METHOD_CALL,EXPR,ARRAY_INIT,UNARY_MINUS,UNARY_PLUS,ELIST,STAR,ASSIGN,PLUS,MINUS,DIV,LITERAL_NEW"
                      name="constantWaiverParentToken"
                      type="java.lang.String[]"
                      validation-type="tokenTypesSet">
               <description>Specify tokens that are allowed in the AST path
 from the number literal to the enclosing constant definition.</description>
            </property>
            <property default-value="NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG"
                      name="tokens"
                      type="java.lang.String[]"
                      validation-type="tokenSet">
               <description>tokens to check</description>
            </property>
         </properties>
         <message-keys>
            <message-key key="magic.number"/>
         </message-keys>
      </check>
   </module>
</checkstyle-metadata>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy