View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = (default)-1, 0, 1, 2
4   ignoreHashCodeMethod = true
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  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  class InputMagicNumberIgnoreHashCodeMethod3 {
18  
19      public int hashCode() {
20          return 31;
21      }
22  
23  
24      public int hashCode(int val) {
25          return 42; // violation
26      }
27  
28  
29      public int hashcode() {
30          return 13; // violation
31      }
32  
33      static {
34          int x=21; // violation
35      }
36  
37      {
38          int y=37; // violation
39      }
40  
41      public InputMagicNumberIgnoreHashCodeMethod3() {
42          int z=101; // violation
43      }
44  
45      @InputMagicNumberIntMethodAnnotation(42)
46      public void another() {
47      }
48  
49      @InputMagicNumberIntMethodAnnotation(value=43)
50      public void another2() {
51      }
52  
53      @InputMagicNumberIntMethodAnnotation(-44)
54      public void anotherNegative() {
55      }
56  
57      @InputMagicNumberIntMethodAnnotation(value=-45)
58      public void anotherNegative2() {
59      }
60  }
61  
62  class TestMethodCallIgnoreHashCodeMethod3 {
63  
64          public TestMethodCallIgnoreHashCodeMethod3(int x){
65  
66      }
67  
68          public void method2() {
69          final TestMethodCallIgnoreHashCodeMethod3 dummyObject =
70                  new TestMethodCallIgnoreHashCodeMethod3(62);
71          }
72  }
73  
74  class BinaryIgnoreHashCodeMethod3 {
75      int intValue = 0b101; // violation
76      long l = 0b1010000101000101101000010100010110100001010001011010000101000101L; // violation
77  }
78  @interface AnnotationWithDefaultValueIgnoreHashCodeMethod3{
79      int value() default 101;
80      int[] ar() default {102};
81  }
82  class AIgnoreHashCodeMethod3 {
83      {
84          switch (Blah2IgnoreHashCodeMethod1.LOW) {
85          default:
86              int b = 122; // violation
87          }
88      }
89  }