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