View Javadoc
1   /*
2   ExplicitInitialization
3   onlyObjectReferences = true
4   
5   
6   */
7   
8   package com.puppycrawl.tools.checkstyle.checks.coding.explicitinitialization;
9   
10  public class InputExplicitInitializationOnlyObjectReference {
11      private int x = 0;
12      private Object bar = /* comment test */null; // violation
13      private int y = 1;
14      private long y1 = 1 - 1;
15      private long y3;
16      private long y4 = 0L;
17      private boolean b1 = false;
18      private boolean b2 = true;
19      private boolean b3;
20      private String str = "";
21      java.lang.String str1 = null, str3 = null; // 2 violations
22      int ar1[] = null; // violation
23      int ar2[] = new int[1];
24      int ar3[];
25      float f1 = 0f;
26      double d1 = 0.0;
27  
28      static char ch;
29      static char ch1 = 0;
30      static char ch2 = '\0';
31      static char ch3 = '\1';
32  
33      void method() {
34          int xx = 0;
35          String s = null;
36      }
37  }
38  
39  interface interface2 {
40      int TOKEN_first = 0x00;
41      int TOKEN_second = 0x01;
42      int TOKEN_third = 0x02;
43  }
44  
45  class InputExplicitInit4 {
46      private Bar<String> bar = null; // violation
47      private Bar<String>[] barArray = null; // violation
48  }
49  
50  enum InputExplicitInit5 {
51      A,
52      B
53      {
54          private int x = 0;
55          private Bar<String> bar = null; // violation
56          private Bar<String>[] barArray = null; // violation
57          private int y = 1;
58      };
59      private int x = 0;
60      private Bar<String> bar = null; // violation
61      private Bar<String>[] barArray = null; // violation
62      private int y = 1;
63      private Boolean booleanAtt = false;
64  }
65  
66  @interface annotation2{
67      int TOKEN_first = 0x00;
68      int TOKEN_second = 0x01;
69      int TOKEN_third = 0x02;
70  }
71  
72  class ForEach1 {
73      public ForEach1(java.util.Collection<String> strings)
74      {
75          for(String s : strings) //this should not even be checked
76          {
77  
78          }
79      }
80  }
81  
82  class Bar1<T> {
83  }
84  
85  class Chars1 {
86      char a;
87      char b = a;
88      byte c = 1;
89      short d = 1;
90      final long e = 0;
91  }
92  
93  class Doubles1 {
94      final double subZero = -0.0;
95      final double nan = Double.NaN;
96      private short shortVariable = 0;
97      private byte bite = 0;
98      double d = 0d;
99  }