View Javadoc
1   package com.puppycrawl.tools.checkstyle.grammars;
2   
3   import static java.lang.String.valueOf;
4   
5   import java.io.BufferedReader;
6   import java.io.FileNotFoundException;
7   import java.io.IOException;
8   import java.io.InputStreamReader;
9   import java.util.ArrayList;
10  import java.util.HashMap;
11  import java.util.Iterator;
12  import java.util.List;
13  import java.util.Map;
14  
15  import javax.xml.*;
16  
17  public class InputRegressionJavaClass1 {
18      //comments
19  
20      // single line
21      /* multi on single line */
22      /* multi
23       line */
24      /** javadoc */
25      // tab ->	<-
26  
27      // fields
28      // modifiers
29      public int f1;
30      private int f2;
31      protected int f3;
32      int f4;
33      static int f5;
34      final int f6;
35      volatile int f7;
36      transient int f8;
37      Object f9;
38  
39      // constructors
40      static {}
41      public InputRegressionJavaClass1() {f6 = 0;}
42      public InputRegressionJavaClass1(int i) {this.f6 = i;}
43      public InputRegressionJavaClass1(float f) {this((int)f);}
44      InputRegressionJavaClass1(double a) throws Exception {f6 = 0;}
45  
46      // methods
47      // modifiers
48      native void m1();
49      void m2() {}
50      synchronized void m4() {}
51      strictfp void m5() {}    
52      
53      // returns
54      public int[] m6() {return null;}
55      public int m7() [] {return null;}
56  
57      // parameters
58      public void m10(String p1) {}
59      public void m11(final String p1) {}
60      public void m12(String[] p1) {}
61      public void m13(String[][] p1) {}
62      public void m14(String p1, String p2) {}
63      public void m15(String... p1) {}
64      public void m16(String[]... p1) {}
65      public void m17(int p1, String[]... p2) {}
66  
67      // throws
68      public void m18() throws Exception {}
69      public void m19() throws IOException, Exception {}
70  
71      // types
72      public <T_$> T_$ m20() {return null;}
73      public <$_T> $_T m21() {return null;}
74      public <T extends Enum<T>> void m22() {}
75      public <T> void m23() {};
76      public <T extends RuntimeException & java.io.Serializable> void m24() {}
77      
78      // annotations
79      @SuppressWarnings({})
80      public void m50() {}
81      @SuppressWarnings({"1"})
82      public void m51() {}
83      @SuppressWarnings({"1","2"})
84      public void m52() {}
85      @SuppressWarnings(value={"1"})
86      public void m53() {}
87      @SuppressWarnings(value={"1",})
88      public void m54() {}
89      @SuppressWarnings(value={"1","2"})
90      public void m55() {}
91      @InputRegressionJavaAnnotation1(m1="1", m2="2")
92      public void m56() {}
93      @ComplexAnnotation({
94              @InputRegressionJavaAnnotation1(m1 = "1"), @InputRegressionJavaAnnotation1(m1 = "1")
95      })
96      public void m57() {}
97      public void m58(@Deprecated String s) {}
98      public void m59(final @Deprecated List l) {}
99  
100     // extra
101     {}
102     ;
103 
104     // instructions
105     public void instructions() throws Exception {
106         // used to let inputs compile
107         boolean b = Math.random() > 0;
108 
109         // variables and types
110         byte vbyte;
111         boolean vboolean;
112         char vchar;
113         short vshort;
114         int vint;
115         long vlong;
116         float vfloat;
117         double vdouble;
118         int[] varray;
119         int varray2[];
120         boolean test1 = true;
121 
122         // types
123         String vstring;
124         List<String> vlist;
125         Map<String, String[]> vmap;
126         int[] test2 = {};
127         List<char[]> test3;
128         Class<?> test4;
129         List<? extends InputRegressionJavaClass1> test5;
130         List<? extends List<Object>> test6;
131         List<? extends List<List<Object>>> test7;
132         List<? extends int[]> test8;
133         List<? super InputRegressionJavaClass1> test9;
134 
135         // literals
136         vboolean = true;
137         vboolean = false;
138         vchar = ' ';
139         vchar = '"';
140         vchar = '\0';
141         vchar = '\'';
142         vchar = '\n';
143         vchar = '\r';
144         vchar = '\t';
145         vchar = '\b';
146         vchar = '\f';
147         vchar = '\"';
148         vchar = '\'';
149         vchar = '\\';
150         vchar = '\00';
151         vchar = '\013';
152         vchar = '\4';
153         vchar = '\40';
154         vchar = '\u0000';
155         vchar = '\u1234';
156         vchar = '\u005C\u005C';
157         vchar = '\u005c\u005c';
158         vchar = '\uu005C\uuuuu005C';
159         vchar = '\u005cn';
160         vchar = '\u005cr';
161         vchar = '\u005ct';
162         vchar = '\u005cb';
163         vchar = '\u005cf';
164         vchar = '\u005c"';
165         vchar = '\u005c'';
166         vchar = '\u005c\';
167         vint = 0;
168         vint = -1;
169         vint = +1;
170         vint = 100_000;
171         vint = 0x00;
172         vint = 0x12345678;
173         vint = 0X9;
174         vint = 0x1234_5678;
175         vint = 0b101;
176         vint = 0B101;
177         vint = 0b1;
178         vint = 0b1_0;
179         vint = 012345670;
180         vint = 01234_5670;
181         vlong = 0L;
182         vlong = 1L;
183         vlong = 0b1L;
184         vlong = 1234567890l;
185         vlong = 1234567890L;
186         vlong = 0x0l;
187         vlong = 0xABCDEFl;
188         vlong = 0XABCDEFL;
189         vfloat = 0f;
190         vfloat = 0F;
191         vfloat = 1.1f;
192         vfloat = 1.10_1F;
193         vfloat = 0_1.1_1F;
194         vfloat = 1e0f;
195         vfloat = 1e0F;
196         vfloat = 1.0e0F;
197         vfloat = 0x2__3_34.4___AFP00_00f;
198         vdouble = 10.;
199         vdouble = .1;
200         vdouble = .1__1_1;
201         vdouble = 0.0;
202         vdouble = 1000.0;
203         vdouble = .1d;
204         vdouble = 1.D;
205         vdouble = 0_1.0d;
206         vdouble = 0_1.0D;
207         vdouble = 4e23;
208         vdouble = 4E23;
209         vdouble = 4E2_3;
210         vdouble = 0x0.0000000000001p-1022;
211         vdouble = 0x0.0000000000001P-1022;
212         vdouble = 0X0.0000000000001p+1022;
213         vdouble = 0X0.0000000000001P+1022;
214         vdouble = 0x.0P0;
215         vdouble = 0X0p+2;
216         vdouble = 0X0p+20F;
217         vdouble = 0X0p+2D;
218         vdouble = 0X0p+2d;
219         vdouble = 0x1.P-1;
220         vdouble = 0x.1___AFp1;
221         vstring = null;
222         vstring = "";
223         vstring = "\\";
224         
225         // assignments and operators
226         vint = 1 + 1;
227         vint = 1 - 1;
228         vint = 1 * 1;
229         vint = 1 / 1;
230         vint = 1 % 1;
231         vint = 1 & 1;
232         vint = 1 | 1;
233         vint = 1 ^ 1;
234         vint = ~1;
235         vboolean = 1 != 0;
236         vboolean = 1 == 0;
237         vboolean = 1 > 0;
238         vboolean = 1 >= 0;
239         vboolean = 1 < 0;
240         vboolean = 1 <= 0;
241         vboolean = true && true;
242         vboolean = true || true;
243         vboolean = true ? true : false;
244         vboolean = !true;
245         vboolean = f9 instanceof Object;
246         vint = 1 << 1;
247         vint = 1 >> 1;
248         vint = 1 >>> 1;
249         vint += 1;
250         vint -= 1;
251         vint *= 1;
252         vint /= 1;
253         vint %= 1;
254         vint &= 1;
255         vint |= 1;
256         vint ^= 1;
257         vint <<= 1;
258         vint >>= 1;
259         vint >>>= 1;
260         vint++;
261         vint--;
262         ++vint;
263         --vint;
264         String[] arrayinit = {};
265         String[] arrayinit2 = {""};
266         String[] arrayinit3 = {"", "",};
267         
268         // new
269         varray = new int[]{};
270         varray = new int[]{0};
271         varray = new int[]{0, 1};
272         varray = new int[5];
273         vlist = new ArrayList<String>();
274         vmap = new HashMap<String, String[]>();
275         Object anonymous = new InputRegressionJavaClass1() {};
276 
277         // stataments
278         ;
279         this.f1 = 0;
280         
281         // labels
282         test_label1:
283 
284         // blocks
285         {}
286         if (true) ;
287         if (true) {}
288         if (true) {} else ;
289         if (true) {} else {}
290         if (b) { for (;;) ; }
291         if (b) { for (;;) {} }
292         for (int i = 0; i < 1; i++) {}
293         for (int i = 0, j = 0; i < 1; i++, j += 2) {}
294         for (int value: new int[]{}) ;
295         for (String s : new String[]{}) ;
296         for (final String s : new String[]{}) ;
297         if (b) { while (true) ; }
298         if (b) { while (true) {} }
299         do {} while (false);
300         synchronized (f9) {}
301         
302         switch (0) {
303             case 1:
304             case 0: break;
305             default: break;
306         }
307 
308         try {
309             if (b) { throw new IOException(); }
310             if (b) { throw new ArrayIndexOutOfBoundsException(); }
311             throw new Exception();
312         } catch (IOException | ArrayIndexOutOfBoundsException e) {
313         } catch (Exception e) {
314         } finally {}
315         try (BufferedReader br = new BufferedReader(new InputStreamReader(null, "utf-8"))) {}
316         try (BufferedReader br1 = new BufferedReader(new InputStreamReader(null, "utf-8"));
317                 BufferedReader br2 = new BufferedReader(new InputStreamReader(null, "utf-8"));) {}
318         
319         // access
320         test4 = InputRegressionJavaClass1.class;
321         test4 = List[].class;
322         test4 = boolean[].class;
323         varray[0] = 0;
324         for (String[] s : new String[][]{{}}) ;
325         for (Map.Entry<String, String[]> e : vmap.entrySet()) { }
326 
327         // others
328         for (;;) {break;}
329         test_label2:
330         for (;;) {break test_label2;}
331         if (b) { for (;;) {continue;} }
332         if (b) { test_label3: for (;;) {continue test_label3;} }
333         if (false) return;
334         if (false) throw new Exception();
335         assert(false);
336         assert true : "false";
337         f9 = (Object) f9;
338         f9.equals(((vstring = "")));
339         for (int i = 0; ((i) < (6+6)); i++) ;
340         if ((b & b)) {}
341         
342         // ast error handling
343         vint = vboolean ? (vint = 1) : (vint = 0);
344         varray[vint] = Integer.parseInt("0");
345     }
346 
347     public @interface innerAnnotation {}
348 }