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