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