View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = -9223372036854775808, -2147483648, -1, 0, 1, 2, -2
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                              SR, BSR, SL, BXOR, BOR, BAND, BNOT, QUESTION, COLON, EQUAL, NOT_EQUAL, \
11                              GE, GT, LE, LT, MOD
12  tokens = NUM_INT, NUM_LONG
13  
14  
15  */
16  
17  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
18  
19  class InputMagicNumberIgnoreNegativeOctalHex3 {
20  
21      public int hashCode() {
22          return 31; // violation
23      }
24  
25  
26      public int hashCode(int val) {
27          return 42; // violation
28      }
29  
30  
31      public int hashcode() {
32          return 13; // violation
33      }
34  
35      static {
36          int x=21; // violation
37      }
38  
39      {
40          int y=37; // violation
41      }
42  
43      public InputMagicNumberIgnoreNegativeOctalHex3() {
44          int z=101; // violation
45      }
46  
47      @InputMagicNumberIntMethodAnnotation(42)
48      public void another() {
49      }
50  
51      @InputMagicNumberIntMethodAnnotation(value=43)
52      public void another2() {
53      }
54  
55      @InputMagicNumberIntMethodAnnotation(-44)
56      public void anotherNegative() {
57      }
58  
59      @InputMagicNumberIntMethodAnnotation(value=-45)
60      public void anotherNegative2() {
61      }
62  }
63  
64  class TestMethodCallIgnoreNegativeOctalHex3 {
65  
66          public TestMethodCallIgnoreNegativeOctalHex3(int x){
67  
68      }
69  
70          public void method2() {
71          final TestMethodCallIgnoreNegativeOctalHex3 dummyObject =
72                  new TestMethodCallIgnoreNegativeOctalHex3(62);
73          }
74  }
75  
76  class BinaryIgnoreNegativeOctalHex3 {
77      int intValue = 0b101; // violation
78      long l = 0b1010000101000101101000010100010110100001010001011010000101000101L; // violation
79  }
80  @interface AnnotationWithDefaultValueIgnoreNegativeOctalHex3 {
81      int value() default 101;
82      int[] ar() default {102};
83  }
84  class AIgnoreNegativeOctalHex3 {
85      {
86          switch (Blah2IgnoreNegativeOctalHex1.LOW) {
87          default:
88              int b = 122; // violation
89          }
90      }
91  }