View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = (default)-1, 0, 1, 2
4   ignoreHashCodeMethod = true
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  /**
18   * Describe class InputMagicNumber
19   * @author Rick Giles
20   * @version 6-May-2003
21   */
22  public class InputMagicNumberIgnoreHashCodeMethod1 {
23      public void magicMethod() {
24  
25          final int INT_CONST = 101_000;
26          final long LONG_CONST1 = 100_000L;
27          final long LONG_CONST2 = 100l;
28          final float FLOAT_CONST1 = 1.500_0F;
29          final float FLOAT_CONST2 = 1.5f;
30          final double DOUBLE_CONST1 = 1.500_0D;
31          final double DOUBLE_CONST2 = 1.5d;
32          final double DOUBLE_CONST3 = 1.5;
33  
34  
35          int int_var1 = 1;
36          int int_var2 = (2);
37          long long_var1 = 0L;
38          long long_var2 = 0l;
39          double double_var1 = 0D;
40          double double_var2 = 0d;
41  
42          int[] int_array = new int[2];
43  
44          int_var1 = 1 + 2;
45          int_var1 += 1;
46          double_var1 = 1.0 + 2.0;
47  
48          for (int i = 0; i < 2; i++);
49  
50          if (1 < 2);
51  
52          if (1.0 < 2.0);
53  
54  
55          int int_magic1 = 3_000; // violation
56          double double_magic1 = 1.5_0; // violation
57          int int_magic2 = (3 + 4); // 2 violations
58  
59          int_array = new int[3]; // violation
60  
61          int_magic1 += 3; // violation
62          double_magic1 *= 1.5; // violation
63  
64          for (int j = 3; j < 5; j += 3) { // 3 violations
65              int_magic1++;
66          }
67  
68          if (int_magic1 < 3) { // violation
69              int_magic1 = int_magic1 + 3; // violation
70          }
71  
72  
73          int octalVar0 = 00;
74          int octalVar8 = 010; // violation
75          int octalVar9 = 011; // violation
76  
77          long longOctalVar8 = 0_10L; // violation
78          long longOctalVar9 = 011l; // violation
79  
80  
81          int hexVar0 = 0x0;
82          int hexVar16 = 0x10; // violation
83          int hexVar17 = 0X011;  // violation
84          long longHexVar0 = 0x0L;
85          long longHexVar16 = 0x10L;  // violation
86          long longHexVar17 = 0X11l; // violation
87      }
88  }
89  
90  interface Blah2IgnoreHashCodeMethod1
91  {
92    int LOW = 5;
93    int HIGH = 78;
94  }
95  
96  class ArrayMagicTestIgnoreHashCodeMethod1
97  {
98      private static final int[] NONMAGIC = {3};
99      private int[] magic = {3}; // violation
100     private static final int[][] NONMAGIC2 = {{1}, {2}, {3}};
101 }