View Javadoc
1   /*
2   MagicNumber
3   ignoreNumbers = -2, -1, 0, 1, 2, 100
4   ignoreHashCodeMethod = true
5   ignoreFieldDeclaration = (default)false
6   constantWaiverParentToken = ARRAY_INIT, ASSIGN, ELIST, EXPR
7   
8   */
9   
10  package com.puppycrawl.tools.checkstyle.checks.coding.magicnumber;
11  
12  import java.time.OffsetDateTime;
13  import java.time.ZoneOffset;
14  
15  public class InputMagicNumberIgnoreFieldDeclaration5 {
16      public final int radius = 10;
17      public final double area = 22 / 7.0 * radius * radius;
18      // 2 violations above:
19      //                    ''22' is a magic number'
20      //                    ''7.0' is a magic number'
21      public final int a[] = {4, 5};
22  
23      public int x = 10; // violation ''10' is a magic number'
24      public int y = 10 * 20;
25      // 2 violations above:
26      //                    ''10' is a magic number'
27      //                    ''20' is a magic number'
28      public static int[] z = {4, 5, 6, 7};
29      // 4 violations above:
30      //                    ''4' is a magic number'
31      //                    ''5' is a magic number'
32      //                    ''6' is a magic number'
33      //                    ''7' is a magic number'
34      private static final String TEST_TIME =
35         OffsetDateTime.of(2023, 11, 11, 11,
36         // 4 violations above:
37         //                    ''2023' is a magic number'
38         //                    ''11' is a magic number'
39         //                    ''11' is a magic number'
40         //                    ''11' is a magic number'
41  
42                 11, 11, 11, ZoneOffset.of("Z")).toString();
43                 // 3 violations above:
44                 //                    ''11' is a magic number'
45                 //                    ''11' is a magic number'
46                 //                    ''11' is a magic number'
47  
48      public static int OFFSETOF_NAME = z[3]; // violation ''3' is a magic number'
49      public static Object[] STABLE_OBJECT_ARRAY = new Object[4];
50      // 1 violations above:
51      //                   ''4' is a magic number'
52  }