View Javadoc
1   /*xml
2   <module name="Checker">
3     <module name="TreeWalker">
4       <module name="MagicNumber">
5           <property name="ignoreHashCodeMethod" value="true"/>
6       </module>
7     </module>
8   </module>
9   */
10  
11  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
12  
13  // xdoc section -- start
14  @Example6.Annotation(6) // violation, ''6' is a magic number.'
15  public class Example6 {
16    private int field = 7; // violation, ''7' is a magic number.'
17  
18    void method1() {
19      int i = 1;
20      int j = 8; // violation, ''8' is a magic number.'
21    }
22    public void method2() {
23      final TestClass testObject = new TestClass(62);
24      final int a = 3;
25      final int[] b = {4, 5};
26      final int c = -3;
27      final int d = +4;
28      final int e = method3(10, 20);
29      final int f = 3 * 4;
30      final int g = 3 / 4;
31      final int h = 3 + 4;
32      final int i = 3 - 4;
33      final int j = (int) 3.4;
34    }
35    private int method3(int a, int b) {
36      return a + b;
37    }
38    public int hashCode() {
39      return 10;
40    }
41    @interface Annotation {
42      int value() default 10;
43      int[] value2() default {10};
44    }
45    class TestClass {
46      TestClass(int field) {}
47    }
48  }
49  // xdoc section -- end