View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = (default)-1, 0, 1, 2
4   ignoreHashCodeMethod = (default)false
5   ignoreAnnotation = (default)false
6   ignoreFieldDeclaration = true
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 InputMagicNumberIgnoreFieldDeclaration3 {
18  
19      public int hashCode() {
20          return 31; // violation
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 InputMagicNumberIgnoreFieldDeclaration3() {
42          int z=101; // violation
43      }
44  
45      @InputMagicNumberIntMethodAnnotation(42) // violation
46      public void another() {
47      }
48  
49      @InputMagicNumberIntMethodAnnotation(value=43) // violation
50      public void another2() {
51      }
52  
53      @InputMagicNumberIntMethodAnnotation(-44) // violation
54      public void anotherNegative() {
55      }
56  
57      @InputMagicNumberIntMethodAnnotation(value=-45) // violation
58      public void anotherNegative2() {
59      }
60  }
61  
62  class TestMethodCallIgnoreFieldDeclaration3 {
63  
64          public TestMethodCallIgnoreFieldDeclaration3(int x){
65  
66      }
67  
68          public void method2() {
69          final TestMethodCallIgnoreFieldDeclaration3 dummyObject =
70                  new TestMethodCallIgnoreFieldDeclaration3(62);
71          }
72  }
73  
74  class BinaryIgnoreFieldDeclaration3 {
75      int intValue = 0b101;
76      long l = 0b1010000101000101101000010100010110100001010001011010000101000101L;
77  }
78  @interface AnnotationWithDefaultValueIgnoreFieldDeclaration3 {
79      int value() default 101;
80      int[] ar() default {102};
81  }
82  class AIgnoreFieldDeclaration3 {
83      {
84          switch (Blah2IgnoreFieldDeclaration1.LOW) {
85          default:
86              int b = 122; // violation
87          }
88      }
89  }