View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = (default)-1, 0, 1, 2
4   ignoreHashCodeMethod = (default)false
5   ignoreAnnotation = true
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 = NUM_DOUBLE, NUM_FLOAT, NUM_INT
11  
12  
13  */
14  
15  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
16  
17  import java.util.ArrayList;
18  import java.util.HashSet;
19  import java.util.List;
20  import java.util.Set;
21  
22  public class InputMagicNumberMagicNumber2 {
23      {
24          int a = 0;
25          int b = 9; // violation ''9' is a magic number'
26          double e = 0;
27          double c = 5.5; // violation ''5.5' is a magic number'
28          float d = 12.2f; // violation ''12.2f' is a magic number'
29      }
30  
31      void foo(){
32          {
33              int notField = 45; // violation ''45' is a magic number'
34              int notField2 = 1;
35          }
36      }
37  
38      void foo2() {
39          {
40              int a = 0;
41              int b = 9; // violation ''9' is a magic number'
42              double e = 0;
43              double c = 5.5; // violation ''5.5' is a magic number'
44              float d = 12.2f; // violation ''12.2f' is a magic number'
45          }
46      }
47  
48      {
49          Set<Person> p1 = new HashSet<Person>(5); // violation ''5' is a magic number'
50          Object[] values = new Object[5]; // violation ''5' is a magic number'
51          String[] fStrings = new String[5]; // violation ''5' is a magic number'
52          Person p = new Person(5); // violation ''5' is a magic number'
53          List<Integer> multisets = new ArrayList(5); // violation ''5' is a magic number'
54      }
55  
56      {
57          Set<Person> p1 = new HashSet<Person>(1);
58          Object[] values = new Object[1];
59          String[] fStrings = new String[1];
60          Person p = new Person(1);
61          List<Integer> multisets = new ArrayList(1);
62      }
63  
64      void method() {
65          {
66              Set<Person> p1 = new HashSet<Person>(5); // violation ''5' is a magic number'
67              Object[] values = new Object[5]; // violation ''5' is a magic number'
68              String[] fStrings = new String[5]; // violation ''5' is a magic number'
69              Person p = new Person(5); // violation ''5' is a magic number'
70              List<Integer> multisets = new ArrayList(5); // violation ''5' is a magic number'
71          }
72  
73          {
74              Set<Person> p1 = new HashSet<Person>(1);
75              Object[] values = new Object[1];
76              String[] fStrings = new String[1];
77              Person p = new Person(1);
78              List<Integer> multisets = new ArrayList(1);
79          }
80      }
81  }