1 /*******************************************************************************
2 * Copyright (c) 2000, 2020 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 * Jesper S Moller - realigned with bug 399695
14 *******************************************************************************/
15 package org.eclipse.jdt.core.tests.compiler.parser;
16
17 import junit.framework.Test;
18
19 import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest;
20 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
21
22 @SuppressWarnings({ "rawtypes" })
23 public class ComplianceDiagnoseTest extends AbstractRegressionTest {
ComplianceDiagnoseTest(String name)24 public ComplianceDiagnoseTest(String name) {
25 super(name);
26 }
27 // Static initializer to specify tests subset using TESTS_* static variables
28 // All specified tests which does not belong to the class are skipped...
29 static {
30 // TESTS_NAMES = new String[] { "test0042" };
31 // TESTS_NUMBERS = new int[] { 50 };
32 // TESTS_RANGE = new int[] { 21, 50 };
33 }
suite()34 public static Test suite() {
35 return buildAllCompliancesTestSuite(testClass());
36 }
testClass()37 public static Class testClass() {
38 return ComplianceDiagnoseTest.class;
39 }
runComplianceParserTest( String[] testFiles, String expected13ProblemLog, String expected14ProblemLog, String expected15ProblemLog)40 public void runComplianceParserTest(
41 String[] testFiles,
42 String expected13ProblemLog,
43 String expected14ProblemLog,
44 String expected15ProblemLog){
45 if(this.complianceLevel == ClassFileConstants.JDK1_3) {
46 this.runNegativeTest(testFiles, expected13ProblemLog);
47 } else if(this.complianceLevel == ClassFileConstants.JDK1_4) {
48 this.runNegativeTest(testFiles, expected14ProblemLog);
49 } else if(this.complianceLevel >= ClassFileConstants.JDK1_5) {
50 this.runNegativeTest(testFiles, expected15ProblemLog);
51 }
52 }
runComplianceParserTest( String[] testFiles, String expected13ProblemLog, String expected14ProblemLog, String expected15ProblemLog, String expected17ProblemLog)53 public void runComplianceParserTest(
54 String[] testFiles,
55 String expected13ProblemLog,
56 String expected14ProblemLog,
57 String expected15ProblemLog,
58 String expected17ProblemLog){
59 if(this.complianceLevel == ClassFileConstants.JDK1_3) {
60 this.runNegativeTest(testFiles, expected13ProblemLog);
61 } else if(this.complianceLevel == ClassFileConstants.JDK1_4) {
62 this.runNegativeTest(testFiles, expected14ProblemLog);
63 } else if(this.complianceLevel < ClassFileConstants.JDK1_7) {
64 this.runNegativeTest(testFiles, expected15ProblemLog);
65 } else {
66 this.runNegativeTest(testFiles, expected17ProblemLog);
67 }
68 }
runComplianceParserTest( String[] testFiles, String expected13ProblemLog, String expected14ProblemLog, String expected15ProblemLog, String expected16ProblemLog, String expected17ProblemLog)69 public void runComplianceParserTest(
70 String[] testFiles,
71 String expected13ProblemLog,
72 String expected14ProblemLog,
73 String expected15ProblemLog,
74 String expected16ProblemLog,
75 String expected17ProblemLog){
76 if (this.complianceLevel == ClassFileConstants.JDK1_3) {
77 this.runNegativeTest(testFiles, expected13ProblemLog);
78 } else if(this.complianceLevel == ClassFileConstants.JDK1_4) {
79 this.runNegativeTest(testFiles, expected14ProblemLog);
80 } else if(this.complianceLevel == ClassFileConstants.JDK1_5) {
81 this.runNegativeTest(testFiles, expected15ProblemLog);
82 } else if(this.complianceLevel == ClassFileConstants.JDK1_6) {
83 this.runNegativeTest(testFiles, expected16ProblemLog);
84 } else if(this.complianceLevel < ClassFileConstants.JDK1_8) {
85 this.runNegativeTest(testFiles, expected17ProblemLog);
86 }
87 }
runComplianceParserTest( String[] testFiles, String expected13ProblemLog, String expected14ProblemLog, String expected15ProblemLog, String expected16ProblemLog, String expected17ProblemLog, String expected18ProblemLog)88 public void runComplianceParserTest(
89 String[] testFiles,
90 String expected13ProblemLog,
91 String expected14ProblemLog,
92 String expected15ProblemLog,
93 String expected16ProblemLog,
94 String expected17ProblemLog,
95 String expected18ProblemLog){
96 if (this.complianceLevel == ClassFileConstants.JDK1_3) {
97 this.runNegativeTest(testFiles, expected13ProblemLog);
98 } else if(this.complianceLevel == ClassFileConstants.JDK1_4) {
99 this.runNegativeTest(testFiles, expected14ProblemLog);
100 } else if(this.complianceLevel == ClassFileConstants.JDK1_5) {
101 this.runNegativeTest(testFiles, expected15ProblemLog);
102 } else if(this.complianceLevel == ClassFileConstants.JDK1_6) {
103 this.runNegativeTest(testFiles, expected16ProblemLog);
104 } else if(this.complianceLevel < ClassFileConstants.JDK1_8) {
105 this.runNegativeTest(testFiles, expected17ProblemLog);
106 } else {
107 this.runNegativeTest(testFiles, expected18ProblemLog);
108 }
109 }
test0001()110 public void test0001() {
111 String[] testFiles = new String[] {
112 "X.java",
113 "import static aaa.BBB.*;\n" +
114 "public class X {\n" +
115 "}\n"
116 };
117
118 String expected13ProblemLog =
119 "----------\n" +
120 "1. ERROR in X.java (at line 1)\n" +
121 " import static aaa.BBB.*;\n" +
122 " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
123 "Syntax error, static imports are only available if source level is 1.5 or greater\n" +
124 "----------\n" +
125 "2. ERROR in X.java (at line 1)\n" +
126 " import static aaa.BBB.*;\n" +
127 " ^^^\n" +
128 "The import aaa cannot be resolved\n" +
129 "----------\n";
130 String expected14ProblemLog =
131 expected13ProblemLog;
132
133 String expected15ProblemLog =
134 "----------\n" +
135 "1. ERROR in X.java (at line 1)\n" +
136 " import static aaa.BBB.*;\n" +
137 " ^^^\n" +
138 "The import aaa cannot be resolved\n" +
139 "----------\n";
140
141 runComplianceParserTest(
142 testFiles,
143 expected13ProblemLog,
144 expected14ProblemLog,
145 expected15ProblemLog
146 );
147 }
test0002()148 public void test0002() {
149 String[] testFiles = new String[] {
150 "X.java",
151 "import static aaa.BBB.CCC;\n" +
152 "public class X {\n" +
153 "}\n"
154 };
155
156 String expected13ProblemLog =
157 "----------\n" +
158 "1. ERROR in X.java (at line 1)\n" +
159 " import static aaa.BBB.CCC;\n" +
160 " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
161 "Syntax error, static imports are only available if source level is 1.5 or greater\n" +
162 "----------\n" +
163 "2. ERROR in X.java (at line 1)\n" +
164 " import static aaa.BBB.CCC;\n" +
165 " ^^^\n" +
166 "The import aaa cannot be resolved\n" +
167 "----------\n";
168 String expected14ProblemLog =
169 expected13ProblemLog;
170
171 String expected15ProblemLog =
172 "----------\n" +
173 "1. ERROR in X.java (at line 1)\n" +
174 " import static aaa.BBB.CCC;\n" +
175 " ^^^\n" +
176 "The import aaa cannot be resolved\n" +
177 "----------\n";
178
179 runComplianceParserTest(
180 testFiles,
181 expected13ProblemLog,
182 expected14ProblemLog,
183 expected15ProblemLog
184 );
185 }
test0003()186 public void test0003() {
187 String[] testFiles = new String[] {
188 "X.java",
189 "public enum X {\n" +
190 "}\n"
191 };
192
193 String expected13ProblemLog =
194 "----------\n" +
195 "1. ERROR in X.java (at line 1)\n" +
196 " public enum X {\n" +
197 " ^^^^\n" +
198 "Syntax error on token \"enum\", interface expected\n" +
199 "----------\n";
200 String expected14ProblemLog =
201 expected13ProblemLog;
202
203 String expected15ProblemLog =
204 "";
205
206 runComplianceParserTest(
207 testFiles,
208 expected13ProblemLog,
209 expected14ProblemLog,
210 expected15ProblemLog
211 );
212 }
test0004()213 public void test0004() {
214 String[] testFiles = new String[] {
215 "X.java",
216 "public class X {\n" +
217 " void foo(){\n" +
218 " for(String o: c) {\n" +
219 " }\n" +
220 " }\n" +
221 "}\n"
222 };
223
224 String expected13ProblemLog =
225 "----------\n" +
226 "1. ERROR in X.java (at line 3)\n" +
227 " for(String o: c) {\n" +
228 " ^^^^^^^^^^^\n" +
229 "Syntax error, \'for each\' statements are only available if source level is 1.5 or greater\n" +
230 "----------\n" +
231 "2. ERROR in X.java (at line 3)\n" +
232 " for(String o: c) {\n" +
233 " ^\n" +
234 "c cannot be resolved to a variable\n" +
235 "----------\n";
236 String expected14ProblemLog =
237 expected13ProblemLog;
238
239 String expected15ProblemLog =
240 "----------\n" +
241 "1. ERROR in X.java (at line 3)\n" +
242 " for(String o: c) {\n" +
243 " ^\n" +
244 "c cannot be resolved to a variable\n" +
245 "----------\n";
246
247 runComplianceParserTest(
248 testFiles,
249 expected13ProblemLog,
250 expected14ProblemLog,
251 expected15ProblemLog
252 );
253 }
test0005()254 public void test0005() {
255 String[] testFiles = new String[] {
256 "X.java",
257 "public class X {\n" +
258 " void foo(Z ... arg){\n" +
259 " }\n" +
260 "}\n"
261 };
262
263 String expected13ProblemLog =
264 "----------\n" +
265 "1. ERROR in X.java (at line 2)\n" +
266 " void foo(Z ... arg){\n" +
267 " ^^^^^^^^^\n" +
268 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
269 "----------\n" +
270 "2. ERROR in X.java (at line 2)\n" +
271 " void foo(Z ... arg){\n" +
272 " ^\n" +
273 "Z cannot be resolved to a type\n" +
274 "----------\n";
275 String expected14ProblemLog =
276 expected13ProblemLog;
277
278 String expected15ProblemLog =
279 "----------\n" +
280 "1. ERROR in X.java (at line 2)\n" +
281 " void foo(Z ... arg){\n" +
282 " ^\n" +
283 "Z cannot be resolved to a type\n" +
284 "----------\n";
285
286 runComplianceParserTest(
287 testFiles,
288 expected13ProblemLog,
289 expected14ProblemLog,
290 expected15ProblemLog
291 );
292 }
test0006()293 public void test0006() {
294 String[] testFiles = new String[] {
295 "X.java",
296 "public class X <T1 extends String, T2> extends Y {\n" +
297 "}\n"
298 };
299
300 String expected13ProblemLog =
301 "----------\n" +
302 "1. ERROR in X.java (at line 1)\n" +
303 " public class X <T1 extends String, T2> extends Y {\n" +
304 " ^^^^^^^^^^^^^^^^^^^^^\n" +
305 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
306 "----------\n" +
307 "2. ERROR in X.java (at line 1)\n" +
308 " public class X <T1 extends String, T2> extends Y {\n" +
309 " ^\n" +
310 "Y cannot be resolved to a type\n" +
311 "----------\n";
312 String expected14ProblemLog =
313 expected13ProblemLog;
314
315 String expected15ProblemLog =
316 "----------\n" +
317 "1. WARNING in X.java (at line 1)\n" +
318 " public class X <T1 extends String, T2> extends Y {\n" +
319 " ^^^^^^\n" +
320 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
321 "----------\n" +
322 "2. ERROR in X.java (at line 1)\n" +
323 " public class X <T1 extends String, T2> extends Y {\n" +
324 " ^\n" +
325 "Y cannot be resolved to a type\n" +
326 "----------\n";
327
328 runComplianceParserTest(
329 testFiles,
330 expected13ProblemLog,
331 expected14ProblemLog,
332 expected15ProblemLog
333 );
334 }
test0007()335 public void test0007() {
336 String[] testFiles = new String[] {
337 "X.java",
338 "public interface X <T1 extends String, T2> extends Y {\n" +
339 "}\n"
340 };
341
342 String expected13ProblemLog =
343 "----------\n" +
344 "1. ERROR in X.java (at line 1)\n" +
345 " public interface X <T1 extends String, T2> extends Y {\n" +
346 " ^^^^^^^^^^^^^^^^^^^^^\n" +
347 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
348 "----------\n" +
349 "2. ERROR in X.java (at line 1)\n" +
350 " public interface X <T1 extends String, T2> extends Y {\n" +
351 " ^\n" +
352 "Y cannot be resolved to a type\n" +
353 "----------\n";
354 String expected14ProblemLog =
355 expected13ProblemLog;
356
357 String expected15ProblemLog =
358 "----------\n" +
359 "1. WARNING in X.java (at line 1)\n" +
360 " public interface X <T1 extends String, T2> extends Y {\n" +
361 " ^^^^^^\n" +
362 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
363 "----------\n" +
364 "2. ERROR in X.java (at line 1)\n" +
365 " public interface X <T1 extends String, T2> extends Y {\n" +
366 " ^\n" +
367 "Y cannot be resolved to a type\n" +
368 "----------\n";
369
370 runComplianceParserTest(
371 testFiles,
372 expected13ProblemLog,
373 expected14ProblemLog,
374 expected15ProblemLog
375 );
376 }
test0008()377 public void test0008() {
378 String[] testFiles = new String[] {
379 "X.java",
380 "public class X {\n" +
381 " public <T1 extends String, T2> int foo(){\n" +
382 " }\n" +
383 "}\n"
384 };
385
386 String expected13ProblemLog =
387 "----------\n" +
388 "1. ERROR in X.java (at line 2)\n" +
389 " public <T1 extends String, T2> int foo(){\n" +
390 " ^^^^^^^^^^^^^^^^^^^^^\n" +
391 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
392 "----------\n";
393 String expected14ProblemLog =
394 expected13ProblemLog;
395
396 String expected15ProblemLog =
397 "----------\n" +
398 "1. WARNING in X.java (at line 2)\n" +
399 " public <T1 extends String, T2> int foo(){\n" +
400 " ^^^^^^\n" +
401 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
402 "----------\n" +
403 "2. ERROR in X.java (at line 2)\n" +
404 " public <T1 extends String, T2> int foo(){\n" +
405 " ^^^^^\n" +
406 "This method must return a result of type int\n" +
407 "----------\n";
408
409 runComplianceParserTest(
410 testFiles,
411 expected13ProblemLog,
412 expected14ProblemLog,
413 expected15ProblemLog
414 );
415 }
test0009()416 public void test0009() {
417 String[] testFiles = new String[] {
418 "X.java",
419 "public class X {\n" +
420 " public <T1 extends String, T2> X(){\n" +
421 " }\n" +
422 "}\n"
423 };
424
425 String expected13ProblemLog =
426 "----------\n" +
427 "1. ERROR in X.java (at line 2)\n" +
428 " public <T1 extends String, T2> X(){\n" +
429 " ^^^^^^^^^^^^^^^^^^^^^\n" +
430 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
431 "----------\n";
432
433 String expected15ProblemLog =
434 "----------\n" +
435 "1. WARNING in X.java (at line 2)\n" +
436 " public <T1 extends String, T2> X(){\n" +
437 " ^^^^^^\n" +
438 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
439 "----------\n";
440
441 if(this.complianceLevel < ClassFileConstants.JDK1_5) {
442 this.runNegativeTest(testFiles, expected13ProblemLog);
443 } else {
444 runConformTest(
445 true,
446 testFiles,
447 expected15ProblemLog,
448 null, null,
449 JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
450 }
451 }
test0010()452 public void test0010() {
453 String[] testFiles = new String[] {
454 "X.java",
455 "public class X {\n" +
456 " Z<Y1, Y2> var;\n" +
457 "}\n"
458 };
459
460 String expected13ProblemLog =
461 "----------\n" +
462 "1. ERROR in X.java (at line 2)\n" +
463 " Z<Y1, Y2> var;\n" +
464 " ^\n" +
465 "Z cannot be resolved to a type\n" +
466 "----------\n" +
467 "2. ERROR in X.java (at line 2)\n" +
468 " Z<Y1, Y2> var;\n" +
469 " ^^^^^^\n" +
470 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
471 "----------\n" +
472 "3. ERROR in X.java (at line 2)\n" +
473 " Z<Y1, Y2> var;\n" +
474 " ^^\n" +
475 "Y1 cannot be resolved to a type\n" +
476 "----------\n" +
477 "4. ERROR in X.java (at line 2)\n" +
478 " Z<Y1, Y2> var;\n" +
479 " ^^\n" +
480 "Y2 cannot be resolved to a type\n" +
481 "----------\n";
482 String expected14ProblemLog =
483 expected13ProblemLog;
484
485 String expected15ProblemLog =
486 "----------\n" +
487 "1. ERROR in X.java (at line 2)\n" +
488 " Z<Y1, Y2> var;\n" +
489 " ^\n" +
490 "Z cannot be resolved to a type\n" +
491 "----------\n" +
492 "2. ERROR in X.java (at line 2)\n" +
493 " Z<Y1, Y2> var;\n" +
494 " ^^\n" +
495 "Y1 cannot be resolved to a type\n" +
496 "----------\n" +
497 "3. ERROR in X.java (at line 2)\n" +
498 " Z<Y1, Y2> var;\n" +
499 " ^^\n" +
500 "Y2 cannot be resolved to a type\n" +
501 "----------\n";
502
503 runComplianceParserTest(
504 testFiles,
505 expected13ProblemLog,
506 expected14ProblemLog,
507 expected15ProblemLog
508 );
509 }
test0011()510 public void test0011() {
511 String[] testFiles = new String[] {
512 "X.java",
513 "public class X {\n" +
514 " public X(){\n" +
515 " <Y1, Y2>this(null);\n" +
516 " }\n" +
517 "}\n"
518 };
519
520 String expected13ProblemLog =
521 "----------\n" +
522 "1. ERROR in X.java (at line 3)\n" +
523 " <Y1, Y2>this(null);\n" +
524 " ^^^^^^\n" +
525 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
526 "----------\n" +
527 "2. ERROR in X.java (at line 3)\n" +
528 " <Y1, Y2>this(null);\n" +
529 " ^^\n" +
530 "Y1 cannot be resolved to a type\n" +
531 "----------\n" +
532 "3. ERROR in X.java (at line 3)\n" +
533 " <Y1, Y2>this(null);\n" +
534 " ^^\n" +
535 "Y2 cannot be resolved to a type\n" +
536 "----------\n";
537 String expected14ProblemLog =
538 expected13ProblemLog;
539
540 String expected15ProblemLog =
541 "----------\n" +
542 "1. ERROR in X.java (at line 3)\n" +
543 " <Y1, Y2>this(null);\n" +
544 " ^^\n" +
545 "Y1 cannot be resolved to a type\n" +
546 "----------\n" +
547 "2. ERROR in X.java (at line 3)\n" +
548 " <Y1, Y2>this(null);\n" +
549 " ^^\n" +
550 "Y2 cannot be resolved to a type\n" +
551 "----------\n" +
552 "3. ERROR in X.java (at line 3)\n" +
553 " <Y1, Y2>this(null);\n" +
554 " ^^^^^^^^^^^\n" +
555 "The constructor X(null) is undefined\n" +
556 "----------\n";
557
558 runComplianceParserTest(
559 testFiles,
560 expected13ProblemLog,
561 expected14ProblemLog,
562 expected15ProblemLog
563 );
564 }
test0012()565 public void test0012() {
566 String[] testFiles = new String[] {
567 "X.java",
568 "public class X {\n" +
569 " void foo() {\n" +
570 " assert true;\n" +
571 " }\n" +
572 "}\n" +
573 "\n"
574 };
575
576 String expected13ProblemLog =
577 "----------\n" +
578 "1. WARNING in X.java (at line 3)\n" +
579 " assert true;\n" +
580 " ^^^^^^\n" +
581 "\'assert\' should not be used as an identifier, since it is a reserved keyword from source level 1.4 on\n" +
582 "----------\n" +
583 "2. ERROR in X.java (at line 3)\n" +
584 " assert true;\n" +
585 " ^^^^^^\n" +
586 "Syntax error on token \"assert\", AssignmentOperator expected after this token\n" +
587 "----------\n";
588 String expected14ProblemLog =
589 "";
590
591 String expected15ProblemLog =
592 expected14ProblemLog;
593
594 runComplianceParserTest(
595 testFiles,
596 expected13ProblemLog,
597 expected14ProblemLog,
598 expected15ProblemLog
599 );
600 }
test0013()601 public void test0013() {
602 String[] testFiles = new String[] {
603 "X.java",
604 "import static aaa.*\n" +
605 "public class X {\n" +
606 "}\n" +
607 "\n"
608 };
609
610 String expected13ProblemLog =
611 "----------\n" +
612 "1. ERROR in X.java (at line 1)\n" +
613 " import static aaa.*\n" +
614 " ^^^^^^^^^^^^^^^^^\n" +
615 "Syntax error, static imports are only available if source level is 1.5 or greater\n" +
616 "----------\n" +
617 "2. ERROR in X.java (at line 1)\n" +
618 " import static aaa.*\n" +
619 " ^^^\n" +
620 "The import aaa cannot be resolved\n" +
621 "----------\n" +
622 "3. ERROR in X.java (at line 1)\n" +
623 " import static aaa.*\n" +
624 " ^\n" +
625 "Syntax error on token \"*\", ; expected after this token\n" +
626 "----------\n";
627 String expected14ProblemLog =
628 expected13ProblemLog;
629
630 String expected15ProblemLog =
631 "----------\n" +
632 "1. ERROR in X.java (at line 1)\n" +
633 " import static aaa.*\n" +
634 " ^^^\n" +
635 "The import aaa cannot be resolved\n" +
636 "----------\n" +
637 "2. ERROR in X.java (at line 1)\n" +
638 " import static aaa.*\n" +
639 " ^\n" +
640 "Syntax error on token \"*\", ; expected after this token\n" +
641 "----------\n";
642
643 runComplianceParserTest(
644 testFiles,
645 expected13ProblemLog,
646 expected14ProblemLog,
647 expected15ProblemLog
648 );
649 }
test0014()650 public void test0014() {
651 String[] testFiles = new String[] {
652 "X.java",
653 "public enum X \n" +
654 "}\n"
655 };
656
657 String expected13ProblemLog =
658 "----------\n" +
659 "1. ERROR in X.java (at line 1)\n" +
660 " public enum X \n" +
661 "}\n" +
662 " ^^^^^^^^^\n" +
663 "Syntax error on tokens, delete these tokens\n" +
664 "----------\n";
665 String expected14ProblemLog =
666 expected13ProblemLog;
667
668 String expected15ProblemLog =
669 "----------\n" +
670 "1. ERROR in X.java (at line 1)\n" +
671 " public enum X \n" +
672 " ^\n" +
673 "Syntax error on token \"X\", { expected after this token\n" +
674 "----------\n";
675
676 runComplianceParserTest(
677 testFiles,
678 expected13ProblemLog,
679 expected14ProblemLog,
680 expected15ProblemLog
681 );
682 }
test0015()683 public void test0015() {
684 String[] testFiles = new String[] {
685 "X.java",
686 "public class X {\n" +
687 " void foo(){\n" +
688 " for(String o: c) {\n" +
689 " #\n" +
690 " }\n" +
691 " }\n" +
692 "}\n"
693 };
694
695 String expected13ProblemLog =
696 "----------\n" +
697 "1. ERROR in X.java (at line 3)\n" +
698 " for(String o: c) {\n" +
699 " ^^^^^^^^^^^\n" +
700 "Syntax error, \'for each\' statements are only available if source level is 1.5 or greater\n" +
701 "----------\n" +
702 "2. ERROR in X.java (at line 4)\n" +
703 " #\n" +
704 " ^\n" +
705 "Syntax error on token \"Invalid Character\", delete this token\n" +
706 "----------\n";
707 String expected14ProblemLog =
708 expected13ProblemLog;
709
710 String expected15ProblemLog =
711 "----------\n" +
712 "1. ERROR in X.java (at line 4)\n" +
713 " #\n" +
714 " ^\n" +
715 "Syntax error on token \"Invalid Character\", delete this token\n" +
716 "----------\n";
717
718 runComplianceParserTest(
719 testFiles,
720 expected13ProblemLog,
721 expected14ProblemLog,
722 expected15ProblemLog
723 );
724 }
test0016()725 public void test0016() {
726 String[] testFiles = new String[] {
727 "X.java",
728 "public class X {\n" +
729 " void foo(Z ... arg){\n" +
730 " }\n" +
731 " #\n" +
732 "}\n"
733 };
734
735 String expected13ProblemLog =
736 "----------\n" +
737 "1. ERROR in X.java (at line 2)\n" +
738 " void foo(Z ... arg){\n" +
739 " ^^^^^^^^^\n" +
740 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
741 "----------\n" +
742 "2. ERROR in X.java (at line 2)\n" +
743 " void foo(Z ... arg){\n" +
744 " ^\n" +
745 "Z cannot be resolved to a type\n" +
746 "----------\n" +
747 "3. ERROR in X.java (at line 4)\n" +
748 " #\n" +
749 " ^\n" +
750 "Syntax error on token \"Invalid Character\", delete this token\n" +
751 "----------\n";
752 String expected14ProblemLog =
753 expected13ProblemLog;
754
755 String expected15ProblemLog =
756 "----------\n" +
757 "1. ERROR in X.java (at line 2)\n" +
758 " void foo(Z ... arg){\n" +
759 " ^\n" +
760 "Z cannot be resolved to a type\n" +
761 "----------\n" +
762 "2. ERROR in X.java (at line 4)\n" +
763 " #\n" +
764 " ^\n" +
765 "Syntax error on token \"Invalid Character\", delete this token\n" +
766 "----------\n";
767
768 runComplianceParserTest(
769 testFiles,
770 expected13ProblemLog,
771 expected14ProblemLog,
772 expected15ProblemLog
773 );
774 }
test0017()775 public void test0017() {
776 String[] testFiles = new String[] {
777 "X.java",
778 "public class X <T1 extends String, T2> extends Y {\n" +
779 " #\n" +
780 "}\n"
781 };
782
783 String expected13ProblemLog =
784 "----------\n" +
785 "1. ERROR in X.java (at line 1)\n" +
786 " public class X <T1 extends String, T2> extends Y {\n" +
787 " ^^^^^^^^^^^^^^^^^^^^^\n" +
788 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
789 "----------\n" +
790 "2. ERROR in X.java (at line 1)\n" +
791 " public class X <T1 extends String, T2> extends Y {\n" +
792 " ^\n" +
793 "Y cannot be resolved to a type\n" +
794 "----------\n" +
795 "3. ERROR in X.java (at line 2)\n" +
796 " #\n" +
797 " ^\n" +
798 "Syntax error on token \"Invalid Character\", delete this token\n" +
799 "----------\n";
800 String expected14ProblemLog =
801 expected13ProblemLog;
802
803 String expected15ProblemLog =
804 "----------\n" +
805 "1. WARNING in X.java (at line 1)\n" +
806 " public class X <T1 extends String, T2> extends Y {\n" +
807 " ^^^^^^\n" +
808 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
809 "----------\n" +
810 "2. ERROR in X.java (at line 1)\n" +
811 " public class X <T1 extends String, T2> extends Y {\n" +
812 " ^\n" +
813 "Y cannot be resolved to a type\n" +
814 "----------\n" +
815 "3. ERROR in X.java (at line 2)\n" +
816 " #\n" +
817 " ^\n" +
818 "Syntax error on token \"Invalid Character\", delete this token\n" +
819 "----------\n";
820
821 runComplianceParserTest(
822 testFiles,
823 expected13ProblemLog,
824 expected14ProblemLog,
825 expected15ProblemLog
826 );
827 }
test0018()828 public void test0018() {
829 String[] testFiles = new String[] {
830 "X.java",
831 "public class X {\n" +
832 " public <T1 extends String, T2> int foo(){\n" +
833 " }\n" +
834 " #\n" +
835 "}\n"
836 };
837
838 String expected13ProblemLog =
839 "----------\n" +
840 "1. ERROR in X.java (at line 2)\n" +
841 " public <T1 extends String, T2> int foo(){\n" +
842 " ^^^^^^^^^^^^^^^^^^^^^\n" +
843 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
844 "----------\n" +
845 "2. ERROR in X.java (at line 4)\n" +
846 " #\n" +
847 " ^\n" +
848 "Syntax error on token \"Invalid Character\", delete this token\n" +
849 "----------\n";
850 String expected14ProblemLog =
851 expected13ProblemLog;
852
853 String expected15ProblemLog =
854 "----------\n" +
855 "1. WARNING in X.java (at line 2)\n" +
856 " public <T1 extends String, T2> int foo(){\n" +
857 " ^^^^^^\n" +
858 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
859 "----------\n" +
860 "2. ERROR in X.java (at line 4)\n" +
861 " #\n" +
862 " ^\n" +
863 "Syntax error on token \"Invalid Character\", delete this token\n" +
864 "----------\n";
865
866 runComplianceParserTest(
867 testFiles,
868 expected13ProblemLog,
869 expected14ProblemLog,
870 expected15ProblemLog
871 );
872 }
test0019()873 public void test0019() {
874 String[] testFiles = new String[] {
875 "X.java",
876 "public class X {\n" +
877 " Z<Y1, Y2> var;\n" +
878 " #\n" +
879 "}\n"
880 };
881
882 String expected13ProblemLog =
883 "----------\n" +
884 "1. ERROR in X.java (at line 2)\n" +
885 " Z<Y1, Y2> var;\n" +
886 " ^\n" +
887 "Z cannot be resolved to a type\n" +
888 "----------\n" +
889 "2. ERROR in X.java (at line 2)\n" +
890 " Z<Y1, Y2> var;\n" +
891 " ^^^^^^\n" +
892 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
893 "----------\n" +
894 "3. ERROR in X.java (at line 2)\n" +
895 " Z<Y1, Y2> var;\n" +
896 " ^^\n" +
897 "Y1 cannot be resolved to a type\n" +
898 "----------\n" +
899 "4. ERROR in X.java (at line 2)\n" +
900 " Z<Y1, Y2> var;\n" +
901 " ^^\n" +
902 "Y2 cannot be resolved to a type\n" +
903 "----------\n" +
904 "5. ERROR in X.java (at line 3)\n" +
905 " #\n" +
906 " ^\n" +
907 "Syntax error on token \"Invalid Character\", delete this token\n" +
908 "----------\n";
909 String expected14ProblemLog =
910 expected13ProblemLog;
911
912 String expected15ProblemLog =
913 "----------\n" +
914 "1. ERROR in X.java (at line 2)\n" +
915 " Z<Y1, Y2> var;\n" +
916 " ^\n" +
917 "Z cannot be resolved to a type\n" +
918 "----------\n" +
919 "2. ERROR in X.java (at line 2)\n" +
920 " Z<Y1, Y2> var;\n" +
921 " ^^\n" +
922 "Y1 cannot be resolved to a type\n" +
923 "----------\n" +
924 "3. ERROR in X.java (at line 2)\n" +
925 " Z<Y1, Y2> var;\n" +
926 " ^^\n" +
927 "Y2 cannot be resolved to a type\n" +
928 "----------\n" +
929 "4. ERROR in X.java (at line 3)\n" +
930 " #\n" +
931 " ^\n" +
932 "Syntax error on token \"Invalid Character\", delete this token\n" +
933 "----------\n";
934
935 runComplianceParserTest(
936 testFiles,
937 expected13ProblemLog,
938 expected14ProblemLog,
939 expected15ProblemLog
940 );
941 }
test0020()942 public void test0020() {
943 String[] testFiles = new String[] {
944 "X.java",
945 "public class X {\n" +
946 " void foo() {\n" +
947 " assert true;\n" +
948 " #\n" +
949 " }\n" +
950 "}\n" +
951 "\n"
952 };
953
954 String expected13ProblemLog =
955 "----------\n" +
956 "1. WARNING in X.java (at line 3)\n" +
957 " assert true;\n" +
958 " ^^^^^^\n" +
959 "\'assert\' should not be used as an identifier, since it is a reserved keyword from source level 1.4 on\n" +
960 "----------\n" +
961 "2. ERROR in X.java (at line 3)\n" +
962 " assert true;\n" +
963 " ^^^^^^\n" +
964 "Syntax error on token \"assert\", AssignmentOperator expected after this token\n" +
965 "----------\n" +
966 "3. ERROR in X.java (at line 4)\n" +
967 " #\n" +
968 " ^\n" +
969 "Syntax error on token \"Invalid Character\", delete this token\n" +
970 "----------\n";
971 String expected14ProblemLog =
972 "----------\n" +
973 "1. ERROR in X.java (at line 4)\n" +
974 " #\n" +
975 " ^\n" +
976 "Syntax error on token \"Invalid Character\", delete this token\n" +
977 "----------\n";
978
979 String expected15ProblemLog =
980 expected14ProblemLog;
981
982 runComplianceParserTest(
983 testFiles,
984 expected13ProblemLog,
985 expected14ProblemLog,
986 expected15ProblemLog
987 );
988 }
989 //TODO (david) suspicious behavior
test0021()990 public void test0021() {
991 String[] testFiles = new String[] {
992 "X.java",
993 "import staic aaa.*;\n" +
994 "public class X {\n" +
995 "}\n" +
996 "\n"
997 };
998
999 String expected13ProblemLog =
1000 "----------\n" +
1001 "1. ERROR in X.java (at line 1)\n" +
1002 " import staic aaa.*;\n" +
1003 " ^^^^^\n" +
1004 "The import staic cannot be resolved\n" +
1005 "----------\n" +
1006 "2. ERROR in X.java (at line 1)\n" +
1007 " import staic aaa.*;\n" +
1008 " ^^^\n" +
1009 "Syntax error on token \"aaa\", delete this token\n" +
1010 "----------\n";
1011 String expected14ProblemLog =
1012 expected13ProblemLog;
1013
1014 String expected15ProblemLog =
1015 "----------\n" +
1016 "1. ERROR in X.java (at line 1)\n" +
1017 " import staic aaa.*;\n" +
1018 " ^^^^^\n" +
1019 "Syntax error on token \"staic\", static expected\n" +
1020 "----------\n" +
1021 "2. ERROR in X.java (at line 1)\n" +
1022 " import staic aaa.*;\n" +
1023 " ^^^^^\n" +
1024 "The import staic cannot be resolved\n" +
1025 "----------\n";
1026
1027 runComplianceParserTest(
1028 testFiles,
1029 expected13ProblemLog,
1030 expected14ProblemLog,
1031 expected15ProblemLog
1032 );
1033 }
1034 //TODO (david) suspicious behavior
test0022()1035 public void test0022() {
1036 String[] testFiles = new String[] {
1037 "X.java",
1038 "import static aaa.*.*;\n" +
1039 "public class X {\n" +
1040 "}\n" +
1041 "\n"
1042 };
1043
1044 String expected13ProblemLog =
1045 "----------\n" +
1046 "1. ERROR in X.java (at line 1)\n" +
1047 " import static aaa.*.*;\n" +
1048 " ^^^^^^^^^^^^^^^^^\n" +
1049 "Syntax error, static imports are only available if source level is 1.5 or greater\n" +
1050 "----------\n" +
1051 "2. ERROR in X.java (at line 1)\n" +
1052 " import static aaa.*.*;\n" +
1053 " ^^^\n" +
1054 "The import aaa cannot be resolved\n" +
1055 "----------\n" +
1056 "3. ERROR in X.java (at line 1)\n" +
1057 " import static aaa.*.*;\n" +
1058 " ^^\n" +
1059 "Syntax error on tokens, delete these tokens\n" +
1060 "----------\n";
1061 String expected14ProblemLog =
1062 expected13ProblemLog;
1063
1064 String expected15ProblemLog =
1065 "----------\n" +
1066 "1. ERROR in X.java (at line 1)\n" +
1067 " import static aaa.*.*;\n" +
1068 " ^^^\n" +
1069 "The import aaa cannot be resolved\n" +
1070 "----------\n" +
1071 "2. ERROR in X.java (at line 1)\n" +
1072 " import static aaa.*.*;\n" +
1073 " ^\n" +
1074 "Syntax error on token \"*\", Identifier expected\n" +
1075 "----------\n";
1076
1077 runComplianceParserTest(
1078 testFiles,
1079 expected13ProblemLog,
1080 expected14ProblemLog,
1081 expected15ProblemLog
1082 );
1083 }
test0023()1084 public void test0023() {
1085 String[] testFiles = new String[] {
1086 "X.java",
1087 "import static for;\n" +
1088 "public class X {\n" +
1089 "}\n" +
1090 "\n"
1091 };
1092
1093 String expected13ProblemLog =
1094 "----------\n" +
1095 "1. ERROR in X.java (at line 1)\n" +
1096 " import static for;\n" +
1097 " ^^^^^^^^^^\n" +
1098 "Syntax error on tokens, Name expected instead\n" +
1099 "----------\n";
1100 String expected14ProblemLog =
1101 expected13ProblemLog;
1102
1103 String expected15ProblemLog =
1104 "----------\n" +
1105 "1. ERROR in X.java (at line 1)\n" +
1106 " import static for;\n" +
1107 " ^^^\n" +
1108 "Syntax error on token \"for\", invalid Name\n" +
1109 "----------\n";
1110
1111 runComplianceParserTest(
1112 testFiles,
1113 expected13ProblemLog,
1114 expected14ProblemLog,
1115 expected15ProblemLog
1116 );
1117 }
1118
1119 //TODO (david) reenable once bug is fixed
_test0024()1120 public void _test0024() {
1121 String[] testFiles = new String[] {
1122 "X.java",
1123 "import static {aaa};\n" +
1124 "public class X {\n" +
1125 "}\n" +
1126 "\n"
1127 };
1128
1129 String expected13ProblemLog =
1130 "----------\n" +
1131 "1. ERROR in X.java (at line 1)\n" +
1132 " import static {aaa};\n" +
1133 " ^^^^^^^^^^^^\n" +
1134 "Syntax error on tokens, Name expected instead\n" +
1135 "----------\n";
1136 String expected14ProblemLog =
1137 expected13ProblemLog;
1138
1139 String expected15ProblemLog =
1140 "----------\n" +
1141 "1. ERROR in X.java (at line 1)\n" +
1142 " import static {aaa};\n" +
1143 " ^^^^^\n" +
1144 "Syntax error on tokens, Name expected instead\n" +
1145 "----------\n";
1146
1147 runComplianceParserTest(
1148 testFiles,
1149 expected13ProblemLog,
1150 expected14ProblemLog,
1151 expected15ProblemLog
1152 );
1153 }
test0025()1154 public void test0025() {
1155 String[] testFiles = new String[] {
1156 "X.java",
1157 "static aaa.*;\n" +
1158 "public class X {\n" +
1159 "}\n" +
1160 "\n"
1161 };
1162
1163 String expected13ProblemLog =
1164 "----------\n" +
1165 "1. ERROR in X.java (at line 1)\n" +
1166 " static aaa.*;\n" +
1167 " ^^^^^^\n" +
1168 "Syntax error on token \"static\", import expected\n" +
1169 "----------\n";
1170 String expected14ProblemLog =
1171 expected13ProblemLog;
1172
1173 String expected15ProblemLog =
1174 "----------\n" +
1175 "1. ERROR in X.java (at line 1)\n" +
1176 " static aaa.*;\n" +
1177 " ^^^^^^\n" +
1178 "Syntax error on token \"static\", import expected before this token\n" +
1179 "----------\n";
1180
1181 runComplianceParserTest(
1182 testFiles,
1183 expected13ProblemLog,
1184 expected14ProblemLog,
1185 expected15ProblemLog
1186 );
1187 }
test0026()1188 public void test0026() {
1189 String[] testFiles = new String[] {
1190 "X.java",
1191 "public class X {\n" +
1192 " void foo(){\n" +
1193 " for(Object o ? c){\n" +
1194 " }\n" +
1195 " }\n" +
1196 "}\n" +
1197 "\n"
1198 };
1199
1200 String expected13ProblemLog =
1201 "----------\n" +
1202 "1. ERROR in X.java (at line 3)\n" +
1203 " for(Object o ? c){\n" +
1204 " ^^^^^^\n" +
1205 "Syntax error on token \"Object\", ( expected\n" +
1206 "----------\n" +
1207 "2. ERROR in X.java (at line 3)\n" +
1208 " for(Object o ? c){\n" +
1209 " ^^^\n" +
1210 "Syntax error on token(s), misplaced construct(s)\n" +
1211 "----------\n" +
1212 "3. ERROR in X.java (at line 3)\n" +
1213 " for(Object o ? c){\n" +
1214 " ^\n" +
1215 "Syntax error, insert \"AssignmentOperator Expression\" to complete Assignment\n" +
1216 "----------\n" +
1217 "4. ERROR in X.java (at line 3)\n" +
1218 " for(Object o ? c){\n" +
1219 " ^\n" +
1220 "Syntax error, insert \"; ; ) Statement\" to complete BlockStatements\n" +
1221 "----------\n";
1222 String expected14ProblemLog =
1223 expected13ProblemLog;
1224
1225 String expected15ProblemLog =
1226 "----------\n" +
1227 "1. ERROR in X.java (at line 3)\n" +
1228 " for(Object o ? c){\n" +
1229 " ^\n" +
1230 "Syntax error on token \"?\", : expected\n" +
1231 "----------\n";
1232
1233 runComplianceParserTest(
1234 testFiles,
1235 expected13ProblemLog,
1236 expected14ProblemLog,
1237 expected15ProblemLog
1238 );
1239 }
test0027()1240 public void test0027() {
1241 String[] testFiles = new String[] {
1242 "X.java",
1243 "public class X {\n" +
1244 " void foo(){\n" +
1245 " for(Object o : switch){\n" +
1246 " }\n" +
1247 " }\n" +
1248 "}\n" +
1249 "\n"
1250 };
1251
1252 String expected13ProblemLog =
1253 "----------\n" +
1254 "1. ERROR in X.java (at line 3)\n" +
1255 " for(Object o : switch){\n" +
1256 " ^\n" +
1257 "Syntax error on token \":\", delete this token\n" +
1258 "----------\n" +
1259 "2. ERROR in X.java (at line 3)\n" +
1260 " for(Object o : switch){\n" +
1261 " ^\n" +
1262 "Syntax error, insert \": Expression )\" to complete EnhancedForStatementHeader\n" + // FIXME: bogus suggestion, this rule is compliance 1.5
1263 "----------\n" +
1264 "3. ERROR in X.java (at line 3)\n" +
1265 " for(Object o : switch){\n" +
1266 " ^\n" +
1267 "Syntax error, insert \"Statement\" to complete BlockStatements\n" +
1268 "----------\n";
1269 String expected14ProblemLog =
1270 expected13ProblemLog;
1271
1272 String expected15ProblemLog =
1273 "----------\n" +
1274 "1. ERROR in X.java (at line 3)\n" +
1275 " for(Object o : switch){\n" +
1276 " ^^^^^^\n" +
1277 "Syntax error on token \"switch\", invalid Expression\n" +
1278 "----------\n";
1279
1280 runComplianceParserTest(
1281 testFiles,
1282 expected13ProblemLog,
1283 expected14ProblemLog,
1284 expected15ProblemLog
1285 );
1286 }
test0028()1287 public void test0028() {
1288 String[] testFiles = new String[] {
1289 "X.java",
1290 "public class X {\n" +
1291 " void foo(int ... ){\n" +
1292 " }\n" +
1293 "}\n" +
1294 "\n"
1295 };
1296
1297 String expected13ProblemLog =
1298 "----------\n" +
1299 "1. ERROR in X.java (at line 1)\n" +
1300 " public class X {\n" +
1301 " ^\n" +
1302 "Syntax error, insert \"}\" to complete ClassBody\n" +
1303 "----------\n" +
1304 "2. ERROR in X.java (at line 2)\n" +
1305 " void foo(int ... ){\n" +
1306 " ^^^\n" +
1307 "Syntax error on token \"...\", invalid VariableDeclaratorId\n" +
1308 "----------\n" +
1309 "3. ERROR in X.java (at line 4)\n" +
1310 " }\n" +
1311 " ^\n" +
1312 "Syntax error on token \"}\", delete this token\n" +
1313 "----------\n";
1314 String expected14ProblemLog =
1315 expected13ProblemLog;
1316
1317 String expected15ProblemLog =
1318 "----------\n" +
1319 "1. ERROR in X.java (at line 1)\n" +
1320 " public class X {\n" +
1321 " ^\n" +
1322 "Syntax error, insert \"}\" to complete ClassBody\n" +
1323 "----------\n" +
1324 "2. ERROR in X.java (at line 2)\n" +
1325 " void foo(int ... ){\n" +
1326 " ^^^\n" +
1327 "Syntax error on token \"...\", VariableDeclaratorId expected after this token\n" +
1328 "----------\n" +
1329 "3. ERROR in X.java (at line 4)\n" +
1330 " }\n" +
1331 " ^\n" +
1332 "Syntax error on token \"}\", delete this token\n" +
1333 "----------\n";
1334
1335 runComplianceParserTest(
1336 testFiles,
1337 expected13ProblemLog,
1338 expected14ProblemLog,
1339 expected15ProblemLog
1340 );
1341 }
test0029()1342 public void test0029() {
1343 String[] testFiles = new String[] {
1344 "X.java",
1345 "public class X {\n" +
1346 " void foo(int ... for){\n" +
1347 " }\n" +
1348 "}\n" +
1349 "\n"
1350 };
1351
1352 String expected13ProblemLog =
1353 "----------\n" +
1354 "1. ERROR in X.java (at line 1)\n" +
1355 " public class X {\n" +
1356 " ^\n" +
1357 "Syntax error, insert \"}\" to complete ClassBody\n" +
1358 "----------\n" +
1359 "2. ERROR in X.java (at line 2)\n" +
1360 " void foo(int ... for){\n" +
1361 " ^^^^^^^\n" +
1362 "Syntax error on tokens, VariableDeclaratorId expected instead\n" +
1363 "----------\n" +
1364 "3. ERROR in X.java (at line 4)\n" +
1365 " }\n" +
1366 " ^\n" +
1367 "Syntax error on token \"}\", delete this token\n" +
1368 "----------\n";
1369 String expected14ProblemLog =
1370 expected13ProblemLog;
1371
1372 String expected15ProblemLog =
1373 "----------\n" +
1374 "1. ERROR in X.java (at line 1)\n" +
1375 " public class X {\n" +
1376 " ^\n" +
1377 "Syntax error, insert \"}\" to complete ClassBody\n" +
1378 "----------\n" +
1379 "2. ERROR in X.java (at line 2)\n" +
1380 " void foo(int ... for){\n" +
1381 " ^^^\n" +
1382 "Syntax error on token \"for\", invalid VariableDeclaratorId\n" +
1383 "----------\n" +
1384 "3. ERROR in X.java (at line 4)\n" +
1385 " }\n" +
1386 " ^\n" +
1387 "Syntax error on token \"}\", delete this token\n" +
1388 "----------\n";
1389
1390 runComplianceParserTest(
1391 testFiles,
1392 expected13ProblemLog,
1393 expected14ProblemLog,
1394 expected15ProblemLog
1395 );
1396 }
_test0030()1397 public void _test0030() {
1398 String[] testFiles = new String[] {
1399 "X.java",
1400 "public class X {\n" +
1401 " void foo(int .. aaa){\n" +
1402 " }\n" +
1403 "}\n" +
1404 "\n"
1405 };
1406
1407 String expected13ProblemLog =
1408 "----------\n" +
1409 "1. ERROR in X.java (at line 1)\n" +
1410 " public class X {\n" +
1411 " ^\n" +
1412 "Syntax error, insert \"}\" to complete ClassBody\n" +
1413 "----------\n" +
1414 "2. ERROR in X.java (at line 2)\n" +
1415 " void foo(int .. aaa){\n" +
1416 " ^^\n" +
1417 "Syntax error on tokens, delete these tokens\n" +
1418 "----------\n" +
1419 "3. ERROR in X.java (at line 4)\n" +
1420 " }\n" +
1421 " ^\n" +
1422 "Syntax error on token \"}\", delete this token\n" +
1423 "----------\n";
1424 String expected14ProblemLog =
1425 expected13ProblemLog;
1426
1427 String expected15ProblemLog =
1428 "----------\n" +
1429 "1. ERROR in X.java (at line 1)\n" +
1430 " public class X {\n" +
1431 " ^\n" +
1432 "Syntax error, insert \"}\" to complete ClassBody\n" +
1433 "----------\n" +
1434 "2. ERROR in X.java (at line 2)\n" +
1435 " void foo(int .. aaa){\n" +
1436 " ^^\n" +
1437 "Syntax error on tokens, delete these tokens\n" +
1438 "----------\n" +
1439 "3. ERROR in X.java (at line 4)\n" +
1440 " }\n" +
1441 " ^\n" +
1442 "Syntax error on token \"}\", delete this token\n" +
1443 "----------\n";
1444
1445 runComplianceParserTest(
1446 testFiles,
1447 expected13ProblemLog,
1448 expected14ProblemLog,
1449 expected15ProblemLog
1450 );
1451 }
test0031()1452 public void test0031() {
1453 String[] testFiles = new String[] {
1454 "X.java",
1455 "public class X {\n" +
1456 " void foo(int ... aaa bbb){\n" +
1457 " }\n" +
1458 "}\n" +
1459 "\n"
1460 };
1461
1462 String expected13ProblemLog =
1463 "----------\n" +
1464 "1. ERROR in X.java (at line 1)\n" +
1465 " public class X {\n" +
1466 " ^\n" +
1467 "Syntax error, insert \"}\" to complete ClassBody\n" +
1468 "----------\n" +
1469 "2. ERROR in X.java (at line 2)\n" +
1470 " void foo(int ... aaa bbb){\n" +
1471 " ^^^^^^^^^^^\n" +
1472 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
1473 "----------\n" +
1474 "3. ERROR in X.java (at line 2)\n" +
1475 " void foo(int ... aaa bbb){\n" +
1476 " ^^^^^^^\n" +
1477 "Syntax error on token(s), misplaced construct(s)\n" +
1478 "----------\n" +
1479 "4. ERROR in X.java (at line 4)\n" +
1480 " }\n" +
1481 " ^\n" +
1482 "Syntax error on token \"}\", delete this token\n" +
1483 "----------\n";
1484 String expected14ProblemLog =
1485 expected13ProblemLog;
1486
1487 String expected15ProblemLog =
1488 "----------\n" +
1489 "1. ERROR in X.java (at line 1)\n" +
1490 " public class X {\n" +
1491 " ^\n" +
1492 "Syntax error, insert \"}\" to complete ClassBody\n" +
1493 "----------\n" +
1494 "2. ERROR in X.java (at line 2)\n" +
1495 " void foo(int ... aaa bbb){\n" +
1496 " ^^^\n" +
1497 "Syntax error on token \"bbb\", delete this token\n" +
1498 "----------\n" +
1499 "3. ERROR in X.java (at line 4)\n" +
1500 " }\n" +
1501 " ^\n" +
1502 "Syntax error on token \"}\", delete this token\n" +
1503 "----------\n";
1504
1505 runComplianceParserTest(
1506 testFiles,
1507 expected13ProblemLog,
1508 expected14ProblemLog,
1509 expected15ProblemLog
1510 );
1511 }
_test0032()1512 public void _test0032() {
1513 String[] testFiles = new String[] {
1514 "X.java",
1515 "public class X <T1 extends String, T2 extends Y {\n" +
1516 " \n" +
1517 "}\n"
1518 };
1519
1520 String expected13ProblemLog =
1521 "----------\n" +
1522 "1. ERROR in X.java (at line 1)\n" +
1523 " public class X <T1 extends String, T2 extends Y {\n" +
1524 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1525 "Syntax error on token(s), misplaced construct(s)\n" +
1526 "----------\n" +
1527 "2. ERROR in X.java (at line 1)\n" +
1528 " public class X <T1 extends String, T2 extends Y {\n" +
1529 " ^\n" +
1530 "Y cannot be resolved to a type\n" +
1531 "----------\n";
1532 String expected14ProblemLog =
1533 expected13ProblemLog;
1534
1535 String expected15ProblemLog =
1536 "----------\n" +
1537 "1. WARNING in X.java (at line 1)\n" +
1538 " public class X <T1 extends String, T2 extends Y {\n" +
1539 " ^^^^^^\n" +
1540 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
1541 "----------\n" +
1542 "2. ERROR in X.java (at line 1)\n" +
1543 " public class X <T1 extends String, T2 extends Y {\n" +
1544 " ^\n" +
1545 "Syntax error, insert \">\" to complete ReferenceType1\n" +
1546 "----------\n" +
1547 "3. ERROR in X.java (at line 1)\n" +
1548 " public class X <T1 extends String, T2 extends Y {\n" +
1549 " ^\n" +
1550 "Y cannot be resolved to a type\n" +
1551 "----------\n";
1552
1553 runComplianceParserTest(
1554 testFiles,
1555 expected13ProblemLog,
1556 expected14ProblemLog,
1557 expected15ProblemLog
1558 );
1559 }
test0033()1560 public void test0033() {
1561 String[] testFiles = new String[] {
1562 "X.java",
1563 "public class X T1 extends String, T2> extends Y {\n" +
1564 " \n" +
1565 "}\n"
1566 };
1567
1568 String expected13ProblemLog =
1569 "----------\n" +
1570 "1. ERROR in X.java (at line 1)\n" +
1571 " public class X T1 extends String, T2> extends Y {\n" +
1572 " ^^\n" +
1573 "Syntax error on token \"T1\", delete this token\n" +
1574 "----------\n" +
1575 "2. ERROR in X.java (at line 1)\n" +
1576 " public class X T1 extends String, T2> extends Y {\n" +
1577 " ^^^^^^^^^^^^^^^^^^^\n" +
1578 "Syntax error on tokens, delete these tokens\n" +
1579 "----------\n";
1580 String expected14ProblemLog =
1581 expected13ProblemLog;
1582
1583 String expected15ProblemLog =
1584 "----------\n" +
1585 "1. ERROR in X.java (at line 1)\n" +
1586 " public class X T1 extends String, T2> extends Y {\n" +
1587 " ^\n" +
1588 "Syntax error on token \"X\", < expected after this token\n" +
1589 "----------\n";
1590
1591 runComplianceParserTest(
1592 testFiles,
1593 expected13ProblemLog,
1594 expected14ProblemLog,
1595 expected15ProblemLog
1596 );
1597 }
test0034()1598 public void test0034() {
1599 String[] testFiles = new String[] {
1600 "X.java",
1601 "public class X <T1 extnds String, T2> extends Y {\n" +
1602 " \n" +
1603 "}\n"
1604 };
1605
1606 String expected13ProblemLog =
1607 "----------\n" +
1608 "1. ERROR in X.java (at line 1)\n" +
1609 " public class X <T1 extnds String, T2> extends Y {\n" +
1610 " ^\n" +
1611 "Syntax error on token \"<\", { expected\n" +
1612 "----------\n" +
1613 "2. ERROR in X.java (at line 1)\n" +
1614 " public class X <T1 extnds String, T2> extends Y {\n" +
1615 " ^^^^^^^^^^^^^^^^^^^^^\n" +
1616 "Syntax error on tokens, InterfaceHeaderName expected instead\n" +
1617 "----------\n" +
1618 "3. ERROR in X.java (at line 1)\n" +
1619 " public class X <T1 extnds String, T2> extends Y {\n" +
1620 " ^^^^^^\n" +
1621 "extnds cannot be resolved to a type\n" +
1622 "----------\n" +
1623 "4. ERROR in X.java (at line 1)\n" +
1624 " public class X <T1 extnds String, T2> extends Y {\n" +
1625 " ^^^^^^\n" +
1626 "Syntax error on token \"String\", delete this token\n" +
1627 "----------\n" +
1628 "5. ERROR in X.java (at line 3)\n" +
1629 " }\n" +
1630 " ^\n" +
1631 "Syntax error, insert \"}\" to complete ClassBody\n" +
1632 "----------\n";
1633 String expected14ProblemLog =
1634 expected13ProblemLog;
1635
1636 String expected15ProblemLog =
1637 "----------\n" +
1638 "1. ERROR in X.java (at line 1)\n" +
1639 " public class X <T1 extnds String, T2> extends Y {\n" +
1640 " ^^^^^^\n" +
1641 "Syntax error on token \"extnds\", extends expected\n" +
1642 "----------\n" +
1643 "2. ERROR in X.java (at line 1)\n" +
1644 " public class X <T1 extnds String, T2> extends Y {\n" +
1645 " ^^^^^^\n" +
1646 "extnds cannot be resolved to a type\n" +
1647 "----------\n";
1648
1649 runComplianceParserTest(
1650 testFiles,
1651 expected13ProblemLog,
1652 expected14ProblemLog,
1653 expected15ProblemLog
1654 );
1655 }
test0035()1656 public void test0035() {
1657 String[] testFiles = new String[] {
1658 "X.java",
1659 "public class X <T1 extends for, T2> extends Y {\n" +
1660 " \n" +
1661 "}\n"
1662 };
1663
1664 String expected13ProblemLog =
1665 "----------\n" +
1666 "1. ERROR in X.java (at line 1)\n" +
1667 " public class X <T1 extends for, T2> extends Y {\n" +
1668 " ^^^^^^^^^^^^^^^^^^^^\n" +
1669 "Syntax error on tokens, delete these tokens\n" +
1670 "----------\n";
1671 String expected14ProblemLog =
1672 expected13ProblemLog;
1673
1674 String expected15ProblemLog =
1675 "----------\n" +
1676 "1. ERROR in X.java (at line 1)\n" +
1677 " public class X <T1 extends for, T2> extends Y {\n" +
1678 " ^^^\n" +
1679 "Syntax error on token \"for\", invalid ReferenceType\n" +
1680 "----------\n";
1681
1682 runComplianceParserTest(
1683 testFiles,
1684 expected13ProblemLog,
1685 expected14ProblemLog,
1686 expected15ProblemLog
1687 );
1688 }
test0036()1689 public void test0036() {
1690 String[] testFiles = new String[] {
1691 "X.java",
1692 "public class X {\n" +
1693 " public <T1 extends String, T2> foo(){\n" +
1694 " }\n" +
1695 "}\n"
1696 };
1697
1698 String expected13ProblemLog =
1699 "----------\n" +
1700 "1. ERROR in X.java (at line 2)\n" +
1701 " public <T1 extends String, T2> foo(){\n" +
1702 " ^^^^^^^^^^^^^^^^^^^^^\n" +
1703 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
1704 "----------\n" +
1705 "2. ERROR in X.java (at line 2)\n" +
1706 " public <T1 extends String, T2> foo(){\n" +
1707 " ^^^^^\n" +
1708 "Return type for the method is missing\n" +
1709 "----------\n";
1710 String expected14ProblemLog =
1711 expected13ProblemLog;
1712
1713 String expected15ProblemLog =
1714 "----------\n" +
1715 "1. WARNING in X.java (at line 2)\n" +
1716 " public <T1 extends String, T2> foo(){\n" +
1717 " ^^^^^^\n" +
1718 "The type parameter T1 should not be bounded by the final type String. Final types cannot be further extended\n" +
1719 "----------\n" +
1720 "2. ERROR in X.java (at line 2)\n" +
1721 " public <T1 extends String, T2> foo(){\n" +
1722 " ^^^^^\n" +
1723 "Return type for the method is missing\n" +
1724 "----------\n";
1725
1726 runComplianceParserTest(
1727 testFiles,
1728 expected13ProblemLog,
1729 expected14ProblemLog,
1730 expected15ProblemLog
1731 );
1732 }
test0037()1733 public void test0037() {
1734 String[] testFiles = new String[] {
1735 "X.java",
1736 "public class X {\n" +
1737 " public <T1 extnds String, T2> int foo(){\n" +
1738 " }\n" +
1739 "}\n"
1740 };
1741
1742 String expected13ProblemLog =
1743 "----------\n" +
1744 "1. ERROR in X.java (at line 2)\n" +
1745 " public <T1 extnds String, T2> int foo(){\n" +
1746 " ^^^\n" +
1747 "Syntax error on token(s), misplaced construct(s)\n" +
1748 "----------\n" +
1749 "2. ERROR in X.java (at line 2)\n" +
1750 " public <T1 extnds String, T2> int foo(){\n" +
1751 " ^^\n" +
1752 "T1 cannot be resolved to a type\n" +
1753 "----------\n" +
1754 "3. ERROR in X.java (at line 2)\n" +
1755 " public <T1 extnds String, T2> int foo(){\n" +
1756 " ^\n" +
1757 "Syntax error on token \">\", ; expected\n" +
1758 "----------\n";
1759 String expected14ProblemLog =
1760 expected13ProblemLog;
1761
1762 String expected15ProblemLog =
1763 "----------\n" +
1764 "1. ERROR in X.java (at line 2)\n" +
1765 " public <T1 extnds String, T2> int foo(){\n" +
1766 " ^^\n" +
1767 "T1 cannot be resolved to a type\n" +
1768 "----------\n" +
1769 "2. ERROR in X.java (at line 2)\n" +
1770 " public <T1 extnds String, T2> int foo(){\n" +
1771 " ^^^^^^\n" +
1772 "Syntax error on token \"extnds\", extends expected\n" +
1773 "----------\n";
1774
1775 runComplianceParserTest(
1776 testFiles,
1777 expected13ProblemLog,
1778 expected14ProblemLog,
1779 expected15ProblemLog
1780 );
1781 }
test0038()1782 public void test0038() {
1783 String[] testFiles = new String[] {
1784 "X.java",
1785 "public class X {\n" +
1786 " public <T1 extends String T2> int foo(){\n" +
1787 " }\n" +
1788 "}\n"
1789 };
1790
1791 String expected13ProblemLog =
1792 "----------\n" +
1793 "1. ERROR in X.java (at line 2)\n" +
1794 " public <T1 extends String T2> int foo(){\n" +
1795 " ^^^^^^^^^^^\n" +
1796 "Syntax error on token(s), misplaced construct(s)\n" +
1797 "----------\n" +
1798 "2. ERROR in X.java (at line 2)\n" +
1799 " public <T1 extends String T2> int foo(){\n" +
1800 " ^\n" +
1801 "Syntax error on token \">\", ; expected\n" +
1802 "----------\n";
1803 String expected14ProblemLog =
1804 expected13ProblemLog;
1805
1806 String expected15ProblemLog =
1807 "----------\n" +
1808 "1. ERROR in X.java (at line 2)\n" +
1809 " public <T1 extends String T2> int foo(){\n" +
1810 " ^^\n" +
1811 "Syntax error on token \"T2\", delete this token\n" +
1812 "----------\n";
1813
1814 runComplianceParserTest(
1815 testFiles,
1816 expected13ProblemLog,
1817 expected14ProblemLog,
1818 expected15ProblemLog
1819 );
1820 }
test0039()1821 public void test0039() {
1822 String[] testFiles = new String[] {
1823 "X.java",
1824 "public class X {\n" +
1825 " Z Y1, Y2> var;\n" +
1826 "}\n"
1827 };
1828
1829 String expected13ProblemLog =
1830 "----------\n" +
1831 "1. ERROR in X.java (at line 2)\n" +
1832 " Z Y1, Y2> var;\n" +
1833 " ^\n" +
1834 "Z cannot be resolved to a type\n" +
1835 "----------\n" +
1836 "2. ERROR in X.java (at line 2)\n" +
1837 " Z Y1, Y2> var;\n" +
1838 " ^\n" +
1839 "Syntax error on token \">\", , expected\n" +
1840 "----------\n";
1841 String expected14ProblemLog =
1842 expected13ProblemLog;
1843
1844 String expected15ProblemLog =
1845 "----------\n" +
1846 "1. ERROR in X.java (at line 2)\n" +
1847 " Z Y1, Y2> var;\n" +
1848 " ^\n" +
1849 "Z cannot be resolved to a type\n" +
1850 "----------\n" +
1851 "2. ERROR in X.java (at line 2)\n" +
1852 " Z Y1, Y2> var;\n" +
1853 " ^\n" +
1854 "Syntax error on token \">\", , expected\n" +
1855 "----------\n";
1856
1857 runComplianceParserTest(
1858 testFiles,
1859 expected13ProblemLog,
1860 expected14ProblemLog,
1861 expected15ProblemLog
1862 );
1863 }
test0040()1864 public void test0040() {
1865 String[] testFiles = new String[] {
1866 "X.java",
1867 "public class X {\n" +
1868 " Z <Y1, Y2 var;\n" +
1869 "}\n"
1870 };
1871
1872 String expected13ProblemLog =
1873 "----------\n" +
1874 "1. ERROR in X.java (at line 2)\n" +
1875 " Z <Y1, Y2 var;\n" +
1876 " ^^^^^^^\n" +
1877 "Syntax error on token(s), misplaced construct(s)\n" +
1878 "----------\n" +
1879 "2. ERROR in X.java (at line 2)\n" +
1880 " Z <Y1, Y2 var;\n" +
1881 " ^^\n" +
1882 "Y2 cannot be resolved to a type\n" +
1883 "----------\n";
1884 String expected14ProblemLog =
1885 expected13ProblemLog;
1886
1887 String expected15ProblemLog =
1888 "----------\n" +
1889 "1. ERROR in X.java (at line 2)\n" +
1890 " Z <Y1, Y2 var;\n" +
1891 " ^^\n" +
1892 "Syntax error, insert \">\" to complete ReferenceType1\n" +
1893 "----------\n" +
1894 "2. ERROR in X.java (at line 2)\n" +
1895 " Z <Y1, Y2 var;\n" +
1896 " ^^\n" +
1897 "Y2 cannot be resolved to a type\n" +
1898 "----------\n";
1899
1900 runComplianceParserTest(
1901 testFiles,
1902 expected13ProblemLog,
1903 expected14ProblemLog,
1904 expected15ProblemLog
1905 );
1906 }
test0041()1907 public void test0041() {
1908 String[] testFiles = new String[] {
1909 "X.java",
1910 "public class X {\n" +
1911 " Z <Y1, for Y2> var;\n" +
1912 "}\n"
1913 };
1914
1915 String expected13ProblemLog =
1916 "----------\n" +
1917 "1. ERROR in X.java (at line 2)\n" +
1918 " Z <Y1, for Y2> var;\n" +
1919 " ^^^^^^^^^^^^\n" +
1920 "Syntax error on tokens, delete these tokens\n" +
1921 "----------\n";
1922 String expected14ProblemLog =
1923 expected13ProblemLog;
1924
1925 String expected15ProblemLog =
1926 "----------\n" +
1927 "1. ERROR in X.java (at line 2)\n" +
1928 " Z <Y1, for Y2> var;\n" +
1929 " ^^^\n" +
1930 "Syntax error on token \"for\", delete this token\n" +
1931 "----------\n";
1932
1933 runComplianceParserTest(
1934 testFiles,
1935 expected13ProblemLog,
1936 expected14ProblemLog,
1937 expected15ProblemLog
1938 );
1939 }
1940 //TODO: Enable after Bug 552769 is fixed
test0042()1941 public void test0042() {
1942 String[] testFiles = new String[] {
1943 "X.java",
1944 "void ___eval() {\n" +
1945 " new Runnable() {\n" +
1946 " int ___run() throws Throwable {\n" +
1947 " return blah;\n" +
1948 " }\n" +
1949 " private String blarg;\n" +
1950 " public void run() {\n" +
1951 " }\n" +
1952 " };\n" +
1953 "}\n" +
1954 "public class X {\n" +
1955 " private static int x;\n" +
1956 " private String blah;\n" +
1957 " public static void main(String[] args) {\n" +
1958 " }\n" +
1959 " public void hello() {\n" +
1960 " }\n" +
1961 " public boolean blah() {\n" +
1962 " return false;\n" +
1963 " }\n" +
1964 " public void foo() {\n" +
1965 " }\n" +
1966 "}\n"
1967 };
1968
1969 String expected13ProblemLog =
1970 "----------\n" +
1971 "1. ERROR in X.java (at line 1)\n" +
1972 " void ___eval() {\n" +
1973 " ^^^^^^^^^^^^^^\n" +
1974 "Syntax error on tokens, delete these tokens\n" +
1975 "----------\n" +
1976 "2. ERROR in X.java (at line 2)\n" +
1977 " new Runnable() {\n" +
1978 " int ___run() throws Throwable {\n" +
1979 " return blah;\n" +
1980 " }\n" +
1981 " private String blarg;\n" +
1982 " public void run() {\n" +
1983 " }\n" +
1984 " };\n" +
1985 "}\n" +
1986 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1987 "Syntax error on tokens, delete these tokens\n" +
1988 "----------\n";
1989 @SuppressWarnings("unused")
1990 String expected14ProblemLog =
1991 expected13ProblemLog;
1992
1993 @SuppressWarnings("unused")
1994 String expected15ProblemLog =
1995 "----------\n" +
1996 "1. ERROR in X.java (at line 1)\n" +
1997 " void ___eval() {\n" +
1998 " ^^^^\n" +
1999 "Syntax error on token \"void\", @ expected\n" +
2000 "----------\n" +
2001 "2. ERROR in X.java (at line 1)\n" +
2002 " void ___eval() {\n" +
2003 " ^\n" +
2004 "Syntax error on token \")\", delete this token\n" +
2005 "----------\n" +
2006 "3. ERROR in X.java (at line 9)\n" +
2007 " };\n" +
2008 "}\n" +
2009 " ^^^^\n" +
2010 "Syntax error on tokens, delete these tokens\n" +
2011 "----------\n" +
2012 "4. ERROR in X.java (at line 23)\n" +
2013 " }\n" +
2014 " ^\n" +
2015 "Syntax error, insert \"}\" to complete ClassBody\n" +
2016 "----------\n" +
2017 "5. ERROR in X.java (at line 23)\n" +
2018 " }\n" +
2019 " ^\n" +
2020 "Syntax error, insert \"}\" to complete MemberValue\n" +
2021 "----------\n" +
2022 "6. ERROR in X.java (at line 23)\n" +
2023 " }\n" +
2024 " ^\n" +
2025 "Syntax error, insert \")\" to complete Modifiers\n" +
2026 "----------\n" +
2027 "7. ERROR in X.java (at line 23)\n" +
2028 " }\n" +
2029 " ^\n" +
2030 "Syntax error, insert \"enum Identifier\" to complete EnumHeader\n" +
2031 "----------\n" +
2032 "8. ERROR in X.java (at line 23)\n" +
2033 " }\n" +
2034 " ^\n" +
2035 "Syntax error, insert \"EnumBody\" to complete CompilationUnit\n" +
2036 "----------\n";
2037
2038 String expectedJ14ProblemLog =
2039 "----------\n" +
2040 "1. ERROR in X.java (at line 1)\n" +
2041 " void ___eval() {\n" +
2042 " ^^^^\n" +
2043 "Syntax error on token \"void\", record expected\n" +
2044 "----------\n" +
2045 "2. ERROR in X.java (at line 2)\n" +
2046 " new Runnable() {\n" +
2047 " ^^^\n" +
2048 "Syntax error on token \"new\", record expected\n" +
2049 "----------\n";
2050 runComplianceParserTest(
2051 testFiles,
2052 expected13ProblemLog,
2053 expected14ProblemLog,
2054 (this.complianceLevel < ClassFileConstants.JDK14 ? expected15ProblemLog : expectedJ14ProblemLog)
2055 );
2056 }
2057 /*
2058 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=72942
2059 */
test0043()2060 public void test0043() {
2061 String[] testFiles = new String[] {
2062 "X.java",
2063 "public class X {\n" +
2064 "}\n" +
2065 "public static void foo(){}\n" +
2066 "\n"
2067 };
2068
2069 String expected13ProblemLog =
2070 "----------\n" +
2071 "1. ERROR in X.java (at line 2)\n" +
2072 " }\n" +
2073 " ^\n" +
2074 "Syntax error on token \"}\", delete this token\n" +
2075 "----------\n" +
2076 "2. ERROR in X.java (at line 3)\n" +
2077 " public static void foo(){}\n" +
2078 " ^\n" +
2079 "Syntax error, insert \"}\" to complete ClassBody\n" +
2080 "----------\n";
2081 String expected14ProblemLog =
2082 expected13ProblemLog;
2083
2084 String expected15ProblemLog =
2085 expected13ProblemLog;
2086
2087 runComplianceParserTest(
2088 testFiles,
2089 expected13ProblemLog,
2090 expected14ProblemLog,
2091 expected15ProblemLog
2092 );
2093 }
2094 /*
2095 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62472
2096 */
test0044()2097 public void test0044() {
2098 String[] testFiles = new String[] {
2099 "X.java",
2100 "public class X {\n" +
2101 " public <T> X(T t){\n" +
2102 " System.out.println(t);\n" +
2103 " }\n" +
2104 " }\n" +
2105 " public static void main(String[] args) {\n" +
2106 " class Local extends X {\n" +
2107 " Local() {\n" +
2108 " <String>super(\"SUCCESS\");\n" +
2109 " }\n" +
2110 " }\n" +
2111 " new Local();\n" +
2112 " }\n" +
2113 "}\n"
2114 };
2115
2116 String expected13ProblemLog =
2117 "----------\n" +
2118 "1. ERROR in X.java (at line 2)\n" +
2119 " public <T> X(T t){\n" +
2120 " ^\n" +
2121 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
2122 "----------\n" +
2123 "2. ERROR in X.java (at line 5)\n" +
2124 " }\n" +
2125 " ^\n" +
2126 "Syntax error on token \"}\", delete this token\n" +
2127 "----------\n" +
2128 "3. ERROR in X.java (at line 9)\n" +
2129 " <String>super(\"SUCCESS\");\n" +
2130 " ^^^^^^\n" +
2131 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
2132 "----------\n" +
2133 "4. ERROR in X.java (at line 9)\n" +
2134 " <String>super(\"SUCCESS\");\n" +
2135 " ^^^^^^\n" +
2136 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
2137 "----------\n";
2138 String expected14ProblemLog =
2139 expected13ProblemLog;
2140
2141 String expected15ProblemLog =
2142 "----------\n" +
2143 "1. ERROR in X.java (at line 5)\n" +
2144 " }\n" +
2145 " ^\n" +
2146 "Syntax error on token \"}\", delete this token\n" +
2147 "----------\n";
2148
2149 runComplianceParserTest(
2150 testFiles,
2151 expected13ProblemLog,
2152 expected14ProblemLog,
2153 expected15ProblemLog
2154 );
2155 }
2156 /*
2157 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62472
2158 */
test0045()2159 public void test0045() {
2160 String[] testFiles = new String[] {
2161 "X.java",
2162 "public class X {\n" +
2163 " public void foo(){\n" +
2164 " }\n" +
2165 " }\n" +
2166 " public void bar() {\n" +
2167 " }\n" +
2168 "}\n"
2169 };
2170
2171 String expected13ProblemLog =
2172 "----------\n" +
2173 "1. ERROR in X.java (at line 4)\n" +
2174 " }\n" +
2175 " ^\n" +
2176 "Syntax error on token \"}\", delete this token\n" +
2177 "----------\n";
2178 String expected14ProblemLog =
2179 expected13ProblemLog;
2180
2181 String expected15ProblemLog =
2182 expected13ProblemLog;
2183
2184 runComplianceParserTest(
2185 testFiles,
2186 expected13ProblemLog,
2187 expected14ProblemLog,
2188 expected15ProblemLog
2189 );
2190 }
2191 /*
2192 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74519
2193 */
test0046()2194 public void test0046() {
2195 String[] testFiles = new String[] {
2196 "X.java",
2197 "public @interface X {\n" +
2198 " String annName();\n" +
2199 "}"
2200 };
2201
2202 String expected13ProblemLog =
2203 "----------\n" +
2204 "1. ERROR in X.java (at line 1)\n" +
2205 " public @interface X {\n" +
2206 " ^\n" +
2207 "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" +
2208 "----------\n";
2209 String expected14ProblemLog =
2210 expected13ProblemLog;
2211
2212 String expected15ProblemLog = "";
2213
2214 runComplianceParserTest(
2215 testFiles,
2216 expected13ProblemLog,
2217 expected14ProblemLog,
2218 expected15ProblemLog
2219 );
2220 }
2221 /*
2222 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74519
2223 */
test0047()2224 public void test0047() {
2225 String[] testFiles = new String[] {
2226 "A.java",
2227 "public @interface A {}",
2228 "X.java",
2229 "@A public class X {\n" +
2230 "}"
2231 };
2232
2233 String expected13ProblemLog =
2234 "----------\n" +
2235 "1. ERROR in A.java (at line 1)\n" +
2236 " public @interface A {}\n" +
2237 " ^\n" +
2238 "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" +
2239 "----------\n" +
2240 "----------\n" +
2241 "1. ERROR in X.java (at line 1)\n" +
2242 " @A public class X {\n" +
2243 " ^^\n" +
2244 "Syntax error, annotations are only available if source level is 1.5 or greater\n" +
2245 "----------\n";
2246 String expected14ProblemLog =
2247 expected13ProblemLog;
2248
2249 String expected15ProblemLog = "";
2250
2251 runComplianceParserTest(
2252 testFiles,
2253 expected13ProblemLog,
2254 expected14ProblemLog,
2255 expected15ProblemLog
2256 );
2257 }
test0048()2258 public void test0048() {
2259 String[] testFiles = new String[] {
2260 "X.java",
2261 "public class X {\n" +
2262 " void foo(X ... arg[]){\n" +
2263 " }\n" +
2264 "}\n"
2265 };
2266
2267 String expected13ProblemLog =
2268 "----------\n" +
2269 "1. ERROR in X.java (at line 2)\n" +
2270 " void foo(X ... arg[]){\n" +
2271 " ^^^^^^^^^\n" +
2272 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
2273 "----------\n";
2274 String expected14ProblemLog =
2275 expected13ProblemLog;
2276
2277 String expected15ProblemLog =
2278 "----------\n" +
2279 "1. ERROR in X.java (at line 2)\n" +
2280 " void foo(X ... arg[]){\n" +
2281 " ^^^\n" +
2282 "Extended dimensions are illegal for a variable argument\n" +
2283 "----------\n";
2284
2285 runComplianceParserTest(
2286 testFiles,
2287 expected13ProblemLog,
2288 expected14ProblemLog,
2289 expected15ProblemLog
2290 );
2291 }
test0049()2292 public void test0049() {
2293 String[] testFiles = new String[] {
2294 "X.java",
2295 "@interface MyAnn {\n" +
2296 " String value1() default \"\";\n" +
2297 " String value2();\n" +
2298 "}\n" +
2299 "class ZZZ {} \n" +
2300 "public @MyAnn(\"\",\"\") class Test { \n" +
2301 "}\n"
2302 };
2303
2304 String expected13ProblemLog =
2305 "----------\n" +
2306 "1. ERROR in X.java (at line 1)\n" +
2307 " @interface MyAnn {\n" +
2308 " ^^^^^\n" +
2309 "Syntax error, annotation declarations are only available if source level is 1.5 or greater\n" +
2310 "----------\n" +
2311 "2. ERROR in X.java (at line 6)\n" +
2312 " public @MyAnn(\"\",\"\") class Test { \n" +
2313 " ^^\n" +
2314 "Syntax error, insert \")\" to complete Modifier\n" +
2315 "----------\n" +
2316 "3. ERROR in X.java (at line 6)\n" +
2317 " public @MyAnn(\"\",\"\") class Test { \n" +
2318 " ^^\n" +
2319 "The attribute value is undefined for the annotation type MyAnn\n" +
2320 "----------\n" +
2321 "4. ERROR in X.java (at line 6)\n" +
2322 " public @MyAnn(\"\",\"\") class Test { \n" +
2323 " ^^^^\n" +
2324 "The public type Test must be defined in its own file\n" +
2325 "----------\n";
2326 String expected14ProblemLog =
2327 expected13ProblemLog;
2328
2329 String expected15ProblemLog =
2330 "----------\n" +
2331 "1. ERROR in X.java (at line 6)\n" +
2332 " public @MyAnn(\"\",\"\") class Test { \n" +
2333 " ^^\n" +
2334 "The attribute value is undefined for the annotation type MyAnn\n" +
2335 "----------\n" +
2336 "2. ERROR in X.java (at line 6)\n" +
2337 " public @MyAnn(\"\",\"\") class Test { \n" +
2338 " ^\n" +
2339 "Syntax error on token \",\", < expected\n" +
2340 "----------\n" +
2341 "3. ERROR in X.java (at line 6)\n" +
2342 " public @MyAnn(\"\",\"\") class Test { \n" +
2343 " ^^^^\n" +
2344 "The public type Test must be defined in its own file\n" +
2345 "----------\n";
2346
2347 runComplianceParserTest(
2348 testFiles,
2349 expected13ProblemLog,
2350 expected14ProblemLog,
2351 expected15ProblemLog
2352 );
2353 }
test0050()2354 public void test0050() {
2355 String[] testFiles = new String[] {
2356 "X.java",
2357 "public class X {\n" +
2358 " void foo(List<String>... args) {}\n" +
2359 "}\n"
2360 };
2361
2362 String expected13ProblemLog =
2363 "----------\n" +
2364 "1. ERROR in X.java (at line 2)\n" +
2365 " void foo(List<String>... args) {}\n" +
2366 " ^^^^^^^^^^^^^^^^^^^^\n" +
2367 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
2368 "----------\n" +
2369 "2. ERROR in X.java (at line 2)\n" +
2370 " void foo(List<String>... args) {}\n" +
2371 " ^^^^\n" +
2372 "List cannot be resolved to a type\n" +
2373 "----------\n" +
2374 "3. ERROR in X.java (at line 2)\n" +
2375 " void foo(List<String>... args) {}\n" +
2376 " ^^^^^^\n" +
2377 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
2378 "----------\n";
2379 String expected14ProblemLog =
2380 expected13ProblemLog;
2381
2382 String expected15ProblemLog =
2383 "----------\n" +
2384 "1. ERROR in X.java (at line 2)\n" +
2385 " void foo(List<String>... args) {}\n" +
2386 " ^^^^\n" +
2387 "List cannot be resolved to a type\n" +
2388 "----------\n";
2389 String expected17ProblemLog =
2390 "----------\n" +
2391 "1. ERROR in X.java (at line 2)\n" +
2392 " void foo(List<String>... args) {}\n" +
2393 " ^^^^\n" +
2394 "List cannot be resolved to a type\n" +
2395 "----------\n" +
2396 "2. WARNING in X.java (at line 2)\n" +
2397 " void foo(List<String>... args) {}\n" +
2398 " ^^^^\n" +
2399 "Type safety: Potential heap pollution via varargs parameter args\n" +
2400 "----------\n";
2401
2402 runComplianceParserTest(
2403 testFiles,
2404 expected13ProblemLog,
2405 expected14ProblemLog,
2406 expected15ProblemLog,
2407 expected17ProblemLog
2408 );
2409 }
test0051()2410 public void test0051() {
2411 String[] testFiles = new String[] {
2412 "X.java",
2413 "public class X {\n" +
2414 " void foo(java.util.List2<String>... args) {}\n" +
2415 "}\n"
2416 };
2417
2418 String expected13ProblemLog =
2419 "----------\n" +
2420 "1. ERROR in X.java (at line 2)\n" +
2421 " void foo(java.util.List2<String>... args) {}\n" +
2422 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2423 "Syntax error, varargs are only available if source level is 1.5 or greater\n" +
2424 "----------\n" +
2425 "2. ERROR in X.java (at line 2)\n" +
2426 " void foo(java.util.List2<String>... args) {}\n" +
2427 " ^^^^^^^^^^^^^^^\n" +
2428 "java.util.List2 cannot be resolved to a type\n" +
2429 "----------\n" +
2430 "3. ERROR in X.java (at line 2)\n" +
2431 " void foo(java.util.List2<String>... args) {}\n" +
2432 " ^^^^^^\n" +
2433 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
2434 "----------\n";
2435 String expected14ProblemLog =
2436 expected13ProblemLog;
2437
2438 String expected15ProblemLog =
2439 "----------\n" +
2440 "1. ERROR in X.java (at line 2)\n" +
2441 " void foo(java.util.List2<String>... args) {}\n" +
2442 " ^^^^^^^^^^^^^^^\n" +
2443 "java.util.List2 cannot be resolved to a type\n" +
2444 "----------\n";
2445
2446 runComplianceParserTest(
2447 testFiles,
2448 expected13ProblemLog,
2449 expected14ProblemLog,
2450 expected15ProblemLog
2451 );
2452 }
2453 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=154811
test0052()2454 public void test0052() {
2455 String[] testFiles = new String[] {
2456 "X.java",
2457 "public class X {\n" +
2458 " void foo1() {\n" +
2459 " class Y {\n" +
2460 " }\n" +
2461 " void foo2() {\n" +
2462 " }\n" +
2463 " class Z<T> { \n" +
2464 " }\n" +
2465 " }\n" +
2466 "} \n"
2467 };
2468
2469 String expected13ProblemLog =
2470 "----------\n" +
2471 "1. ERROR in X.java (at line 5)\n" +
2472 " void foo2() {\n" +
2473 " ^^^^\n" +
2474 "Syntax error on token \"void\", new expected\n" +
2475 "----------\n" +
2476 "2. ERROR in X.java (at line 7)\n" +
2477 " class Z<T> { \n" +
2478 " ^^^^^\n" +
2479 "Syntax error on token \"class\", invalid AssignmentOperator\n" +
2480 "----------\n" +
2481 "3. ERROR in X.java (at line 7)\n" +
2482 " class Z<T> { \n" +
2483 " ^\n" +
2484 "Syntax error on token \">\", ; expected\n" +
2485 "----------\n";
2486 String expected14ProblemLog =
2487 expected13ProblemLog;
2488
2489 String expected15ProblemLog =
2490 "----------\n" +
2491 "1. ERROR in X.java (at line 5)\n" +
2492 " void foo2() {\n" +
2493 " ^^^^\n" +
2494 "Syntax error on token \"void\", new expected\n" +
2495 "----------\n" +
2496 "2. ERROR in X.java (at line 6)\n" +
2497 " }\n" +
2498 " ^\n" +
2499 "Syntax error, insert \";\" to complete Statement\n" +
2500 "----------\n";
2501
2502 String expectedJ14ProblemLog =
2503 "----------\n" +
2504 "1. ERROR in X.java (at line 5)\n" +
2505 " void foo2() {\n" +
2506 " ^^^^\n" +
2507 "Syntax error on token \"void\", record expected\n" +
2508 "----------\n";
2509
2510 runComplianceParserTest(
2511 testFiles,
2512 expected13ProblemLog,
2513 expected14ProblemLog,
2514 (this.complianceLevel < ClassFileConstants.JDK14 ? expected15ProblemLog : expectedJ14ProblemLog)
2515 );
2516 }
2517 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=42243
test0053()2518 public void test0053() {
2519 String[] testFiles = new String[] {
2520 "X.java",
2521 "public class X {\n" +
2522 " public static void main(String[] args) {\n" +
2523 " assert true;\n" +
2524 " }\n" +
2525 "}\n"
2526 };
2527
2528 String expected13ProblemLog =
2529 "----------\n" +
2530 "1. WARNING in X.java (at line 3)\n" +
2531 " assert true;\n" +
2532 " ^^^^^^\n" +
2533 "\'assert\' should not be used as an identifier, since it is a reserved keyword from source level 1.4 on\n" +
2534 "----------\n" +
2535 "2. ERROR in X.java (at line 3)\n" +
2536 " assert true;\n" +
2537 " ^^^^^^\n" +
2538 "Syntax error on token \"assert\", AssignmentOperator expected after this token\n" +
2539 "----------\n";
2540 String expected14ProblemLog =
2541 "";
2542
2543 String expected15ProblemLog =
2544 expected14ProblemLog;
2545
2546 runComplianceParserTest(
2547 testFiles,
2548 expected13ProblemLog,
2549 expected14ProblemLog,
2550 expected15ProblemLog
2551 );
2552 }
test0054()2553 public void test0054() {
2554 String[] testFiles = new String[] {
2555 "X.java",
2556 "public class X {\n" +
2557 " public static void main(String[] args) {\n" +
2558 " try (int i = 0) {};\n" +
2559 " }\n" +
2560 "}\n"
2561 };
2562
2563 String expected13ProblemLog =
2564 "----------\n" +
2565 "1. ERROR in X.java (at line 3)\n" +
2566 " try (int i = 0) {};\n" +
2567 " ^^^^^^^^^\n" +
2568 "Resource specification not allowed here for source level below 1.7\n" +
2569 "----------\n";
2570 String expected14ProblemLog =
2571 expected13ProblemLog;
2572
2573 String expected15ProblemLog =
2574 expected14ProblemLog;
2575
2576 String expected17ProblemLog =
2577 "----------\n" +
2578 "1. ERROR in X.java (at line 3)\n" +
2579 " try (int i = 0) {};\n" +
2580 " ^^^\n" +
2581 "The resource type int does not implement java.lang.AutoCloseable\n" +
2582 "----------\n";
2583 runComplianceParserTest(
2584 testFiles,
2585 expected13ProblemLog,
2586 expected14ProblemLog,
2587 expected15ProblemLog,
2588 expected17ProblemLog
2589 );
2590 }
2591 // test that use of multi-catch is flagged accordingly
test0055()2592 public void test0055() {
2593 if(this.complianceLevel >= ClassFileConstants.JDK1_7) {
2594 return;
2595 }
2596 String[] testFiles = new String[] {
2597 "X.java",
2598 "import java.io.*;\n" +
2599 "public class X {\n" +
2600 " public static void main(String[] args) {\n" +
2601 " try {\n" +
2602 " System.out.println();\n" +
2603 " Reader r = new FileReader(args[0]);\n" +
2604 " r.read();\n" +
2605 " } catch(IOException | RuntimeException e) {\n" +
2606 " e.printStackTrace();\n" +
2607 " }\n" +
2608 " }\n" +
2609 "}\n"
2610 };
2611
2612 String expected13ProblemLog =
2613 "----------\n" +
2614 "1. ERROR in X.java (at line 8)\n" +
2615 " } catch(IOException | RuntimeException e) {\n" +
2616 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2617 "Multi-catch parameters are not allowed for source level below 1.7\n" +
2618 "----------\n";
2619 String expected14ProblemLog =
2620 expected13ProblemLog;
2621
2622 String expected15ProblemLog =
2623 expected14ProblemLog;
2624
2625 runComplianceParserTest(
2626 testFiles,
2627 expected13ProblemLog,
2628 expected14ProblemLog,
2629 expected15ProblemLog
2630 );
2631 }
2632 // rethrow should not be precisely computed in 1.6-
test0056()2633 public void test0056() {
2634 String[] testFiles = new String[] {
2635 "X.java",
2636 "public class X {\n" +
2637 " public static void main(String[] args) {\n" +
2638 " try {\n" +
2639 " throw new DaughterOfFoo();\n"+
2640 " } catch(Foo e) {\n" +
2641 " try {\n" +
2642 " throw e;\n" +
2643 " } catch (SonOfFoo e1) {\n" +
2644 " e1.printStackTrace();\n" +
2645 " } catch (Foo e1) {}\n" +
2646 " }\n" +
2647 " }\n" +
2648 "}\n"+
2649 "class Foo extends Exception {}\n"+
2650 "class SonOfFoo extends Foo {}\n"+
2651 "class DaughterOfFoo extends Foo {}\n"
2652 };
2653
2654 String expected13ProblemLog =
2655 "----------\n" +
2656 "1. WARNING in X.java (at line 14)\n" +
2657 " class Foo extends Exception {}\n" +
2658 " ^^^\n" +
2659 "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
2660 "----------\n" +
2661 "2. WARNING in X.java (at line 15)\n" +
2662 " class SonOfFoo extends Foo {}\n" +
2663 " ^^^^^^^^\n" +
2664 "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
2665 "----------\n" +
2666 "3. WARNING in X.java (at line 16)\n" +
2667 " class DaughterOfFoo extends Foo {}\n" +
2668 " ^^^^^^^^^^^^^\n" +
2669 "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
2670 "----------\n";
2671 String expected14ProblemLog =
2672 expected13ProblemLog;
2673
2674 String expected15ProblemLog =
2675 expected14ProblemLog;
2676
2677 String expected17ProblemLog =
2678 "----------\n" +
2679 "1. ERROR in X.java (at line 8)\n" +
2680 " } catch (SonOfFoo e1) {\n" +
2681 " ^^^^^^^^\n" +
2682 "Unreachable catch block for SonOfFoo. This exception is never thrown from the try statement body\n" +
2683 "----------\n" +
2684 "2. WARNING in X.java (at line 14)\n" +
2685 " class Foo extends Exception {}\n" +
2686 " ^^^\n" +
2687 "The serializable class Foo does not declare a static final serialVersionUID field of type long\n" +
2688 "----------\n" +
2689 "3. WARNING in X.java (at line 15)\n" +
2690 " class SonOfFoo extends Foo {}\n" +
2691 " ^^^^^^^^\n" +
2692 "The serializable class SonOfFoo does not declare a static final serialVersionUID field of type long\n" +
2693 "----------\n" +
2694 "4. WARNING in X.java (at line 16)\n" +
2695 " class DaughterOfFoo extends Foo {}\n" +
2696 " ^^^^^^^^^^^^^\n" +
2697 "The serializable class DaughterOfFoo does not declare a static final serialVersionUID field of type long\n" +
2698 "----------\n";
2699 runComplianceParserTest(
2700 testFiles,
2701 expected13ProblemLog,
2702 expected14ProblemLog,
2703 expected15ProblemLog,
2704 expected17ProblemLog
2705 );
2706 }
2707 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0057()2708 public void test0057() {
2709 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2710 return;
2711 }
2712 String[] testFiles = new String[] {
2713 "X.java",
2714 "interface I {\n" +
2715 " public default void foo() { System.out.println(); }\n" +
2716 "}\n"
2717 };
2718
2719 String expectedProblemLog =
2720 "----------\n" +
2721 "1. ERROR in X.java (at line 2)\n" +
2722 " public default void foo() { System.out.println(); }\n" +
2723 " ^^^^^\n" +
2724 "Default methods are allowed only at source level 1.8 or above\n" +
2725 "----------\n";
2726
2727 runComplianceParserTest(
2728 testFiles,
2729 expectedProblemLog,
2730 expectedProblemLog,
2731 expectedProblemLog,
2732 expectedProblemLog,
2733 expectedProblemLog
2734 );
2735 }
2736 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0058()2737 public void test0058() {
2738 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2739 return;
2740 }
2741 String[] testFiles = new String[] {
2742 "X.java",
2743 "interface I {\n" +
2744 " void foo(int p);\n" +
2745 "}\n" +
2746 "public class X {\n" +
2747 " I i = System::exit;\n" +
2748 "}\n"
2749 };
2750
2751 String expectedProblemLog =
2752 "----------\n" +
2753 "1. ERROR in X.java (at line 5)\n" +
2754 " I i = System::exit;\n" +
2755 " ^^^^^^^^^^^^\n" +
2756 "Method references are allowed only at source level 1.8 or above\n" +
2757 "----------\n";
2758
2759 runComplianceParserTest(
2760 testFiles,
2761 expectedProblemLog,
2762 expectedProblemLog,
2763 expectedProblemLog,
2764 expectedProblemLog,
2765 expectedProblemLog
2766 );
2767 }
2768 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0059()2769 public void test0059() {
2770 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2771 return;
2772 }
2773 String[] testFiles = new String[] {
2774 "X.java",
2775 "interface I {\n" +
2776 " void foo(int p);\n" +
2777 "}\n" +
2778 "class Y {\n" +
2779 " static void goo(int x) {\n" +
2780 " }\n" +
2781 "}\n" +
2782 "public class X extends Y {\n" +
2783 " I i = super::goo;\n" +
2784 "}\n"
2785 };
2786
2787 String expectedProblemLog =
2788 "----------\n" +
2789 "1. ERROR in X.java (at line 9)\n" +
2790 " I i = super::goo;\n" +
2791 " ^^^^^^^^^^\n" +
2792 "Method references are allowed only at source level 1.8 or above\n" +
2793 "----------\n" +
2794 "2. ERROR in X.java (at line 9)\n" +
2795 " I i = super::goo;\n" +
2796 " ^^^^^^^^^^\n" +
2797 "The method goo(int) from the type Y should be accessed in a static way \n" +
2798 "----------\n";
2799
2800 runComplianceParserTest(
2801 testFiles,
2802 expectedProblemLog,
2803 expectedProblemLog,
2804 expectedProblemLog,
2805 expectedProblemLog,
2806 expectedProblemLog
2807 );
2808 }
2809 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0060()2810 public void test0060() {
2811 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2812 return;
2813 }
2814 String[] testFiles = new String[] {
2815 "X.java",
2816 "interface I {\n" +
2817 " void foo(int p);\n" +
2818 "}\n" +
2819 "class Y {\n" +
2820 " void goo(int x) {\n" +
2821 " }\n" +
2822 "}\n" +
2823 "public class X extends Y {\n" +
2824 " I i = new Y()::goo;\n" +
2825 "}\n"
2826 };
2827
2828 String expectedProblemLog =
2829 "----------\n" +
2830 "1. ERROR in X.java (at line 9)\n" +
2831 " I i = new Y()::goo;\n" +
2832 " ^^^^^^^^^^^^\n" +
2833 "Method references are allowed only at source level 1.8 or above\n" +
2834 "----------\n";
2835
2836 runComplianceParserTest(
2837 testFiles,
2838 expectedProblemLog,
2839 expectedProblemLog,
2840 expectedProblemLog,
2841 expectedProblemLog,
2842 expectedProblemLog
2843 );
2844 }
2845 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0061()2846 public void test0061() {
2847 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2848 return;
2849 }
2850 String[] testFiles = new String[] {
2851 "X.java",
2852 "interface I {\n" +
2853 " void foo(int p);\n" +
2854 "}\n" +
2855 "class Y {\n" +
2856 " void goo(int x) {\n" +
2857 " }\n" +
2858 " Y() {}\n" +
2859 " Y(int x) {}\n" +
2860 "}\n" +
2861 "public class X extends Y {\n" +
2862 " I i = Y::new;\n" +
2863 "}\n"
2864 };
2865
2866 String expectedProblemLog =
2867 "----------\n" +
2868 "1. ERROR in X.java (at line 11)\n" +
2869 " I i = Y::new;\n" +
2870 " ^^^^^^\n" +
2871 "Constructor references are allowed only at source level 1.8 or above\n" +
2872 "----------\n";
2873
2874 runComplianceParserTest(
2875 testFiles,
2876 expectedProblemLog,
2877 expectedProblemLog,
2878 expectedProblemLog,
2879 expectedProblemLog,
2880 expectedProblemLog
2881 );
2882 }
2883 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383714
test0062()2884 public void test0062() {
2885 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
2886 return;
2887 }
2888 String[] testFiles = new String[] {
2889 "X.java",
2890 "interface I {\n" +
2891 " int foo(int p);\n" +
2892 "}\n" +
2893 "public class X {\n" +
2894 " I i = p -> 10 + 20 + 30;\n" +
2895 "}\n"
2896 };
2897
2898 String expectedProblemLog =
2899 "----------\n" +
2900 "1. ERROR in X.java (at line 5)\n" +
2901 " I i = p -> 10 + 20 + 30;\n" +
2902 " ^^^^^^^^^^^^^^^^^\n" +
2903 "Lambda expressions are allowed only at source level 1.8 or above\n" +
2904 "----------\n";
2905
2906 runComplianceParserTest(
2907 testFiles,
2908 expectedProblemLog,
2909 expectedProblemLog,
2910 expectedProblemLog,
2911 expectedProblemLog,
2912 expectedProblemLog
2913 );
2914 }
2915 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=381358
test0063()2916 public void test0063() {
2917 if (this.complianceLevel <= ClassFileConstants.JDK1_4 || this.complianceLevel >= ClassFileConstants.JDK1_8) {
2918 return;
2919 }
2920 String[] testFiles = new String[] {
2921 "X.java",
2922 "interface I {\n" +
2923 " int foo(int p);\n" +
2924 "}\n" +
2925 "public class X<T> {\n" +
2926 " I i = X<String>::foo;\n" +
2927 " I i2 = (p) -> 10;\n" +
2928 " public static int foo(int p) {\n" +
2929 " return p;\n" +
2930 " }\n" +
2931 "}\n"
2932 };
2933
2934 String expectedProblemLog =
2935 "----------\n" +
2936 "1. ERROR in X.java (at line 5)\n" +
2937 " I i = X<String>::foo;\n" +
2938 " ^^^^^^^^^^^^^^\n" +
2939 "Method references are allowed only at source level 1.8 or above\n" +
2940 "----------\n" +
2941 "2. ERROR in X.java (at line 5)\n" +
2942 " I i = X<String>::foo;\n" +
2943 " ^^^^^^^^^^^^^^\n" +
2944 "The method foo(int) from the type X<String> should be accessed in a static way \n" +
2945 "----------\n" +
2946 "3. ERROR in X.java (at line 6)\n" +
2947 " I i2 = (p) -> 10;\n" +
2948 " ^^^^^^^^^\n" +
2949 "Lambda expressions are allowed only at source level 1.8 or above\n" +
2950 "----------\n";
2951
2952 runComplianceParserTest(
2953 testFiles,
2954 expectedProblemLog,
2955 expectedProblemLog,
2956 expectedProblemLog,
2957 expectedProblemLog,
2958 expectedProblemLog
2959 );
2960 }
2961 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383913#c22
test0064()2962 public void test0064() {
2963 if (this.complianceLevel >= ClassFileConstants.JDK1_8) {
2964 return;
2965 }
2966 String[] source = new String[] {
2967 "X.java",
2968 "class X {\n" +
2969 " void foo(X this){}\n" +
2970 "}"
2971 };
2972 String expectedProblemLog =
2973 "----------\n" +
2974 "1. ERROR in X.java (at line 2)\n" +
2975 " void foo(X this){}\n" +
2976 " ^^^^\n" +
2977 "Explicit declaration of 'this' parameter is allowed only at source level 1.8 or above\n" +
2978 "----------\n";
2979 runComplianceParserTest(
2980 source,
2981 expectedProblemLog,
2982 expectedProblemLog,
2983 expectedProblemLog,
2984 expectedProblemLog,
2985 expectedProblemLog
2986 );
2987 }
2988 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391201
testBug391201()2989 public void testBug391201() {
2990 if(this.complianceLevel >= ClassFileConstants.JDK1_8 || this.complianceLevel < ClassFileConstants.JDK1_5) {
2991 return;
2992 }
2993 String[] testFiles = new String[] {
2994 "X.java",
2995 "public class X {\n" +
2996 " @Marker int foo(@Marker int p) {\n" +
2997 " @Marker int i = 0;\n" +
2998 " return i;\n" +
2999 " }\n" +
3000 " @Marker\n" +
3001 " class Y {}\n" +
3002 " @java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" +
3003 " @interface Marker {}" +
3004 "}",
3005 "java/lang/annotation/ElementType.java",
3006 "package java.lang.annotation;\n" +
3007 "public enum ElementType {\n" +
3008 " TYPE,\n" +
3009 " FIELD,\n" +
3010 " METHOD,\n" +
3011 " PARAMETER,\n" +
3012 " CONSTRUCTOR,\n" +
3013 " LOCAL_VARIABLE,\n" +
3014 " ANNOTATION_TYPE,\n" +
3015 " PACKAGE,\n" +
3016 " TYPE_PARAMETER,\n" +
3017 " TYPE_USE\n" +
3018 "}\n"
3019 };
3020
3021 String expectedProblemLog =
3022 "----------\n" +
3023 "1. ERROR in X.java (at line 2)\n" +
3024 " @Marker int foo(@Marker int p) {\n" +
3025 " ^^^^^^^\n" +
3026 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3027 "----------\n" +
3028 "2. ERROR in X.java (at line 2)\n" +
3029 " @Marker int foo(@Marker int p) {\n" +
3030 " ^^^^^^^\n" +
3031 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3032 "----------\n" +
3033 "3. ERROR in X.java (at line 3)\n" +
3034 " @Marker int i = 0;\n" +
3035 " ^^^^^^^\n" +
3036 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3037 "----------\n" +
3038 "4. ERROR in X.java (at line 6)\n" +
3039 " @Marker\n" +
3040 " ^^^^^^^\n" +
3041 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3042 "----------\n";
3043
3044 runComplianceParserTest(
3045 testFiles,
3046 expectedProblemLog,
3047 expectedProblemLog,
3048 expectedProblemLog,
3049 expectedProblemLog,
3050 expectedProblemLog
3051 );
3052 }
testBug399773()3053 public void testBug399773() {
3054 if (this.complianceLevel >= ClassFileConstants.JDK1_8)
3055 return;
3056 String[] testFiles = new String[] {
3057 "X.java",
3058 "interface I {\n" +
3059 " void doit();\n" +
3060 " default void doitalso () {}\n" +
3061 "}\n" +
3062 "interface J {\n" +
3063 " void doit();\n" +
3064 " default void doitalso () {}\n" +
3065 "}\n" +
3066 "public class X {\n" +
3067 " Object p = (I & J) () -> {};\n" +
3068 "}\n" ,
3069 };
3070
3071 String expectedProblemLog =
3072 "----------\n" +
3073 "1. ERROR in X.java (at line 3)\n" +
3074 " default void doitalso () {}\n" +
3075 " ^^^^^^^^^^^\n" +
3076 "Default methods are allowed only at source level 1.8 or above\n" +
3077 "----------\n" +
3078 "2. ERROR in X.java (at line 7)\n" +
3079 " default void doitalso () {}\n" +
3080 " ^^^^^^^^^^^\n" +
3081 "Default methods are allowed only at source level 1.8 or above\n" +
3082 "----------\n" +
3083 "3. ERROR in X.java (at line 10)\n" +
3084 " Object p = (I & J) () -> {};\n" +
3085 " ^^^^^\n" +
3086 "Additional bounds are not allowed in cast operator at source levels below 1.8\n" +
3087 "----------\n" +
3088 "4. ERROR in X.java (at line 10)\n" +
3089 " Object p = (I & J) () -> {};\n" +
3090 " ^^^^^\n" +
3091 "Lambda expressions are allowed only at source level 1.8 or above\n" +
3092 "----------\n" +
3093 "5. ERROR in X.java (at line 10)\n" +
3094 " Object p = (I & J) () -> {};\n" +
3095 " ^^^^^\n" +
3096 "The target type of this expression must be a functional interface\n" +
3097 "----------\n";
3098
3099 runComplianceParserTest(
3100 testFiles,
3101 expectedProblemLog,
3102 expectedProblemLog,
3103 expectedProblemLog,
3104 expectedProblemLog,
3105 expectedProblemLog
3106 );
3107 }
3108 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types
testBug399778()3109 public void testBug399778() {
3110 if (this.complianceLevel < ClassFileConstants.JDK1_5)
3111 return;
3112 String[] testFiles = new String[] {
3113 "X.java",
3114 "import java.util.Arrays;\n" +
3115 "import java.util.List;\n" +
3116 "public class X {\n" +
3117 " List<String> l = null == null ? Arrays.asList() : Arrays.asList(\"Hello\",\"world\");\n" +
3118 "}\n",
3119 };
3120
3121 String expectedProblemLog =
3122 "----------\n" +
3123 "1. ERROR in X.java (at line 4)\n" +
3124 " List<String> l = null == null ? Arrays.asList() : Arrays.asList(\"Hello\",\"world\");\n" +
3125 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
3126 "Type mismatch: cannot convert from List<capture#1-of ? extends Object> to List<String>\n" +
3127 "----------\n";
3128
3129 runComplianceParserTest(
3130 testFiles,
3131 expectedProblemLog,
3132 expectedProblemLog,
3133 expectedProblemLog,
3134 expectedProblemLog,
3135 expectedProblemLog,
3136 "" // 1.8 should compile this fine.
3137 );
3138 }
3139 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types
testBug399778a()3140 public void testBug399778a() {
3141 if (this.complianceLevel < ClassFileConstants.JDK1_5)
3142 return;
3143 String[] testFiles = new String[] {
3144 "X.java",
3145 "import java.util.Arrays;\n" +
3146 "import java.util.List;\n" +
3147 "public class X {\n" +
3148 " List<String> l = (List<String>) (null == null ? Arrays.asList() : Arrays.asList(\"Hello\",\"world\"));\n" +
3149 "}\n",
3150 };
3151
3152 String expectedProblemLog =
3153 "----------\n" +
3154 "1. WARNING in X.java (at line 4)\n" +
3155 " List<String> l = (List<String>) (null == null ? Arrays.asList() : Arrays.asList(\"Hello\",\"world\"));\n" +
3156 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
3157 "Type safety: Unchecked cast from List<capture#1-of ? extends Object> to List<String>\n" +
3158 "----------\n";
3159
3160 runComplianceParserTest(
3161 testFiles,
3162 expectedProblemLog,
3163 expectedProblemLog,
3164 expectedProblemLog,
3165 expectedProblemLog,
3166 expectedProblemLog,
3167 expectedProblemLog // 1.8 also issue type safety warning.
3168 );
3169 }
3170 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780: static methods in interfaces.
testBug399780()3171 public void testBug399780() {
3172 if(this.complianceLevel >= ClassFileConstants.JDK1_8) {
3173 return;
3174 }
3175 String[] testFiles = new String[] {
3176 "I.java",
3177 "interface I {\n" +
3178 " public static void foo1() { System.out.println(); }\n" +
3179 " public static void foo2();\n" +
3180 " public abstract static void foo3();\n" +
3181 "}\n"
3182 };
3183
3184 String expectedProblemLog =
3185 "----------\n" +
3186 "1. ERROR in I.java (at line 2)\n" +
3187 " public static void foo1() { System.out.println(); }\n" +
3188 " ^^^^^^\n" +
3189 "Static methods are allowed in interfaces only at source level 1.8 or above\n" +
3190 "----------\n" +
3191 "2. ERROR in I.java (at line 2)\n" +
3192 " public static void foo1() { System.out.println(); }\n" +
3193 " ^^^^^^\n" +
3194 "Illegal modifier for the interface method foo1; only public & abstract are permitted\n" +
3195 "----------\n" +
3196 "3. ERROR in I.java (at line 3)\n" +
3197 " public static void foo2();\n" +
3198 " ^^^^^^\n" +
3199 "Illegal modifier for the interface method foo2; only public & abstract are permitted\n" +
3200 "----------\n" +
3201 "4. ERROR in I.java (at line 4)\n" +
3202 " public abstract static void foo3();\n" +
3203 " ^^^^^^\n" +
3204 "Illegal modifier for the interface method foo3; only public & abstract are permitted\n" +
3205 "----------\n";
3206
3207 runComplianceParserTest(
3208 testFiles,
3209 expectedProblemLog,
3210 expectedProblemLog,
3211 expectedProblemLog,
3212 expectedProblemLog,
3213 expectedProblemLog,
3214 expectedProblemLog
3215 );
3216 }
3217 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=399769: Use of '_' as identifier name should trigger a diagnostic
testBug399781()3218 public void testBug399781() {
3219 String[] testFiles = new String[] {
3220 "X.java",
3221 "public class X {\n" +
3222 " int _;\n" +
3223 " void foo(){\n" +
3224 " int _ = 3;\n" +
3225 " int _123 = 4;\n" +
3226 " int a_ = 5;\n" +
3227 " }\n" +
3228 " void goo(int _) {}\n" +
3229 " void zoo() {\n" +
3230 " try {\n" +
3231 " } catch (Exception _) {\n" +
3232 " }\n" +
3233 " }\n" +
3234 "}\n",
3235 };
3236 String usLevel = this.complianceLevel < ClassFileConstants.JDK9 ? "WARNING" : "ERROR";
3237 String expectedProblemLog =
3238 "----------\n" +
3239 "1. " + usLevel +" in X.java (at line 2)\n" +
3240 " int _;\n" +
3241 " ^\n" +
3242 "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n" +
3243 "----------\n" +
3244 "2. " + usLevel +" in X.java (at line 4)\n" +
3245 " int _ = 3;\n" +
3246 " ^\n" +
3247 "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n" +
3248 "----------\n" +
3249 "3. WARNING in X.java (at line 4)\n" +
3250 " int _ = 3;\n" +
3251 " ^\n" +
3252 "The local variable _ is hiding a field from type X\n" +
3253 "----------\n" +
3254 "4. " + usLevel +" in X.java (at line 8)\n" +
3255 " void goo(int _) {}\n" +
3256 " ^\n" +
3257 "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n" +
3258 "----------\n" +
3259 "5. WARNING in X.java (at line 8)\n" +
3260 " void goo(int _) {}\n" +
3261 " ^\n" +
3262 "The parameter _ is hiding a field from type X\n" +
3263 "----------\n" +
3264 "6. " + usLevel +" in X.java (at line 11)\n" +
3265 " } catch (Exception _) {\n" +
3266 " ^\n" +
3267 "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n" +
3268 "----------\n" +
3269 "7. WARNING in X.java (at line 11)\n" +
3270 " } catch (Exception _) {\n" +
3271 " ^\n" +
3272 "The parameter _ is hiding a field from type X\n" +
3273 "----------\n";
3274 String expected13ProblemLog =
3275 "----------\n" +
3276 "1. WARNING in X.java (at line 4)\n" +
3277 " int _ = 3;\n" +
3278 " ^\n" +
3279 "The local variable _ is hiding a field from type X\n" +
3280 "----------\n" +
3281 "2. WARNING in X.java (at line 8)\n" +
3282 " void goo(int _) {}\n" +
3283 " ^\n" +
3284 "The parameter _ is hiding a field from type X\n" +
3285 "----------\n" +
3286 "3. WARNING in X.java (at line 11)\n" +
3287 " } catch (Exception _) {\n" +
3288 " ^\n" +
3289 "The parameter _ is hiding a field from type X\n" +
3290 "----------\n";
3291
3292 runComplianceParserTest(
3293 testFiles,
3294 expected13ProblemLog,
3295 expected13ProblemLog,
3296 expected13ProblemLog,
3297 expected13ProblemLog,
3298 expected13ProblemLog,
3299 expectedProblemLog
3300 );
3301 }
3302 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=406846: [1.8] compiler NPE for method reference/lambda code compiled with < 1.8 compliance
3303 public void test406846() {
3304
3305 if (this.complianceLevel >= ClassFileConstants.JDK1_8) // tested in LET.
3306 return;
3307
3308 String[] testFiles = new String[] {
3309 "X.java",
3310 "import java.util.*;\n" +
3311 "public class X {\n" +
3312 " public static <E> void printItem(E value, int index) {\n" +
3313 " String output = String.format(\"%d -> %s\", index, value);\n" +
3314 " System.out.println(output);\n" +
3315 " }\n" +
3316 " public static void main(String[] argv) {\n" +
3317 " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
3318 " eachWithIndex(list,X::printItem);\n" +
3319 " }\n" +
3320 " interface ItemWithIndexVisitor<E> {\n" +
3321 " public void visit(E item, int index);\n" +
3322 " }\n" +
3323 " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
3324 " for (int i = 0; i < list.size(); i++) {\n" +
3325 " visitor.visit(list.get(i), i);\n" +
3326 " }\n" +
3327 " }\n" +
3328 "}\n",
3329 };
3330
3331 String expectedProblemLog =
3332 "----------\n" +
3333 "1. ERROR in X.java (at line 9)\n" +
3334 " eachWithIndex(list,X::printItem);\n" +
3335 " ^^^^^^^^^^^^\n" +
3336 "Method references are allowed only at source level 1.8 or above\n" +
3337 "----------\n";
3338 String expected1314ProblemLog =
3339 "----------\n" +
3340 "1. ERROR in X.java (at line 3)\n" +
3341 " public static <E> void printItem(E value, int index) {\n" +
3342 " ^\n" +
3343 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
3344 "----------\n" +
3345 "2. ERROR in X.java (at line 4)\n" +
3346 " String output = String.format(\"%d -> %s\", index, value);\n" +
3347 " ^^^^^^\n" +
3348 "The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, E)\n" +
3349 "----------\n" +
3350 "3. ERROR in X.java (at line 8)\n" +
3351 " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
3352 " ^^^^^^\n" +
3353 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
3354 "----------\n" +
3355 "4. ERROR in X.java (at line 8)\n" +
3356 " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
3357 " ^^^^^^\n" +
3358 "The method asList(T[]) in the type Arrays is not applicable for the arguments (String, String, String)\n" +
3359 "----------\n" +
3360 "5. ERROR in X.java (at line 9)\n" +
3361 " eachWithIndex(list,X::printItem);\n" +
3362 " ^^^^^^^^^^^^\n" +
3363 "Method references are allowed only at source level 1.8 or above\n" +
3364 "----------\n" +
3365 "6. ERROR in X.java (at line 11)\n" +
3366 " interface ItemWithIndexVisitor<E> {\n" +
3367 " ^\n" +
3368 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
3369 "----------\n" +
3370 "7. ERROR in X.java (at line 14)\n" +
3371 " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
3372 " ^\n" +
3373 "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
3374 "----------\n" +
3375 "8. ERROR in X.java (at line 14)\n" +
3376 " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
3377 " ^\n" +
3378 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
3379 "----------\n" +
3380 "9. ERROR in X.java (at line 14)\n" +
3381 " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
3382 " ^\n" +
3383 "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
3384 "----------\n";
3385
3386 runComplianceParserTest(
3387 testFiles,
3388 expected1314ProblemLog,
3389 expected1314ProblemLog,
3390 expectedProblemLog,
3391 expectedProblemLog,
3392 expectedProblemLog,
3393 expectedProblemLog
3394 );
3395 }
3396 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=401850: [1.8][compiler] Compiler fails to type poly allocation expressions in method invocation contexts
3397 // FAIL: sub-optimal overload picked
test401850()3398 public void test401850() {
3399
3400 if (this.complianceLevel < ClassFileConstants.JDK1_7)
3401 return;
3402 this.runConformTest(
3403 new String[] {
3404 "X.java",
3405 "public class X<T> {\n" +
3406 " static void foo(Object o) {\n" +
3407 " System.out.println(\"foo(Object)\");\n" +
3408 " }\n" +
3409 " static void foo(X<String> o) {\n" +
3410 " System.out.println(\"foo(X<String>)\");\n" +
3411 " }\n" +
3412 " public static void main(String[] args) { \n" +
3413 " foo(new X<>()); \n" +
3414 " } \n" +
3415 "}\n",
3416 },
3417 this.complianceLevel == ClassFileConstants.JDK1_7 ? "foo(Object)" : "foo(X<String>)");
3418 }
3419 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=429110: [1.8][quick fix] Hovering over the error does not show the quick fix
3420 //FAIL: sub-optimal overload picked
test429110()3421 public void test429110() {
3422 if (this.complianceLevel != ClassFileConstants.JDK1_7)
3423 return;
3424 this.runNegativeTest(
3425 new String[] {
3426 "java/lang/annotation/ElementType.java",
3427 "package java.lang.annotation;\n" +
3428 "public enum ElementType {\n" +
3429 " TYPE,\n" +
3430 " FIELD,\n" +
3431 " METHOD,\n" +
3432 " PARAMETER,\n" +
3433 " CONSTRUCTOR,\n" +
3434 " LOCAL_VARIABLE,\n" +
3435 " ANNOTATION_TYPE,\n" +
3436 " PACKAGE,\n" +
3437 " TYPE_PARAMETER,\n" +
3438 " TYPE_USE\n" +
3439 "}\n",
3440 "X.java",
3441 "import java.lang.annotation.ElementType;\n" +
3442 "import java.lang.annotation.Target;\n" +
3443 "import java.util.List;\n" +
3444 "public class X {\n" +
3445 " @Target(ElementType.TYPE_USE)\n" +
3446 " static @interface NonNull { }\n" +
3447 " List<@NonNull String> foo(List<@NonNull String> arg) {\n" +
3448 " return arg;\n" +
3449 " }\n" +
3450 "}\n"
3451 },
3452 "----------\n" +
3453 "1. ERROR in X.java (at line 7)\n" +
3454 " List<@NonNull String> foo(List<@NonNull String> arg) {\n" +
3455 " ^^^^^^^^\n" +
3456 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3457 "----------\n" +
3458 "2. ERROR in X.java (at line 7)\n" +
3459 " List<@NonNull String> foo(List<@NonNull String> arg) {\n" +
3460 " ^^^^^^^^\n" +
3461 "Syntax error, type annotations are available only when source level is at least 1.8\n" +
3462 "----------\n");
3463 }
3464 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=421477: [1.8][compiler] strange error message for default method in class
test421477()3465 public void test421477() {
3466 this.runNegativeTest(
3467 new String[] {
3468 "X.java",
3469 "public class X {\n" +
3470 " default void f() {\n" +
3471 " }\n" +
3472 " default X() {}\n" +
3473 "}",
3474 },
3475 "----------\n" +
3476 "1. ERROR in X.java (at line 2)\n" +
3477 " default void f() {\n" +
3478 " ^^^\n" +
3479 (this.complianceLevel >= ClassFileConstants.JDK1_8 ?
3480 "Default methods are allowed only in interfaces.\n" :
3481 "Illegal modifier for the method f; only public, protected, private, abstract, static, final, synchronized, native & strictfp are permitted\n") +
3482 "----------\n" +
3483 "2. ERROR in X.java (at line 4)\n" +
3484 " default X() {}\n" +
3485 " ^\n" +
3486 "Syntax error on token \"X\", Identifier expected after this token\n" +
3487 "----------\n");
3488 }
3489 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=428605: [1.8] Error highlighting can be improved for default methods
test428605()3490 public void test428605() {
3491 this.runNegativeTest(
3492 new String[] {
3493 "X.java",
3494 "interface X {\n" +
3495 " default void f() {\n" +
3496 " }\n" +
3497 " static void g() {\n" +
3498 " }\n" +
3499 "} \n"
3500 },
3501 (this.complianceLevel < ClassFileConstants.JDK1_8 ?
3502 "----------\n" +
3503 "1. ERROR in X.java (at line 2)\n" +
3504 " default void f() {\n" +
3505 " ^^^\n" +
3506 "Default methods are allowed only at source level 1.8 or above\n" +
3507 "----------\n" +
3508 "2. ERROR in X.java (at line 4)\n" +
3509 " static void g() {\n" +
3510 " ^^^\n" +
3511 "Static methods are allowed in interfaces only at source level 1.8 or above\n" +
3512 "----------\n" +
3513 "3. ERROR in X.java (at line 4)\n" +
3514 " static void g() {\n" +
3515 " ^^^\n" +
3516 "Illegal modifier for the interface method g; only public & abstract are permitted\n" +
3517 "----------\n" :
3518 ""));
3519 }
3520 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=440285
3521 // [1.8] Compiler allows array creation reference with type arguments
testBug440285()3522 public void testBug440285() {
3523 if (this.complianceLevel < ClassFileConstants.JDK1_8)
3524 return;
3525 runNegativeTest(new String [] {
3526 "X.java",
3527 "import java.util.function.Function;\n" +
3528 "class Y{}\n" +
3529 "class Z{}\n" +
3530 "public class X {\n" +
3531 " Function<Integer, int[]> m1 = int[]::<Y, Z>new;\n" +
3532 " Function<Integer, int[]> m2 = int[]::<Y>new;\n" +
3533 "}",},
3534 "----------\n" +
3535 "1. ERROR in X.java (at line 5)\n" +
3536 " Function<Integer, int[]> m1 = int[]::<Y, Z>new;\n" +
3537 " ^^^^\n" +
3538 "Type arguments are not allowed here\n" +
3539 "----------\n" +
3540 "2. ERROR in X.java (at line 6)\n" +
3541 " Function<Integer, int[]> m2 = int[]::<Y>new;\n" +
3542 " ^\n" +
3543 "Type arguments are not allowed here\n" +
3544 "----------\n");
3545 }
testBug531714_001()3546 public void testBug531714_001() {
3547 if (this.complianceLevel >= ClassFileConstants.JDK12)
3548 return;
3549 String[] testFiles = new String[] {
3550 "X.java",
3551 "public class X {\n" +
3552 " static int twice(int i) {\n" +
3553 " int tw = switch (i) {\n" +
3554 " case 0 -> i * 0;\n" +
3555 " case 1 -> 2;\n" +
3556 " default -> 3;\n" +
3557 " };\n" +
3558 " return tw;\n" +
3559 " }\n" +
3560 " public static void main(String[] args) {\n" +
3561 " System.out.print(twice(3));\n" +
3562 " }\n" +
3563 "}\n",
3564 };
3565
3566 String expectedProblemLog =
3567 "----------\n" +
3568 "1. ERROR in X.java (at line 3)\n" +
3569 " int tw = switch (i) {\n" +
3570 " case 0 -> i * 0;\n" +
3571 " case 1 -> 2;\n" +
3572 " default -> 3;\n" +
3573 " };\n" +
3574 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
3575 "Switch Expressions are supported from Java 14 onwards only\n" +
3576 "----------\n" +
3577 "2. ERROR in X.java (at line 4)\n" +
3578 " case 0 -> i * 0;\n" +
3579 " ^^^^^^\n" +
3580 "Arrow in case statement supported from Java 14 onwards only\n" +
3581 "----------\n" +
3582 "3. ERROR in X.java (at line 5)\n" +
3583 " case 1 -> 2;\n" +
3584 " ^^^^^^\n" +
3585 "Arrow in case statement supported from Java 14 onwards only\n" +
3586 "----------\n" +
3587 "4. ERROR in X.java (at line 6)\n" +
3588 " default -> 3;\n" +
3589 " ^^^^^^^\n" +
3590 "Arrow in case statement supported from Java 14 onwards only\n" +
3591 "----------\n";
3592
3593 runComplianceParserTest(
3594 testFiles,
3595 expectedProblemLog,
3596 expectedProblemLog,
3597 expectedProblemLog,
3598 expectedProblemLog,
3599 expectedProblemLog
3600 );
3601 }
testBug531714_002()3602 public void testBug531714_002() {
3603 if (this.complianceLevel >= ClassFileConstants.JDK12)
3604 return;
3605 String[] testFiles = new String[] {
3606 "X.java",
3607 "public class X {\n" +
3608 " static int twice(int i) {\n" +
3609 " switch (i) {\n" +
3610 " case 0 -> i * 0;\n" +
3611 " case 1 -> 2;\n" +
3612 " default -> 3;\n" +
3613 " }\n" +
3614 " return 0;\n" +
3615 " }\n" +
3616 " public static void main(String[] args) {\n" +
3617 " System.out.print(twice(3));\n" +
3618 " }\n" +
3619 "}\n",
3620 };
3621
3622 String expectedProblemLog =
3623 "----------\n" +
3624 "1. ERROR in X.java (at line 4)\n" +
3625 " case 0 -> i * 0;\n" +
3626 " ^^^^^^\n" +
3627 "Arrow in case statement supported from Java 14 onwards only\n" +
3628 "----------\n" +
3629 "2. ERROR in X.java (at line 5)\n" +
3630 " case 1 -> 2;\n" +
3631 " ^^^^^^\n" +
3632 "Arrow in case statement supported from Java 14 onwards only\n" +
3633 "----------\n" +
3634 "3. ERROR in X.java (at line 6)\n" +
3635 " default -> 3;\n" +
3636 " ^^^^^^^\n" +
3637 "Arrow in case statement supported from Java 14 onwards only\n" +
3638 "----------\n";
3639
3640 runComplianceParserTest(
3641 testFiles,
3642 expectedProblemLog,
3643 expectedProblemLog,
3644 expectedProblemLog,
3645 expectedProblemLog,
3646 expectedProblemLog
3647 );
3648 }
3649 }
3650