1 package japa.bdd.samples; 2 3 import com.github.javaparser.JavaParser; 4 import japa.parser.ParseException; 5 import com.github.javaparser.ast.CompilationUnit; 6 import org.junit.Ignore; 7 8 import java.io.*; 9 import java.util.*; 10 11 @Ignore 12 @Deprecated 13 public class JavaConcepts<T extends List<int[]>, X> extends Base implements Serializable { 14 15 static Class clz1 = String.class; 16 17 protected Class clz2 = (String.class); 18 19 Class clz3 = int.class; 20 21 Class clz4 = (int.class); 22 23 int[] arr = new int[10]; 24 25 byte bye = 0; 26 27 byte byebye[] = null; 28 29 short sh1, sh2 = 1; 30 31 int intWithUnderscore = 1234_5678; 32 33 long longWithUnderscore = 1234_5678L; 34 35 float floatWithUnderscore = 1_234.5_678f; 36 37 float floatWithUnderscoreAndExponent = 1_234e1_0f; 38 39 double doubleWithUnderscore = 1_234.5_678; 40 41 double doubleWithUnderscoreAndExponent = 1_234e1_0; 42 43 int binaryLiteral = 0b101101; 44 45 List<String>[][] arrLS = (List<String>[][]) new List<?>[10][]; 46 47 { 48 int z = 0, y = 0; 49 int a = (z) + y; 50 a = (+z) + y; 51 byte b = (byte) +y; 52 } 53 54 List<String> diamond1 = new LinkedList<>(); 55 56 @Deprecated() 57 static class Ugly { 58 59 static int x = 0; 60 61 public static void main(String[] args) { 62 x = +x; 63 x = ~x; 64 --x; 65 boolean b = !false; 66 x &= 2; 67 x |= 2; 68 x ^= 2; 69 x -= 2; 70 x %= 2; 71 x /= 2; 72 x *= 2; 73 x <<= 2; 74 x >>= 2; 75 x >>>= 2; 76 b = b || false; 77 b = b | false; 78 b = b & false; 79 b = b ^ false; 80 b = b != false; 81 b = x > 1; 82 b = x < 1; 83 b = x >= 1; 84 b = x <= 1; 85 x = x << 1; 86 x = x >> 1; 87 x = x >>> 1; 88 x = x - 1; 89 x = x * 1; 90 x = x % 1; 91 x = x / 1; 92 } 93 } 94 95 @Deprecated() 96 int[][][][] arr2 = new int[10][2][1][0]; 97 98 volatile float fff = 0x1.fffeP+127f; 99 100 char cc = 'a'; 101 102 int[][] arr3 = {{1, 2}, {3, 4}}; 103 104 static int[] arr4[] = {}; 105 106 public static JavaConcepts t; 107 108 static { 109 arr4 = new int[][]{{2}, {1}}; 110 } 111 112 { 113 arr3 = new int[][]{{2}, {1}}; 114 } 115 116 public enum Teste { 117 118 asc, def 119 } 120 121 public enum Sexo { 122 123 m, @Deprecated 124 f; 125 126 public enum Sexo_ implements Serializable, Cloneable { 127 } 128 129 private Sexo() { 130 } 131 } 132 133 @Deprecated 134 public enum Enum { 135 136 m(1) { 137 @Override 138 void mm() { 139 } 140 }, f(2) { 141 void mm() { 142 } 143 }; 144 145 native void nnn(); 146 147 transient int x; 148 149 private Enum(int x) { 150 this.x = x; 151 } 152 153 abstract void mm(); 154 } 155 156 strictfp double ddd() { 157 return 0.0; 158 } 159 160 public <T, E> JavaConcepts(int x) { 161 this.arr[0] = x; 162 T val1 = null; 163 E val2 = null; 164 super.<T, E>check2(val1, val2); 165 boolean b = true, y = false; 166 abstract class X { 167 168 int i = 0; 169 170 public <D> X() { 171 } 172 173 public void m() { 174 } 175 } 176 @Deprecated 177 final class Y extends X { 178 179 public Y() { 180 super(); 181 JavaConcepts.this.cc = 'c'; 182 super.i = 1; 183 Y.super.m(); 184 } 185 186 public Y(int y) { 187 super(); 188 } 189 190 public Y(long x) { 191 this(); 192 } 193 } 194 } 195 196 public <T> JavaConcepts(String str) { 197 } 198 199 private class QWE extends JavaConcepts<List<int[]>, String> { 200 201 @Deprecated 202 final int z = 0; 203 204 int i = (int) -1; 205 206 public QWE(String... x) { 207 <String>super(x[0]); 208 } 209 210 public QWE(int... x) { 211 super(x[0]); 212 i = x[0]; 213 assert true; 214 assert 1 == 1 : 2; 215 { 216 int iii = 3; 217 iii += 3; 218 } 219 label: 220 { 221 int iii = 1; 222 } 223 ; 224 ; 225 int min = -2147483648; 226 long sl = 123123123123l; 227 long minl = -9223372036854775808L; 228 switch (i) { 229 } 230 ll: 231 switch (i) { 232 case 1: 233 System.out.println(1); 234 break ll; 235 default: { 236 System.out.println("default"); 237 break; 238 } 239 case 2: 240 if (t instanceof Base) { 241 System.out.println(1); 242 } 243 i++; 244 ++i; 245 } 246 } 247 248 private synchronized int doSomething()[] { 249 List<? extends Number> x = new ArrayList<Integer>(); 250 return new int[]{1}; 251 } 252 } 253 254 public static void main(String[] args) throws ParseException, IOException { 255 int x = 2; 256 CompilationUnit cu = parse(new File("src/japa/parser/javacc/Parser.java")); 257 System.out.println(cu); 258 JavaConcepts teste = new JavaConcepts(2); 259 JavaConcepts.QWE qwe = teste.new QWE(1); 260 if (1 + 1 == 2) { 261 teste = null; 262 teste = new JavaConcepts(1); 263 } else { 264 x = 3; 265 teste = new JavaConcepts(1); 266 x = x == 0 ? 2 : 4; 267 } 268 if (true) 269 x = 1; 270 else 271 x = 3; 272 if (true) 273 x = 1; 274 else if (false) 275 x = 3; 276 else 277 x = 2; 278 while (true) { 279 xxx: 280 while (x == 3) continue xxx; 281 break; 282 } 283 do { 284 x++; 285 } while (x < 100); 286 do x++; while (x < 100); 287 for (@Deprecated int i : arr4[0]) { 288 x--; 289 } 290 for (@Deprecated final int i = 0, j = 1; i < 10; x++) { 291 break; 292 } 293 int i, j; 294 for (i = 0, j = 1; i < 10 && j < 2; i++, j--) { 295 break; 296 } 297 } 298 299 public static CompilationUnit parse(@Deprecated File file) throws ParseException, IOException { 300 String a = ((String) "qwe"); 301 String x = ((String) clz1.getName()); 302 int y = ((Integer) (Object) x).intValue(); 303 synchronized (file) { 304 file = null; 305 file = new File(""); 306 } 307 try { 308 if (file == null) { 309 throw new NullPointerException("blah"); 310 } 311 } catch (final NullPointerException e) { 312 System.out.println("catch"); 313 } catch (RuntimeException e) { 314 System.out.println("catch"); 315 } finally { 316 System.out.println("finally"); 317 } 318 try { 319 if (file == null) { 320 throw new NullPointerException("blah"); 321 } 322 } finally { 323 System.out.println("finally"); 324 } 325 try { 326 if (file == null) { 327 throw new NullPointerException("blah"); 328 } 329 } catch (RuntimeException e) { 330 System.out.println("catch"); 331 } 332 try (InputStream in = createInputStream()) { 333 System.out.println(in); 334 } catch (IOException e) { 335 System.out.println("catch"); 336 } 337 try (InputStream in = createInputStream(); 338 InputStream in2 = createInputStream()) { 339 System.out.println(in); 340 } catch (IOException e) { 341 System.out.println("catch"); 342 } 343 try (InputStream in = createInputStream()) { 344 System.out.println(in); 345 } 346 try { 347 System.out.println("whatever"); 348 } catch (RuntimeException e) { 349 System.out.println(e); 350 } catch (final Exception | Error e) { 351 System.out.println(e); 352 } 353 return JavaParser.parse(file); 354 } 355 356 class A<T extends Integer & Serializable> implements XXX, Serializable { 357 358 public <ABC> A(Integer integer, ABC string) throws Exception, IOException { 359 } 360 } 361 362 private <Y> void x(Map<? extends X, ? super T> x) { 363 @Deprecated Comparator c = new Comparator() { 364 365 public int compare(Object o1, Object o2) { 366 try { 367 A<Integer> a = new <String>A<Integer>(new Integer(11), "foo") { 368 }; 369 } catch (Exception e) { 370 } 371 return 0; 372 } 373 374 @Override 375 public boolean equals(Object obj) { 376 return super.equals(obj); 377 } 378 }; 379 } 380 381 private static InputStream createInputStream() { 382 return new ByteArrayInputStream(null); 383 } 384 } 385 386 class Base { 387 388 public <A, B> void check2(A val1, B val2) { 389 } 390 } 391 392 interface XXX extends Serializable, Cloneable { 393 } 394