1616import java .util .Map ;
1717import junit .framework .Test ;
1818import org .eclipse .jdt .core .tests .compiler .regression .AbstractRegressionTest .JavacTestOptions .JavacHasABug ;
19+ import org .eclipse .jdt .core .tests .compiler .regression .AbstractRegressionTest .JavacTestOptions .Excuse ;
1920import org .eclipse .jdt .internal .compiler .classfmt .ClassFileConstants ;
2021import org .eclipse .jdt .internal .compiler .impl .CompilerOptions ;
2122
@@ -380,9 +381,10 @@ public void testBug488663_012() {
380381}
381382// Redundant type argument specification - TODO - confirm that this is correct
382383public void testBug488663_013 () {
383- Map <String , String > options = getCompilerOptions ();
384- options .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
385- this .runNegativeTest (
384+ Runner runner = new Runner ();
385+ runner .customOptions = getCompilerOptions ();
386+ runner .customOptions .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
387+ runner .testFiles =
386388 new String [] {
387389 "X.java" ,
388390 "public class X {\n " +
@@ -406,14 +408,16 @@ public void testBug488663_013() {
406408 "interface I<T> {\n " +
407409 " String toString(T t);\n " +
408410 "}"
409- },
411+ };
412+ runner .expectedCompilerLog =
410413 "----------\n " +
411414 "1. ERROR in X.java (at line 11)\n " +
412415 " I<X> i = new I<X>() {\n " +
413416 " ^\n " +
414417 "Redundant specification of type arguments <X>\n " +
415- "----------\n " ,
416- null , true , options );
418+ "----------\n " ;
419+ runner .javacTestOptions = Excuse .EclipseWarningConfiguredAsError ;
420+ runner .runNegativeTest ();
417421}
418422// All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override
419423public void testBug488663_014 () {
@@ -602,7 +606,8 @@ public void testBug521815b() {
602606 if (this .complianceLevel <= ClassFileConstants .JDK1_8 ) {
603607 return ;
604608 }
605- runNegativeTest (
609+ Runner runner = new Runner ();
610+ runner .testFiles =
606611 new String [] {
607612 "a/b/X.java" ,
608613 "package a.b;\n " +
@@ -618,13 +623,16 @@ public void testBug521815b() {
618623 "import static a.b.X.Inner;\n " +
619624 "public class Y {;\n " +
620625 "}\n "
621- },
626+ };
627+ runner .expectedCompilerLog =
622628 "----------\n " +
623629 "1. WARNING in a\\ Y.java (at line 2)\n " +
624630 " import static a.b.X.Inner;\n " +
625631 " ^^^^^^^^^^^\n " +
626632 "The import a.b.X.Inner is never used\n " +
627- "----------\n " );
633+ "----------\n " ;
634+ runner .javacTestOptions = Excuse .EclipseHasSomeMoreWarnings ;
635+ runner .runWarningTest ();
628636}
629637public void testBug533644 () {
630638 runConformTest (
@@ -702,9 +710,10 @@ public void testBug551913_001() {
702710// "Remove redundant type arguments" diagnostic should be reported ONLY if all the non-private methods defined in the anonymous class
703711// are also present in the parent class.
704712public void testBug551913_002 () {
705- Map <String , String > options = getCompilerOptions ();
706- options .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
707- this .runNegativeTest (
713+ Runner runner = new Runner ();
714+ runner .customOptions = getCompilerOptions ();
715+ runner .customOptions .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
716+ runner .testFiles =
708717 new String [] {
709718 "X.java" ,
710719 "public class X {\n " +
@@ -716,22 +725,25 @@ public void testBug551913_002() {
716725 " };\n " +
717726 " }\n " +
718727 "}" ,
719- },
728+ };
729+ runner .expectedCompilerLog =
720730 "----------\n " +
721731 "1. ERROR in X.java (at line 4)\n " +
722732 " java.util.HashSet<String> b = new java.util.HashSet<String>(a) {\n " +
723733 " ^^^^^^^\n " +
724734 "Redundant specification of type arguments <String>\n " +
725- "----------\n " ,
726- null , true , options );
735+ "----------\n " ;
736+ runner .javacTestOptions = Excuse .EclipseWarningConfiguredAsError ;
737+ runner .runNegativeTest ();
727738}
728739
729740// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
730741// https://bugs.eclipse.org/bugs/show_bug.cgi?id=551913
731742public void testBug551913_003 () {
732- Map <String , String > options = getCompilerOptions ();
733- options .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
734- this .runNegativeTest (
743+ Runner runner = new Runner ();
744+ runner .customOptions = getCompilerOptions ();
745+ runner .customOptions .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
746+ runner .testFiles =
735747 new String [] {
736748 "X.java" ,
737749 "public class X {\n " +
@@ -744,14 +756,16 @@ public void testBug551913_003() {
744756 " };\n " +
745757 " }\n " +
746758 "}" ,
747- },
759+ };
760+ runner .expectedCompilerLog =
748761 "----------\n " +
749762 "1. ERROR in X.java (at line 4)\n " +
750763 " java.util.HashSet<String> b = new java.util.HashSet<String>(a) {\n " +
751764 " ^^^^^^^\n " +
752765 "Redundant specification of type arguments <String>\n " +
753- "----------\n " ,
754- null , true , options );
766+ "----------\n " ;
767+ runner .javacTestOptions = Excuse .EclipseWarningConfiguredAsError ;
768+ runner .runNegativeTest ();
755769}
756770// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
757771// https://bugs.eclipse.org/bugs/show_bug.cgi?id=551913
@@ -811,9 +825,10 @@ public void testGH1506() {
811825// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
812826// Recommendation from compiler to drop type arguments leads to compile error
813827public void testGH1506_2 () {
814- Map <String , String > options = getCompilerOptions ();
815- options .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
816- this .runNegativeTest (
828+ Runner runner = new Runner ();
829+ runner .customOptions = getCompilerOptions ();
830+ runner .customOptions .put (CompilerOptions .OPTION_ReportRedundantSpecificationOfTypeArguments , CompilerOptions .ERROR );
831+ runner .testFiles =
817832 new String [] {
818833 "X.java" ,
819834 "import java.io.File;\n " +
@@ -837,14 +852,16 @@ public void testGH1506_2() {
837852 " };\n " +
838853 " }\n " +
839854 "}\n " ,
840- },
855+ };
856+ runner .expectedCompilerLog =
841857 "----------\n "
842858 + "1. ERROR in X.java (at line 8)\n "
843859 + " return new Iterable<File>() {\n "
844860 + " ^^^^^^^^\n "
845861 + "Redundant specification of type arguments <File>\n "
846- + "----------\n " ,
847- null , true , options );
862+ + "----------\n " ;
863+ runner .javacTestOptions = Excuse .EclipseWarningConfiguredAsError ;
864+ runner .runNegativeTest ();
848865}
849866// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1506
850867// Recommendation from compiler to drop type arguments leads to compile error
@@ -2244,6 +2261,40 @@ The method consume(List<? extends Test.A<? super U>>) in the type Test is not ap
22442261 runner .javacTestOptions = JavacHasABug .JavacBug6573446 ;
22452262 runner .runNegativeTest ();
22462263}
2264+ public void testGH4731 () {
2265+ Runner runner = new Runner ();
2266+ runner .testFiles = new String [] {
2267+ "TestWildcard.java" ,
2268+ """
2269+ import java.util.Collection;
2270+ import java.util.Iterator;
2271+
2272+ public class TestWildcard {
2273+
2274+ private Collection<? extends Collection<? extends Runnable>> _parts;
2275+
2276+ public Iterator<Runnable> iterator() {
2277+ return TestWildcard.concat(_parts).iterator();
2278+ }
2279+
2280+ public static <T> Iterable<T> concat(Iterable<? extends Iterable<? extends T>> entries) {
2281+ return null;
2282+ }
2283+
2284+ }
2285+ """
2286+ };
2287+ runner .expectedCompilerLog = """
2288+ ----------
2289+ 1. ERROR in TestWildcard.java (at line 9)
2290+ return TestWildcard.concat(_parts).iterator();
2291+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2292+ Type mismatch: cannot convert from Iterator<capture#2-of ? extends Runnable> to Iterator<Runnable>
2293+ ----------
2294+ """ ;
2295+ runner .javacTestOptions = JavacHasABug .JavacBug8016207 ;
2296+ runner .runNegativeTest ();
2297+ }
22472298public static Class <GenericsRegressionTest_9 > testClass () {
22482299 return GenericsRegressionTest_9 .class ;
22492300}
0 commit comments