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