View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = (default)-1, 0, 1, 2
4   ignoreHashCodeMethod = (default)false
5   ignoreAnnotation = (default)false
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                              SR, BSR, SL, BXOR, BOR, BAND, BNOT, QUESTION, COLON, EQUAL, NOT_EQUAL, \
11                              GE, GT, LE, LT, MOD
12  tokens = (default)NUM_DOUBLE, NUM_FLOAT, NUM_INT, NUM_LONG
13  
14  
15  */
16  
17  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
18  
19  public class InputMagicNumberDefault2 {
20  /**
21   * test long hex
22   */
23      long l = 0xffffffffL; // violation
24  
25  /**
26   * test signed values
27   */
28      public static final int CONST_PLUS_THREE = +3;
29      public static final int CONST_MINUS_TWO = -2;
30      private int mPlusThree = +3; // violation
31      private int mMinusTwo = -2;  // violation
32      private double mPlusDecimal = +3.5; // violation
33      private double mMinusDecimal = -2.5; // violation
34  
35  /**
36   * test octal and hex negative values
37   */
38      private int hexIntMinusOne = 0xffffffff;
39      private long hexLongMinusOne = 0xffffffffffffffffL;
40      private long hexIntMinValue = 0x80000000; // violation
41      private long hexLongMinValue = 0x8000000000000000L; // violation
42      private int octalIntMinusOne = 037777777777;
43      private long octalLongMinusOne = 01777777777777777777777L;
44      private long octalIntMinValue = 020000000000; // violation
45      private long octalLongMinValue = 01000000000000000000000L; // violation
46  
47      public static final int TESTINTVAL = (byte) 0x80;
48  
49      public static final java.util.List MYLIST = new java.util.ArrayList() {
50          public int size() {
51              // should be flagged although technically inside const definition
52              return 378; // violation
53          }
54      };
55  
56      // according to user feedback this is typical code that should not be flagged
57      public final double SpecialSum = 2 + 1e10, SpecialDifference = 4 - java.lang.Math.PI;
58      public final Integer DefaultInit = new Integer(27);
59      public final int SpecsPerDay = 24 * 60 * 60, SpecialRatio = 4 / 3;
60      public final javax.swing.border.Border StdBorder =
61              javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3);
62  
63      enum MyEnum2Default2 {
64          A(3),
65          B(54);
66  
67          private MyEnum2Default2(int value) {
68  
69          }
70      }
71  }