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  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  public class InputMagicNumberDefault2 {
18  /**
19   * test long hex
20   */
21      long l = 0xffffffffL; // violation
22  
23  /**
24   * test signed values
25   */
26      public static final int CONST_PLUS_THREE = +3;
27      public static final int CONST_MINUS_TWO = -2;
28      private int mPlusThree = +3; // violation
29      private int mMinusTwo = -2;  // violation
30      private double mPlusDecimal = +3.5; // violation
31      private double mMinusDecimal = -2.5; // violation
32  
33  /**
34   * test octal and hex negative values
35   */
36      private int hexIntMinusOne = 0xffffffff;
37      private long hexLongMinusOne = 0xffffffffffffffffL;
38      private long hexIntMinValue = 0x80000000; // violation
39      private long hexLongMinValue = 0x8000000000000000L; // violation
40      private int octalIntMinusOne = 037777777777;
41      private long octalLongMinusOne = 01777777777777777777777L;
42      private long octalIntMinValue = 020000000000; // violation
43      private long octalLongMinValue = 01000000000000000000000L; // violation
44  
45      public static final int TESTINTVAL = (byte) 0x80;
46  
47      public static final java.util.List MYLIST = new java.util.ArrayList() {
48          public int size() {
49              // should be flagged although technically inside const definition
50              return 378; // violation
51          }
52      };
53  
54      // according to user feedback this is typical code that should not be flagged
55      public final double SpecialSum = 2 + 1e10, SpecialDifference = 4 - java.lang.Math.PI;
56      public final Integer DefaultInit = new Integer(27);
57      public final int SpecsPerDay = 24 * 60 * 60, SpecialRatio = 4 / 3;
58      public final javax.swing.border.Border StdBorder =
59              javax.swing.BorderFactory.createEmptyBorder(3, 3, 3, 3);
60  
61      enum MyEnum2Default2 {
62          A(3),
63          B(54);
64  
65          private MyEnum2Default2(int value) {
66  
67          }
68      }
69  }