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 InputMagicNumberWithOperatorsWithIgnoreFieldsTrue {
20  
21      public static final int BIT0 = 1 << 3; // ok, constant field
22      public static final int BIT1 = 1 >> 3;
23      public static final int BIT2 = 1 >>> 3;
24      public static final int BIT3 = 1 | 3;
25      public static final int BIT4 = 1 & 3;
26      public static final int BIT5 = 1 ^ 3;
27      public static final int BIT6 = 1 | 3;
28      public static final int BIT7 = ~3;
29      public static final boolean BIT8 = 1 != 3;
30      public static final boolean BIT9 = 1 > 3;
31      public static final int BIT10 = 1 % 3;
32      public static final int BIT11 = 1 > 3 ? 1 : 3;
33      public static final int BIT12 = 1 % 3;
34  
35      public static int bit0 = 1 << 3; // violation, ''3' is a magic number'
36      public static int bit1 = 1 >> 3; // violation, ''3' is a magic number'
37      public static int bit2 = 1 >>> 3; // violation, ''3' is a magic number'
38      public static int bit3 = 1 | 3; // violation, ''3' is a magic number'
39      public static int bit4 = 1 & 3; // violation, ''3' is a magic number'
40      public static int bit5 = 1 ^ 3; // violation, ''3' is a magic number'
41      public static int bit6 = 1 | 3; // violation, ''3' is a magic number'
42      public static int bit7 = ~3; // violation, ''3' is a magic number'
43  
44      void m1() {
45          final int BIT0 = 1 << 3; // ok, constant variable
46          final int BIT1 = 1 >> 3;
47          final int BIT2 = 1 >>> 3;
48          final int BIT3 = 1 | 3;
49          final int BIT4 = 1 & 3;
50          final int BIT5 = 1 ^ 3;
51          final int BIT6 = 1 | 3;
52          final int BIT7 = ~3;
53  
54          int bit0 = 1 << 3; // violation, ''3' is a magic number'
55          int bit1 = 1 >> 3; // violation, ''3' is a magic number'
56          int bit2 = 1 >>> 3; // violation, ''3' is a magic number'
57          int bit3 = 1 | 3; // violation, ''3' is a magic number'
58          int bit4 = 1 & 3; // violation, ''3' is a magic number'
59          int bit5 = 1 ^ 3; // violation, ''3' is a magic number'
60          int bit6 = 1 | 3; // violation, ''3' is a magic number'
61          int bit7 = ~3; // violation, ''3' is a magic number'
62      }
63  }