View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers =
4   ignoreHashCodeMethod = (default)false
5   ignoreAnnotation = true
6   ignoreFieldDeclaration = (default)false
7   ignoreAnnotationElementDefaults = (default)true
8   constantWaiverParentToken = (default)TYPECAST, METHOD_CALL, EXPR, ARRAY_INIT, UNARY_MINUS, \
9                               UNARY_PLUS, ELIST, STAR, ASSIGN, PLUS, MINUS, DIV, LITERAL_NEW
10  tokens = (default)NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG
11  
12  
13  */
14  
15  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
16  
17  /* Config:
18   *
19   * ignoreNumbers ={}
20   * ignoreAnnotation =  true
21   */
22  
23  /**
24   * Describe class InputMagicNumber
25   * @author Rick Giles
26   * @version 6-May-2003
27   */
28  public class InputMagicNumberIgnoreNone1 {
29      public void magicMethod() {
30  
31          final int INT_CONST = 101_000;
32          final long LONG_CONST1 = 100_000L;
33          final long LONG_CONST2 = 100l;
34          final float FLOAT_CONST1 = 1.500_0F;
35          final float FLOAT_CONST2 = 1.5f;
36          final double DOUBLE_CONST1 = 1.500_0D;
37          final double DOUBLE_CONST2 = 1.5d;
38          final double DOUBLE_CONST3 = 1.5;
39  
40  
41          int int_var1 = 1; // violation
42          int int_var2 = (2); // violation
43          long long_var1 = 0L; // violation
44          long long_var2 = 0l; // violation
45          double double_var1 = 0D; // violation
46          double double_var2 = 0d; // violation
47  
48          int[] int_array = new int[2]; // violation
49  
50          int_var1 = 1 + 2; // 2 violations
51          int_var1 += 1;  // violation
52          double_var1 = 1.0 + 2.0; // 2 violations
53  
54          for (int i = 0; i < 2; i++); // 2 violations
55  
56          if (1 < 2); // 2 violations
57  
58          if (1.0 < 2.0); // 2 violations
59  
60  
61          int int_magic1 = 3_000; // violation
62          double double_magic1 = 1.5_0; // violation
63          int int_magic2 = (3 + 4); // 2 violations
64  
65          int_array = new int[3]; // violation
66  
67          int_magic1 += 3; // violation
68          double_magic1 *= 1.5; // violation
69  
70          for (int j = 3; j < 5; j += 3) { // 3 violations
71              int_magic1++;
72          }
73  
74          if (int_magic1 < 3) { // violation
75              int_magic1 = int_magic1 + 3; // violation
76          }
77  
78  
79          int octalVar0 = 00;  // violation
80          int octalVar8 = 010; // violation
81          int octalVar9 = 011; // violation
82  
83          long longOctalVar8 = 0_10L; // violation
84          long longOctalVar9 = 011l; // violation
85  
86  
87          int hexVar0 = 0x0; // violation
88          int hexVar16 = 0x10; // violation
89          int hexVar17 = 0X011;  // violation
90          long longHexVar0 = 0x0L; // violation
91          long longHexVar16 = 0x10L; // violation
92          long longHexVar17 = 0X11l; // violation
93      }
94  }
95  
96  interface Blah2IgnoreNone1
97  {
98    int LOW = 5;
99    int HIGH = 78;
100 }
101 
102 class ArrayMagicTestIgnoreNone1
103 {
104     private static final int[] NONMAGIC = {3};
105     private int[] magic = {3}; // violation
106     private static final int[][] NONMAGIC2 = {{1}, {2}, {3}};
107 }