|
Lines 14-19
Link Here
|
| 14 |
*******************************************************************************/ |
14 |
*******************************************************************************/ |
| 15 |
package org.eclipse.jdt.core.tests.compiler.regression; |
15 |
package org.eclipse.jdt.core.tests.compiler.regression; |
| 16 |
|
16 |
|
|
|
17 |
import java.util.Map; |
| 18 |
|
| 19 |
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
| 20 |
|
| 17 |
import junit.framework.Test; |
21 |
import junit.framework.Test; |
| 18 |
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest { |
22 |
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest { |
| 19 |
|
23 |
|
|
Lines 1811-1816
Link Here
|
| 1811 |
}, |
1815 |
}, |
| 1812 |
""); |
1816 |
""); |
| 1813 |
} |
1817 |
} |
|
|
1818 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 1819 |
public void test0052() { |
| 1820 |
Map customOptions = getCompilerOptions(); |
| 1821 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 1822 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 1823 |
this.runNegativeTest( |
| 1824 |
new String[] { |
| 1825 |
"X.java", |
| 1826 |
"public class X<E> {\n" + |
| 1827 |
" X(E e) {}\n" + |
| 1828 |
" X() {}\n" + |
| 1829 |
" public static void main(String[] args) {\n" + |
| 1830 |
" X<Number> x = new X<Number>(1);\n" + |
| 1831 |
" X<String> x2 = new X<String>(\"SUCCESS\");\n" + |
| 1832 |
" X<Integer> x3 = new X<Integer>(1);\n" + |
| 1833 |
" X<AX> x4 = new X<AX>(new AX());\n" + |
| 1834 |
" X<? extends AX> x5 = new X<AX<String>>(new AX<String>());\n" + |
| 1835 |
" X<?> x6 = new X<AX<String>>(new AX<String>());\n" + |
| 1836 |
" X<Class<? extends Object>> x7 = new X<Class<? extends Object>>();\n" + |
| 1837 |
" }\n" + |
| 1838 |
"}\n" + |
| 1839 |
"class AX<T>{}\n" |
| 1840 |
}, |
| 1841 |
"----------\n" + |
| 1842 |
"1. ERROR in X.java (at line 6)\n" + |
| 1843 |
" X<String> x2 = new X<String>(\"SUCCESS\");\n" + |
| 1844 |
" ^\n" + |
| 1845 |
"Redundant declaration of type arguments <String>\n" + |
| 1846 |
"----------\n" + |
| 1847 |
"2. ERROR in X.java (at line 7)\n" + |
| 1848 |
" X<Integer> x3 = new X<Integer>(1);\n" + |
| 1849 |
" ^\n" + |
| 1850 |
"Redundant declaration of type arguments <Integer>\n" + |
| 1851 |
"----------\n" + |
| 1852 |
"3. ERROR in X.java (at line 8)\n" + |
| 1853 |
" X<AX> x4 = new X<AX>(new AX());\n" + |
| 1854 |
" ^\n" + |
| 1855 |
"Redundant declaration of type arguments <AX>\n" + |
| 1856 |
"----------\n" + |
| 1857 |
"4. ERROR in X.java (at line 9)\n" + |
| 1858 |
" X<? extends AX> x5 = new X<AX<String>>(new AX<String>());\n" + |
| 1859 |
" ^\n" + |
| 1860 |
"Redundant declaration of type arguments <AX<String>>\n" + |
| 1861 |
"----------\n" + |
| 1862 |
"5. ERROR in X.java (at line 10)\n" + |
| 1863 |
" X<?> x6 = new X<AX<String>>(new AX<String>());\n" + |
| 1864 |
" ^\n" + |
| 1865 |
"Redundant declaration of type arguments <AX<String>>\n" + |
| 1866 |
"----------\n" + |
| 1867 |
"6. ERROR in X.java (at line 11)\n" + |
| 1868 |
" X<Class<? extends Object>> x7 = new X<Class<? extends Object>>();\n" + |
| 1869 |
" ^\n" + |
| 1870 |
"Redundant declaration of type arguments <Class<? extends Object>>\n" + |
| 1871 |
"----------\n", |
| 1872 |
null, |
| 1873 |
false, |
| 1874 |
customOptions); |
| 1875 |
} |
| 1876 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 1877 |
public void test0052b() { |
| 1878 |
Map customOptions = getCompilerOptions(); |
| 1879 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 1880 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 1881 |
this.runNegativeTest( |
| 1882 |
new String[] { |
| 1883 |
"X.java", |
| 1884 |
"public class X<E> {\n" + |
| 1885 |
" E eField;\n" + |
| 1886 |
" E get() { return this.eField; }\n" + |
| 1887 |
" X(E e) {}\n" + |
| 1888 |
" X(int e, String e2) {}\n" + |
| 1889 |
" public static void main(String[] args) {\n" + |
| 1890 |
" X<Number> x = new X<Number>(1);\n" + |
| 1891 |
" X<String> x2 = new X<String>(\"SUCCESS\");\n" + |
| 1892 |
" X<String> x22 = new X<String>(1,\"SUCCESS\");\n" + |
| 1893 |
" X<Integer> x3 = new X<Integer>(1);\n" + |
| 1894 |
" String s = foo(new X<String>(\"aaa\"));\n" + |
| 1895 |
" String s2 = foo(new X<String>(1,\"aaa\"));\n" + |
| 1896 |
" }\n" + |
| 1897 |
" static String foo(X<String> x) {\n" + |
| 1898 |
" return x.get();\n" + |
| 1899 |
" }\n" + |
| 1900 |
"}\n" |
| 1901 |
}, |
| 1902 |
"----------\n" + |
| 1903 |
"1. ERROR in X.java (at line 8)\n" + |
| 1904 |
" X<String> x2 = new X<String>(\"SUCCESS\");\n" + |
| 1905 |
" ^\n" + |
| 1906 |
"Redundant declaration of type arguments <String>\n" + |
| 1907 |
"----------\n" + |
| 1908 |
"2. ERROR in X.java (at line 9)\n" + |
| 1909 |
" X<String> x22 = new X<String>(1,\"SUCCESS\");\n" + |
| 1910 |
" ^\n" + |
| 1911 |
"Redundant declaration of type arguments <String>\n" + |
| 1912 |
"----------\n" + |
| 1913 |
"3. ERROR in X.java (at line 10)\n" + |
| 1914 |
" X<Integer> x3 = new X<Integer>(1);\n" + |
| 1915 |
" ^\n" + |
| 1916 |
"Redundant declaration of type arguments <Integer>\n" + |
| 1917 |
"----------\n" + |
| 1918 |
"4. ERROR in X.java (at line 11)\n" + |
| 1919 |
" String s = foo(new X<String>(\"aaa\"));\n" + |
| 1920 |
" ^\n" + |
| 1921 |
"Redundant declaration of type arguments <String>\n" + |
| 1922 |
"----------\n", |
| 1923 |
null, |
| 1924 |
false, |
| 1925 |
customOptions); |
| 1926 |
} |
| 1927 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 1928 |
public void test0052c() { |
| 1929 |
Map customOptions = getCompilerOptions(); |
| 1930 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 1931 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 1932 |
this.runNegativeTest( |
| 1933 |
new String[] { |
| 1934 |
"X.java", |
| 1935 |
"public class X<E> {\n" + |
| 1936 |
" X(String abc, String def) {}\n" + |
| 1937 |
" void foo() {\n" + |
| 1938 |
" X<Integer> x = new X<Integer>(\"\",\"\");\n" + |
| 1939 |
" foo3(new X<Integer>(\"\",\"\"));\n" + |
| 1940 |
" }\n" + |
| 1941 |
" X<Integer> foo2() {\n" + |
| 1942 |
" return new X<Integer>(\"\",\"\");\n" + |
| 1943 |
" }\n" + |
| 1944 |
" void foo3(X<Integer> x) {}\n" + |
| 1945 |
"}" |
| 1946 |
}, |
| 1947 |
"----------\n" + |
| 1948 |
"1. ERROR in X.java (at line 4)\n" + |
| 1949 |
" X<Integer> x = new X<Integer>(\"\",\"\");\n" + |
| 1950 |
" ^\n" + |
| 1951 |
"Redundant declaration of type arguments <Integer>\n" + |
| 1952 |
"----------\n" + |
| 1953 |
"2. ERROR in X.java (at line 8)\n" + |
| 1954 |
" return new X<Integer>(\"\",\"\");\n" + |
| 1955 |
" ^\n" + |
| 1956 |
"Redundant declaration of type arguments <Integer>\n" + |
| 1957 |
"----------\n", |
| 1958 |
null, |
| 1959 |
false, |
| 1960 |
customOptions); |
| 1961 |
} |
| 1962 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 1963 |
public void test0053() { |
| 1964 |
Map customOptions = getCompilerOptions(); |
| 1965 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 1966 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 1967 |
this.runNegativeTest( |
| 1968 |
new String[] { |
| 1969 |
"Z.java", |
| 1970 |
"public class Z <T extends ZB> { \n" + |
| 1971 |
" public static void main(String[] args) {\n" + |
| 1972 |
" foo(new Z<ZB>());\n" + |
| 1973 |
" }\n" + |
| 1974 |
" static void foo(Z<ZB> z) {\n" + |
| 1975 |
" }\n" + |
| 1976 |
"}\n" + |
| 1977 |
"class ZB {\n" + |
| 1978 |
"}" |
| 1979 |
}, |
| 1980 |
"----------\n" + |
| 1981 |
"1. ERROR in Z.java (at line 3)\n" + |
| 1982 |
" foo(new Z<ZB>());\n" + |
| 1983 |
" ^\n" + |
| 1984 |
"Redundant declaration of type arguments <ZB>\n" + |
| 1985 |
"----------\n", |
| 1986 |
null, |
| 1987 |
false, |
| 1988 |
customOptions); |
| 1989 |
} |
| 1990 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 1991 |
public void test0054() { |
| 1992 |
Map customOptions = getCompilerOptions(); |
| 1993 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 1994 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 1995 |
this.runNegativeTest( |
| 1996 |
new String[] { |
| 1997 |
"Y.java", |
| 1998 |
"public class Y<V> {\n" + |
| 1999 |
" public static <W extends ABC> Y<W> make(Class<W> clazz) {\n" + |
| 2000 |
" return new Y<W>();\n" + |
| 2001 |
" }\n" + |
| 2002 |
"}\n" + |
| 2003 |
"class ABC{}\n" |
| 2004 |
}, |
| 2005 |
"----------\n" + |
| 2006 |
"1. ERROR in Y.java (at line 3)\n" + |
| 2007 |
" return new Y<W>();\n" + |
| 2008 |
" ^\n" + |
| 2009 |
"Redundant declaration of type arguments <W>\n" + |
| 2010 |
"----------\n", |
| 2011 |
null, |
| 2012 |
false, |
| 2013 |
customOptions); |
| 2014 |
} |
| 2015 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 2016 |
public void test0055() { |
| 2017 |
Map customOptions = getCompilerOptions(); |
| 2018 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 2019 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 2020 |
this.runNegativeTest( |
| 2021 |
new String[] { |
| 2022 |
"X.java", |
| 2023 |
"public class X<A> {\n" + |
| 2024 |
" class Inner<B> { }\n" + |
| 2025 |
" static class Inner2<C> { }\n" + |
| 2026 |
"\n" + |
| 2027 |
" void method() {\n" + |
| 2028 |
" X<String>.Inner<Integer> a= new X<String>().new Inner<Integer>();\n" + |
| 2029 |
" Inner<Integer> b= new X<A>().new Inner<Integer>();\n" + |
| 2030 |
" Inner<Integer> c= new Inner<Integer>();\n" + |
| 2031 |
" X<A>.Inner<Integer> e= new X<A>().new Inner<Integer>();\n" + |
| 2032 |
" X<A>.Inner<Integer> f= new Inner<Integer>();\n" + |
| 2033 |
" X.Inner2<Integer> d3 = new X.Inner2<Integer>();\n" + |
| 2034 |
" }\n" + |
| 2035 |
"}\n", |
| 2036 |
}, |
| 2037 |
"----------\n" + |
| 2038 |
"1. ERROR in X.java (at line 6)\n" + |
| 2039 |
" X<String>.Inner<Integer> a= new X<String>().new Inner<Integer>();\n" + |
| 2040 |
" ^^^^^\n" + |
| 2041 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2042 |
"----------\n" + |
| 2043 |
"2. ERROR in X.java (at line 7)\n" + |
| 2044 |
" Inner<Integer> b= new X<A>().new Inner<Integer>();\n" + |
| 2045 |
" ^^^^^\n" + |
| 2046 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2047 |
"----------\n" + |
| 2048 |
"3. ERROR in X.java (at line 8)\n" + |
| 2049 |
" Inner<Integer> c= new Inner<Integer>();\n" + |
| 2050 |
" ^^^^^\n" + |
| 2051 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2052 |
"----------\n" + |
| 2053 |
"4. ERROR in X.java (at line 9)\n" + |
| 2054 |
" X<A>.Inner<Integer> e= new X<A>().new Inner<Integer>();\n" + |
| 2055 |
" ^^^^^\n" + |
| 2056 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2057 |
"----------\n" + |
| 2058 |
"5. ERROR in X.java (at line 10)\n" + |
| 2059 |
" X<A>.Inner<Integer> f= new Inner<Integer>();\n" + |
| 2060 |
" ^^^^^\n" + |
| 2061 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2062 |
"----------\n" + |
| 2063 |
"6. ERROR in X.java (at line 11)\n" + |
| 2064 |
" X.Inner2<Integer> d3 = new X.Inner2<Integer>();\n" + |
| 2065 |
" ^^^^^^\n" + |
| 2066 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2067 |
"----------\n", |
| 2068 |
null, |
| 2069 |
false, |
| 2070 |
customOptions); |
| 2071 |
} |
| 2072 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 2073 |
// qualified allocation |
| 2074 |
public void test0056() { |
| 2075 |
Map customOptions = getCompilerOptions(); |
| 2076 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 2077 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 2078 |
this.runNegativeTest( |
| 2079 |
new String[] { |
| 2080 |
"X.java", |
| 2081 |
"public class X <T> {\n" + |
| 2082 |
" void foo1() {\n" + |
| 2083 |
" X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + |
| 2084 |
" }\n" + |
| 2085 |
" void foo2() {\n" + |
| 2086 |
" X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + |
| 2087 |
" }\n" + |
| 2088 |
" class Item <E> {}\n" + |
| 2089 |
"}\n" |
| 2090 |
}, |
| 2091 |
"----------\n" + |
| 2092 |
"1. ERROR in X.java (at line 3)\n" + |
| 2093 |
" X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + |
| 2094 |
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + |
| 2095 |
"Type mismatch: cannot convert from X<Exception>.Item<Thread> to X<String>.Item<Thread>\n" + |
| 2096 |
"----------\n" + |
| 2097 |
"2. ERROR in X.java (at line 3)\n" + |
| 2098 |
" X<String>.Item<Thread> i = new X<Exception>().new Item<Thread>();\n" + |
| 2099 |
" ^^^^\n" + |
| 2100 |
"Redundant declaration of type arguments <Thread>\n" + |
| 2101 |
"----------\n" + |
| 2102 |
"3. ERROR in X.java (at line 6)\n" + |
| 2103 |
" X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + |
| 2104 |
" ^^^^^^^^^^^^^^^^^\n" + |
| 2105 |
"Cannot allocate the member type X<Exception>.Item<Thread> using a parameterized compound name; use its simple name and an enclosing instance of type X<Exception>\n" + |
| 2106 |
"----------\n" + |
| 2107 |
"4. ERROR in X.java (at line 6)\n" + |
| 2108 |
" X<Exception>.Item<Thread> j = new X<Exception>.Item<Thread>();\n" + |
| 2109 |
" ^^^^\n" + |
| 2110 |
"Redundant declaration of type arguments <Thread>\n" + |
| 2111 |
"----------\n", |
| 2112 |
null, |
| 2113 |
false, |
| 2114 |
customOptions); |
| 2115 |
} |
| 2116 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 2117 |
// qualified allocation |
| 2118 |
public void test0056b() { |
| 2119 |
Map customOptions = getCompilerOptions(); |
| 2120 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 2121 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 2122 |
this.runNegativeTest( |
| 2123 |
new String[] { |
| 2124 |
"X.java", |
| 2125 |
"public class X <T> {\n" + |
| 2126 |
" static class X1<Z> {\n" + |
| 2127 |
" X1(Z z){}\n" + |
| 2128 |
" }\n" + |
| 2129 |
" X1<Integer> x1 = new X.X1<Integer>(1);\n" + |
| 2130 |
" X1<Number> x2 = new X.X1<Number>(1);\n" + |
| 2131 |
"}\n" |
| 2132 |
}, |
| 2133 |
"----------\n" + |
| 2134 |
"1. ERROR in X.java (at line 5)\n" + |
| 2135 |
" X1<Integer> x1 = new X.X1<Integer>(1);\n" + |
| 2136 |
" ^^\n" + |
| 2137 |
"Redundant declaration of type arguments <Integer>\n" + |
| 2138 |
"----------\n", |
| 2139 |
null, |
| 2140 |
false, |
| 2141 |
customOptions); |
| 2142 |
} |
| 2143 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 2144 |
public void test0057() { |
| 2145 |
Map customOptions = getCompilerOptions(); |
| 2146 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 2147 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 2148 |
this.runNegativeTest( |
| 2149 |
new String[] { |
| 2150 |
"X.java", |
| 2151 |
"public class X {\n" + |
| 2152 |
" void test() {\n" + |
| 2153 |
" Pair<Double, Integer> p = new InvertedPair<Integer, Double>();\n" + |
| 2154 |
" }\n" + |
| 2155 |
"}\n" + |
| 2156 |
"class Pair<A, B> {\n" + |
| 2157 |
"}\n" + |
| 2158 |
"class InvertedPair<A, B> extends Pair<B, A> {\n" + |
| 2159 |
"}\n" |
| 2160 |
}, |
| 2161 |
"----------\n" + |
| 2162 |
"1. ERROR in X.java (at line 3)\n" + |
| 2163 |
" Pair<Double, Integer> p = new InvertedPair<Integer, Double>();\n" + |
| 2164 |
" ^^^^^^^^^^^^\n" + |
| 2165 |
"Redundant declaration of type arguments <Integer, Double>\n" + |
| 2166 |
"----------\n", |
| 2167 |
null, |
| 2168 |
false, |
| 2169 |
customOptions); |
| 2170 |
} |
| 2171 |
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 |
| 2172 |
public void test0058() { |
| 2173 |
Map customOptions = getCompilerOptions(); |
| 2174 |
customOptions.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR); |
| 2175 |
customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); |
| 2176 |
this.runNegativeTest( |
| 2177 |
new String[] { |
| 2178 |
"X.java", |
| 2179 |
"import java.util.ArrayList;\n" + |
| 2180 |
"\n" + |
| 2181 |
"public class X {\n" + |
| 2182 |
" public void test(boolean param) {\n" + |
| 2183 |
" ArrayList<?> ls = (param) \n" + |
| 2184 |
" ? new ArrayList<String>()\n" + |
| 2185 |
" : new ArrayList<Object>();\n" + |
| 2186 |
" \n" + |
| 2187 |
" }\n" + |
| 2188 |
"}\n" |
| 2189 |
}, |
| 2190 |
"----------\n" + |
| 2191 |
"1. ERROR in X.java (at line 7)\n" + |
| 2192 |
" : new ArrayList<Object>();\n" + |
| 2193 |
" ^^^^^^^^^\n" + |
| 2194 |
"Redundant declaration of type arguments <Object>\n" + |
| 2195 |
"----------\n", |
| 2196 |
null, |
| 2197 |
false, |
| 2198 |
customOptions); |
| 2199 |
} |
| 1814 |
public static Class testClass() { |
2200 |
public static Class testClass() { |
| 1815 |
return GenericsRegressionTest_1_7.class; |
2201 |
return GenericsRegressionTest_1_7.class; |
| 1816 |
} |
2202 |
} |