Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSrikanth Sankaran2011-03-15 11:33:27 +0000
committerSrikanth Sankaran2011-03-15 11:33:27 +0000
commitca6a0d4f3bf98311c20a941f6f61f98507e3122c (patch)
tree50e3d953002621a7eb02c6fbf63b7dd832484440 /org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
parentacbefd89869bc2e1636c797e9888a047f0db1e79 (diff)
downloadeclipse.jdt.core-ca6a0d4f3bf98311c20a941f6f61f98507e3122c.tar.gz
eclipse.jdt.core-ca6a0d4f3bf98311c20a941f6f61f98507e3122c.tar.xz
eclipse.jdt.core-ca6a0d4f3bf98311c20a941f6f61f98507e3122c.zip
HEAD : Fixed bug 338011: COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS wrongly suppresses constructor parameter type
Fixed bug 337962: COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS misses reference to field from supertype
Diffstat (limited to 'org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java')
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java280
1 files changed, 280 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
index 2e8e618f2b..364221c156 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java
@@ -1460,4 +1460,284 @@ public void test337751a() {
compilerOptions15,
null);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
+public void test337962() {
+ Map compilerOptions15 = getCompilerOptions();
+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "import java.util.ArrayList;\n" +
+ "class Super {\n" +
+ " protected List fList;\n" +
+ "}\n" +
+ "public class X extends Super {\n" +
+ " protected List fSubList; // raw type warning (good)\n" +
+ " {\n" +
+ " fSubList = new ArrayList();\n " +
+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ " void foo(String s) {\n" +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ " X(String s) {\n" +
+ " fSubList = new ArrayList();\n " +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 4)\n" +
+ " protected List fList;\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 7)\n" +
+ " protected List fSubList; // raw type warning (good)\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 9)\n" +
+ " fSubList = new ArrayList();\n" +
+ " ^^^^^^^^^\n" +
+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" +
+ "----------\n" +
+ "4. WARNING in X.java (at line 10)\n" +
+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 11)\n" +
+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "6. WARNING in X.java (at line 12)\n" +
+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "7. WARNING in X.java (at line 15)\n" +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "8. WARNING in X.java (at line 16)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "9. WARNING in X.java (at line 17)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "10. WARNING in X.java (at line 20)\n" +
+ " fSubList = new ArrayList();\n" +
+ " ^^^^^^^^^\n" +
+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" +
+ "----------\n" +
+ "11. WARNING in X.java (at line 21)\n" +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "12. WARNING in X.java (at line 22)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "13. WARNING in X.java (at line 23)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n",
+ null,
+ false,
+ compilerOptions15,
+ null);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962
+public void test337962b() {
+ Map compilerOptions15 = getCompilerOptions();
+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.List;\n" +
+ "import java.util.ArrayList;\n" +
+ "class Super {\n" +
+ " protected List fList;\n" +
+ "}\n" +
+ "public class X extends Super {\n" +
+ " protected List fSubList; // raw type warning (good)\n" +
+ " {\n" +
+ " fSubList = new ArrayList();\n " +
+ " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ " void foo(String s) {\n" +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ " X(String s) {\n" +
+ " fSubList = new ArrayList();\n " +
+ " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 4)\n" +
+ " protected List fList;\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 7)\n" +
+ " protected List fSubList; // raw type warning (good)\n" +
+ " ^^^^\n" +
+ "List is a raw type. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 9)\n" +
+ " fSubList = new ArrayList();\n" +
+ " ^^^^^^^^^\n" +
+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" +
+ "----------\n" +
+ "4. WARNING in X.java (at line 12)\n" +
+ " fSubList.add(null); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 17)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n" +
+ "6. WARNING in X.java (at line 20)\n" +
+ " fSubList = new ArrayList();\n" +
+ " ^^^^^^^^^\n" +
+ "ArrayList is a raw type. References to generic type ArrayList<E> should be parameterized\n" +
+ "----------\n" +
+ "7. WARNING in X.java (at line 23)\n" +
+ " fSubList.add(s); // type safety warning (good, should not be hidden)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method add(Object) belongs to the raw type List. References to generic type List<E> should be parameterized\n" +
+ "----------\n",
+ null,
+ false,
+ compilerOptions15,
+ null);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011
+public void test338011() {
+ Map compilerOptions15 = getCompilerOptions();
+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X extends A {\n" +
+ " public X(Map m) { // should warn about raw type m\n" +
+ " super(m);\n" +
+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" +
+ " }\n" +
+ " public X(Map<String, Integer> m, boolean b) {\n" +
+ " super(m); // shows that parametrizing the parameter type is no problem \n" +
+ " new A(m);\n" +
+ " m.put(\"one\", 1);\n" +
+ " }\n" +
+ "}\n" +
+ "class A {\n" +
+ " public A (Map m) {\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " public X(Map m) { // should warn about raw type m\n" +
+ " ^^^\n" +
+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 5)\n" +
+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 14)\n" +
+ " public A (Map m) {\n" +
+ " ^^^\n" +
+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n",
+ null,
+ false,
+ compilerOptions15,
+ null);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011
+public void test338011b() {
+ Map compilerOptions15 = getCompilerOptions();
+ compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X extends A {\n" +
+ " public X(Map m) { // should warn about raw type m\n" +
+ " super(m);\n" +
+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" +
+ " }\n" +
+ " public X(Map<String, Integer> m, boolean b) {\n" +
+ " super(m); // shows that parametrizing the parameter type is no problem \n" +
+ " new A(m);\n" +
+ " m.put(\"one\", 1);\n" +
+ " }\n" +
+ "}\n" +
+ "class A {\n" +
+ " public A (Map m) {\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " public X(Map m) { // should warn about raw type m\n" +
+ " ^^^\n" +
+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 5)\n" +
+ " m.put(\"one\", 1); // warns about raw method invocation (good)\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 14)\n" +
+ " public A (Map m) {\n" +
+ " ^^^\n" +
+ "Map is a raw type. References to generic type Map<K,V> should be parameterized\n" +
+ "----------\n",
+ null,
+ false,
+ compilerOptions15,
+ null);
+}
} \ No newline at end of file

Back to the top