From 85c859c11b02ab71b4df3be6ee021863954de60d Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 25 Jul 2024 17:53:50 +0200 Subject: [PATCH 1/7] Fixed tests failing after requiring minimal 1.8 compliance - TypeCompletionTest, - CodeCompletionTest, - MissingTypeCompletionTest, - PluginsNotLoadedTest See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../jdt/text/tests/PluginsNotLoadedTest.java | 4 +- .../contentassist/CodeCompletionTest.java | 169 ++++++++++-------- .../MissingTypeCompletionTest.java | 2 +- .../contentassist/TypeCompletionTest.java | 8 +- 4 files changed, 97 insertions(+), 86 deletions(-) diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java index a77abe25bbc..d71b8ec4d04 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/PluginsNotLoadedTest.java @@ -88,7 +88,7 @@ public class PluginsNotLoadedTest { "org.eclipse.help.ui", "org.eclipse.help.webapp", "org.eclipse.jdt", - "org.eclipse.jdt.apt.core", +// "org.eclipse.jdt.apt.core", loaded for Java 1.8+ projects "org.eclipse.jdt.apt.ui", "org.eclipse.jdt.compiler.apt", "org.eclipse.jdt.compiler.tool", @@ -163,7 +163,7 @@ public class PluginsNotLoadedTest { "org.eclipse.equinox.launcher", "org.eclipse.equinox.launcher.win32.win32.x86", "org.eclipse.help.appserver", - "org.eclipse.jdt.apt.pluggable.core", +// "org.eclipse.jdt.apt.pluggable.core", loaded for Java 1.8+ projects "org.eclipse.jdt.source", "org.eclipse.jsch.ui", "org.eclipse.osgi.util", diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java index e81d5682a6e..92d8bf52aa8 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/CodeCompletionTest.java @@ -249,6 +249,7 @@ public class A { public void foo() { Runnable run= new Runnable() { \s + @Override public void run() { //TODO \s @@ -299,6 +300,7 @@ public class A { public void foo() { Runnable run= new Runnable() { \s + @Override public void run() { //TODO \s @@ -355,6 +357,7 @@ interface Inner { public void foo() { Inner inner= new Inner() { \s + @Override public void doIt() { //TODO \s @@ -573,6 +576,7 @@ public void foo() { + ") {\n" + " \n" + + " @Override\n" + " public Object test(@Nullable Object i1, Object i2) {\n" + " //TODO\n" + " return null;\n" + @@ -641,6 +645,7 @@ public void foo() { + ") {\n" + " \n" + + " @Override\n" + " public Object test(@Nullable Object i1, Object i2) {\n" + " //TODO\n" + " return null;\n" + @@ -702,6 +707,7 @@ public class A { + ") {\n" + " \n" + + " @Override\n" + " public Object test(@Nullable Object i1, Object i2) {\n" + " //TODO\n" + " return null;\n" + @@ -726,6 +732,7 @@ public void testAnonymousTypeCompletion10() throws Exception { package test1; import annots.*; public interface Ifc { + @Override @NonNull Object test(@Nullable Object i1, @NonNull Object i2); } """; @@ -765,6 +772,7 @@ public class A { + ") {\n" + " \n" + + " @Override\n" + " public Object test(@Nullable Object i1, Object i2) {\n" + " //TODO\n" + " return null;\n" + @@ -813,6 +821,7 @@ public class Try { Object m() { return new Runnable() { \s + @Override public void run() { //TODO \s @@ -863,6 +872,7 @@ public class Try { Object m() { take(new Runnable() { \s + @Override public void run() { //TODO \s @@ -913,6 +923,7 @@ public class Try { Object m() { take(new Runnable() { \s + @Override public void run() { //TODO \s @@ -990,9 +1001,9 @@ public void testConstructorCompletion() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.BufferedWriter; - + public class MyClass { private BufferedWriter writer; //here @@ -1026,9 +1037,9 @@ public class MyClass { String str1= """ package test1; - + import java.io.BufferedWriter; - + public class MyClass { private BufferedWriter writer; /** @@ -1036,7 +1047,7 @@ public class MyClass { */ public MyClass() { //TODO - + }//here } """; @@ -1053,13 +1064,13 @@ public void testEnumCompletions() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + enum Natural { ONE, TWO, THREE } - + public class Completion { \s void foomethod() { @@ -1092,13 +1103,13 @@ void foomethod() { String result= """ package test1; - + enum Natural { ONE, TWO, THREE } - + public class Completion { \s void foomethod() { @@ -1129,9 +1140,9 @@ public void testGetterCompletion1() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter fWriter; get//here @@ -1165,9 +1176,9 @@ public class A { String str1= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter fWriter; /** @@ -1191,9 +1202,9 @@ public void testMethodCompletion() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter writer; foo//here @@ -1227,9 +1238,9 @@ public class A { String str1= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter writer; /** @@ -1237,7 +1248,7 @@ public class A { */ private void foo() { //TODO - + }//here } """; @@ -1254,7 +1265,7 @@ public void testNormalAllMethodCompletion() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + public class Completion { \s void foomethod() { @@ -1306,7 +1317,7 @@ public void testNormalAllMethodCompletionWithParametersGuessed() throws Exceptio IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + public class Completion { \s void foomethod() { @@ -1359,7 +1370,7 @@ public void testNormalAllMethodCompletionWithParametersNames() throws Exception IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + public class Completion { \s void foomethod() { @@ -1412,7 +1423,7 @@ public void testNormalMethodCompletion() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + public class Completion { \s void foomethod() { @@ -1445,7 +1456,7 @@ void foomethod() { String result= """ package test1; - + public class Completion { \s void foomethod() { @@ -1464,9 +1475,9 @@ public void testOverrideCompletion1() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.Writer; - + public class A extends Writer { public void foo() { } @@ -1501,9 +1512,9 @@ public void foo() { String str1= """ package test1; - + import java.io.Writer; - + public class A extends Writer { public void foo() { } @@ -1527,9 +1538,9 @@ public void testOverrideCompletion2() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.Writer; - + public class A extends Writer { public void foo() { } @@ -1563,10 +1574,10 @@ public void foo() { String str1= """ package test1; - + import java.io.IOException; import java.io.Writer; - + public class A extends Writer { public void foo() { } @@ -1589,9 +1600,9 @@ public void testOverrideCompletion3() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.BufferedWriter; - + public class A extends BufferedWriter { public void foo() { } @@ -1626,10 +1637,10 @@ public void foo() { String str1= """ package test1; - + import java.io.BufferedWriter; import java.io.IOException; - + public class A extends BufferedWriter { public void foo() { } @@ -1653,7 +1664,7 @@ public void testOverrideCompletion4() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String str1= """ package test1; - + public class A { public void foo() { } @@ -1663,7 +1674,7 @@ public void foo() { String str2= """ package test1; - + public interface Inter { public void foo(); } @@ -1672,7 +1683,7 @@ public interface Inter { String str3= """ package test1; - + public class B extends A implements Inter { foo//here } @@ -1706,7 +1717,7 @@ public class B extends A implements Inter { String str4= """ package test1; - + public class B extends A implements Inter { /* (non-Javadoc) * @see test1.A#foo() @@ -1730,7 +1741,7 @@ public void testOverrideCompletion5() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + public class A { public void foo() { new Runnable() { @@ -1767,7 +1778,7 @@ public void foo() { String str1= """ package test1; - + public class A { public void foo() { new Runnable() { @@ -1776,7 +1787,7 @@ public void foo() { */ public void run() { //TODO - + }//here } } @@ -1792,7 +1803,7 @@ public void testOverrideCompletion6_bug157069() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String str1= """ package test1; - + public class A { public class Sub { } public void foo(Sub sub) { @@ -1803,7 +1814,7 @@ public void foo(Sub sub) { String str2= """ package test1; - + public class B extends A { foo//here } @@ -1837,7 +1848,7 @@ public class B extends A { String str3= """ package test1; - + public class B extends A { /* (non-Javadoc) * @see test1.A#foo(test1.A.Sub) @@ -1860,9 +1871,9 @@ public void testOverrideCompletion7_bug355926() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + interface Z {} - + class A { void foo(Z... zs) { } @@ -1899,9 +1910,9 @@ class B extends A { String str1= """ package test1; - + interface Z {} - + class A { void foo(Z... zs) { } @@ -1928,9 +1939,9 @@ public void testOverrideCompletion8_bug355926() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + interface Z {} - + class A { void foo(Z[] zs) { } @@ -1967,9 +1978,9 @@ class B extends A { String str1= """ package test1; - + interface Z {} - + class A { void foo(Z[] zs) { } @@ -1996,11 +2007,11 @@ public void testOverrideCompletion9_bug355926() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.util.List; - + interface Z {} - + class A { void foo(Z> zs) { } @@ -2037,11 +2048,11 @@ class B extends A { String str1= """ package test1; - + import java.util.List; - + interface Z {} - + class A { void foo(Z> zs) { } @@ -2185,9 +2196,9 @@ public void testSetterCompletion1() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String contents= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter writer; se//here @@ -2221,9 +2232,9 @@ public class A { String str1= """ package test1; - + import java.io.BufferedWriter; - + public class A { private BufferedWriter writer; /** @@ -2250,7 +2261,7 @@ public void testStaticImports1() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String str1= """ package test1; - + public class A { public static void foo() { } @@ -2260,7 +2271,7 @@ public static void foo() { String contents= """ package test1; - + public class B { public void bar() { f//here @@ -2298,9 +2309,9 @@ public void bar() { String str2= """ package test1; - + import static test1.A.foo; - + public class B { public void bar() { foo();//here @@ -2325,7 +2336,7 @@ public void testStaticImports2() throws Exception { IPackageFragment pack1= sourceFolder.createPackageFragment("test1", false, null); String str1= """ package test1; - + public class A { public static void foo() { } @@ -2336,7 +2347,7 @@ public static void foo() { IPackageFragment pack2= sourceFolder.createPackageFragment("test2", false, null); String contents= """ package test2; - + public class B { public void bar() { f//here @@ -2378,9 +2389,9 @@ public void foo(int x) { String str2= """ package test2; - + import test1.A; - + public class B { public void bar() { A.foo();//here @@ -2603,7 +2614,7 @@ public ArgImpl() { \s } \s public static void main(String[] args) throws Exception {\s InvokerIF test = new Invoker(); \s - test.invoke(new ArgImpl()) \s + test.invoke(new ArgImpl<>()) \s } \s } \s """; @@ -2616,7 +2627,7 @@ public void testBug466252() throws CoreException { IPackageFragment pack1= sourceFolder.createPackageFragment("p", false, null); String str1= """ package p; - + public class C { void foo() { try { @@ -2656,17 +2667,17 @@ public void testCompletionInPackageInfo() throws Exception { String str= """ package annots; - + public enum DefaultLocation { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS, TYPE_PARAMETER } """; pack0.createCompilationUnit("DefaultLocation.java", str, false, null); String str1= """ package annots; - + import java.lang.annotation.*; import static annots.DefaultLocation.*; - + @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS) @Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE }) public @interface NonNullByDefault { DefaultLocation[] value() default {PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT}; } @@ -2710,7 +2721,7 @@ public enum DefaultLocation { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_AR String expected= """ @annots.NonNullByDefault({ARRAY_CONTENTS}) package test1; - + import static annots.DefaultLocation.ARRAY_CONTENTS; """; assertEquals(expected, doc.get()); @@ -2807,7 +2818,7 @@ public void testArgumentName() throws CoreException { """ package pack; class A { - + public static void main(String[] argv new Member().f ; @@ -2831,7 +2842,7 @@ int foo() """ package pack; class A { - + public static void main(String[] argvStrings new Member().f ; diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MissingTypeCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MissingTypeCompletionTest.java index c2df6ad0a7e..7f79779c34d 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MissingTypeCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/MissingTypeCompletionTest.java @@ -75,7 +75,7 @@ public static class Member {} public void testGenericType_constructor() throws Exception { createMissingType("public class MissingType {\n" + "}\n"); - assertMethodBodyProposal("new MissingType", "MissingType", "new MissingType()"); + assertMethodBodyProposal("new MissingType", "MissingType", "new MissingType<>()"); } } diff --git a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/TypeCompletionTest.java b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/TypeCompletionTest.java index c9efbb640d2..a95624e2e0d 100644 --- a/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/TypeCompletionTest.java +++ b/org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/contentassist/TypeCompletionTest.java @@ -167,7 +167,7 @@ public void testGenericParameterGuessingUnambiguos() throws Exception { addImport("java.util.List"); expectImport("java.util.ArrayList"); expectImport("java.util.List"); - assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList()|"); + assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList<>()|"); } @Test @@ -175,7 +175,7 @@ public void testGenericParameterGuessingExtends() throws Exception { addImport("java.util.List"); expectImport("java.util.ArrayList"); expectImport("java.util.List"); - assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList()|"); + assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList<>()|"); } @Test @@ -183,7 +183,7 @@ public void testGenericParameterGuessingSuper() throws Exception { addImport("java.util.List"); expectImport("java.util.ArrayList"); expectImport("java.util.List"); - assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList()|"); + assertMethodBodyProposal("List list= new A|", "ArrayList()", "List list= new ArrayList<>()|"); } @Test @@ -191,7 +191,7 @@ public void testGenericParameterGuessingMixed() throws Exception { addImport("java.util.Map"); expectImport("java.util.HashMap"); expectImport("java.util.Map"); - assertMethodBodyProposal("Map list= new H|", "HashMap()", "Map list= new HashMap()|"); + assertMethodBodyProposal("Map list= new H|", "HashMap()", "Map list= new HashMap<>()|"); } @Test From 1d3de403c3a4fbfb51d8eaba2547a45668f22ba3 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 25 Jul 2024 18:33:49 +0200 Subject: [PATCH 2/7] Fixed tests failing after requiring minimal 1.8 compliance, part 2 - LocalCorrectionsQuickFixTest - MethodOverrideTest See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../jdt/ui/tests/core/MethodOverrideTest.java | 22 +-- .../LocalCorrectionsQuickFixTest.java | 149 ++++++------------ 2 files changed, 60 insertions(+), 111 deletions(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java index 21d32c0c149..eae03a5f464 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/MethodOverrideTest.java @@ -144,10 +144,10 @@ public B() {} @Override public void o1_foo4(S... t) {} @Override public void o1_foo5(A s) {} @Override public void o1_foo6(A s) {} - @Override public void o1_foo7(S[] t) {} - @Override public void o1_xoo1(S[][] t) {} - @Override public void o1_xoo2(A s) {} - @Override public void o1_xoo3(A s) {} + @Override public void o1_foo7(S... t) {} + @Override public void o1_xoo1(S[] t) {} + @Override public void o1_xoo2(A s) {} + @Override public void o1_xoo3(A s) {} } """; ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); @@ -172,7 +172,7 @@ public void o2_xoo1(List t) {} class B extends A { public B() {} @Override public void o2_foo1(Map t) {} - @Override public void o2_xoo1(List t) {} + @Override public void o2_xoo1(List t) {} } """; ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); @@ -196,7 +196,7 @@ public void o3_xoo1(List t) {} class B extends A { public B() {} @Override public void o3_foo1(List t) {} - @Override public void o3_xoo1(List t) {} + @Override public void o3_xoo1(List t) {} } """; ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); @@ -224,7 +224,7 @@ public B() {} @Override public void o4_foo1(List[] t) {} @Override public void o4_foo2(List t) {} @Override public void o4_foo3(List t) {} - @Override public void o4_xoo1(List t) {} + @Override public void o4_xoo1(List t) {} } """; ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); @@ -261,10 +261,10 @@ public B() {} @Override public void tp1_foo3(V x, W y) {} @Override public void tp1_foo4(X x) {} @Override public void tp1_foo5(X x) {} - @Override public void tp1_xoo1(String s, X x, Object y) {} - @Override public void tp1_xoo2() {} - @Override public void tp1_xoo3(V x, W y) {} - @Override public void tp1_xoo5(Number x) {} + @Override public void tp1_xoo1(String s, X x, Y y) {} + @Override public void tp1_xoo2() {} + @Override public void tp1_xoo3(W x, V y) {} + @Override public void tp1_xoo5(X x) {} } """; ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java index f1d458ee796..612e8a336bb 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/LocalCorrectionsQuickFixTest.java @@ -54,7 +54,6 @@ import org.eclipse.jdt.internal.core.manipulation.CodeTemplateContextType; import org.eclipse.jdt.internal.core.manipulation.StubUtility; -import org.eclipse.jdt.internal.corext.util.JavaModelUtil; import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jdt.ui.tests.core.rules.ProjectTestSetup; @@ -1070,7 +1069,7 @@ public void foo() throws ParseException { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 2); + assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); @@ -1088,10 +1087,12 @@ public String goo() throws IOException, ParseException { /** * Not much to say here. * @throws ParseException Parsing failed - * @throws IOException\s */ - public void foo() throws ParseException, IOException { - goo().substring(2); + public void foo() throws ParseException { + try { + goo().substring(2); + } catch (IOException | ParseException e) { + } } } """; @@ -1151,7 +1152,7 @@ public void foo() { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 2); - assertNumberOfProposals(proposals, 2); + assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); @@ -1171,11 +1172,12 @@ public E bar() throws FileNotFoundException { } /** * Not much to say here. - * @throws InterruptedIOException\s - * @throws FileNotFoundException\s */ - public void foo() throws FileNotFoundException, InterruptedIOException { - goo(1).bar(); + public void foo() { + try { + goo(1).bar(); + } catch (FileNotFoundException | InterruptedIOException e) { + } } } """; @@ -1519,7 +1521,7 @@ public void foo() { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 3); + assertNumberOfProposals(proposals, 4); assertCorrectLabels(proposals); @@ -1534,10 +1536,11 @@ public class E { public static void goo() throws IOException, ParseException { return; } - public void foo() throws ParseException { + public void foo() { try { E.goo(); } catch (IOException e) { + } catch (ParseException e) { } } } @@ -1580,8 +1583,7 @@ public static void goo() throws IOException, ParseException { public void foo() { try { E.goo(); - } catch (IOException e) { - } catch (ParseException e) { + } catch (IOException | ParseException e) { } } } @@ -1882,7 +1884,7 @@ public void m2() throws IOException, ParseException, MyException { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 2); // 2 uncaught exceptions - assertNumberOfProposals(proposals, 2); + assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); @@ -1894,8 +1896,11 @@ public void m2() throws IOException, ParseException, MyException { import java.io.IOException; import java.text.ParseException; public class E { - public void m1() throws IOException, ParseException, MyException { - m2(); + public void m1() throws IOException { + try { + m2(); + } catch (IOException | ParseException | MyException e) { + } } public void m2() throws IOException, ParseException, MyException { } @@ -1946,7 +1951,7 @@ public void foo() { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 2); // 2 uncaught exceptions - assertNumberOfProposals(proposals, 2); + assertNumberOfProposals(proposals, 3); assertCorrectLabels(proposals); @@ -1960,8 +1965,11 @@ public void foo() { public class E { public void goo() throws IOException, ParseException { } - public void foo() throws IOException, ParseException { - goo(); + public void foo() { + try { + goo(); + } catch (IOException | ParseException e) { + } } } """; @@ -3059,6 +3067,7 @@ public abstract class E implements Inter{ import test2.Inter; public class E implements Inter{ + @Override public int getCount(Object[] o) throws IOException { return 0; } @@ -3125,6 +3134,7 @@ public abstract class E extends InterImpl { import test2.InterImpl; public class E extends InterImpl { + @Override public int getCount(Object[] o) throws IOException { return 0; } @@ -3183,6 +3193,7 @@ public class E extends A implements Inter { import test2.Inter; public class E extends A implements Inter { + @Override public int foo() { return 0; } @@ -3236,6 +3247,7 @@ public void c() throws Exception, RuntimeException { } public class A implements F { public void c() throws Exception, RuntimeException { } + @Override public void e() { } } @@ -3295,9 +3307,11 @@ public class A implements F { public class A implements F { + @Override public void b(Properties p) { } + @Override public void g(test2.Properties p) { } } @@ -3351,6 +3365,7 @@ public class A implements IT { package test2; public class A implements IT { + @Override public void foo(java.lang.Class clazz) { } } @@ -3411,6 +3426,7 @@ public abstract class E implements Inter { public class E implements Inter { + @Override public String doT(Collection in) { return null; } @@ -3459,6 +3475,7 @@ public abstract class E implements Inter { package test1; public class E implements Inter { + @Override public String doT(String in) { return null; } @@ -3515,10 +3532,12 @@ public abstract class E implements Inter { public class E implements Inter { + @Override public T doX(Collection in) { return null; } + @Override public T getException() { return null; } @@ -3582,6 +3601,7 @@ public List findPerspectiveElements(Class clazz, List tagsToMa return null; } + @Override public List findElements(Class clazz, List tagsToMatch) { return null; } @@ -3649,6 +3669,7 @@ interface IA { enum TestEnum implements IA { test1,test2; + @Override public void foo() { } } @@ -3772,6 +3793,7 @@ enum TestEnum implements Runnable { package test; enum TestEnum implements Runnable { A { + @Override public void run() { } @Override @@ -3899,6 +3921,7 @@ interface I { package test; public class A implements I { + @Override public void foo() { } } @@ -4194,6 +4217,7 @@ interface Interface1 { Object getX(); } interface Interface2 { Integer getX(); } class Cls implements Interface1, Interface2 { + @Override public Integer getX() { return null; } @@ -4252,6 +4276,7 @@ interface D extends A, B, C {} //Add unimplemented methods class M implements D { + @Override public Object m(Class c) { return null; } @@ -4295,6 +4320,7 @@ interface D extends A, B {} class M implements D { + @Override public Object m(Class c) { return null; } @@ -4338,6 +4364,7 @@ interface D extends B, A {} class M implements D { + @Override public Object m(Class c) { return null; } @@ -11832,7 +11859,7 @@ public class CollectionsTest { public class CollectionsTest { public void foo(Map map) { }; { - foo(Collections.emptyMap()); + foo(Collections.emptyMap()); } } """; @@ -11878,7 +11905,7 @@ public class CollectionsTest { public class CollectionsTest { public void foo(Map map) { }; { - foo(Collections.emptyMap()); + foo(Collections.emptyMap()); } } """; @@ -12614,50 +12641,6 @@ void foo(Collection collection) { } } - @Test - public void testInsertInferredTypeArguments() throws Exception { - - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - import java.util.ArrayList; - import java.util.List; - - public class E { - - private void foo() { - List al1 = new ArrayList<>(); - - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - ArrayList proposals= collectCorrections2(cu, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal)proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - import java.util.ArrayList; - import java.util.List; - - public class E { - - private void foo() { - List al1 = new ArrayList(); - - } - } - """; - assertEqualString(preview, str1); - - String expected1= str1; - assertExpectedExistInProposals(proposals, new String[] { expected1 }); - } - // regression test for https://bugs.eclipse.org/434188 - [quick fix] shows sign of quick fix, but says no suggestions available. @Test public void testNoFixFor_ParsingErrorInsertToComplete() throws Exception { @@ -12706,40 +12689,6 @@ void foo(Map map) { JavaCorrectionProcessor.hasCorrections(cu, IProblem.ParsingErrorInsertToComplete, IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER)); } - @Test - public void testConvertLambdaToAnonymous() throws Exception { - assertFalse("error should not appear in 1.8 or higher", JavaModelUtil.is1d8OrHigher(fJProject1)); - - IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); - String str= """ - package p; - - public class Lambda { - Runnable r= () -> { System.out.println(Lambda.this.r); }; - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("Lambda.java", str, false, null); - - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - - assertCorrectLabels(proposals); - assertNumberOfProposals(proposals, 2); - - String[] expected= new String[2]; - expected[0]= """ - package p; - - public class Lambda { - Runnable r= new Runnable() { - public void run() { System.out.println(Lambda.this.r); } - }; - } - """; - - assertExpectedExistInProposals(proposals, expected); - } - @Test public void testCreateNewObjectProposal_1() throws Exception { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=395216 From 754889cfbf125f026e0d7de7ab828a185c36d140 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 25 Jul 2024 21:26:36 +0200 Subject: [PATCH 3/7] Fixed tests failing after requiring minimal 1.8 compliance, part 3 - GenerateToStringTest - AnnotateAssistTest1d5 - AnnotateAssistTest1d8 - AssistQuickFixTest - AssistQuickFixTest1d7 See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../core/source/GenerateToStringTest.java | 17 ++- .../tests/quickfix/AnnotateAssistTest1d5.java | 16 +-- .../tests/quickfix/AnnotateAssistTest1d8.java | 2 +- .../ui/tests/quickfix/AssistQuickFixTest.java | 117 ++---------------- .../tests/quickfix/AssistQuickFixTest1d7.java | 33 ----- 5 files changed, 33 insertions(+), 152 deletions(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java index d08667d1a8e..40a2f91e1b6 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/core/source/GenerateToStringTest.java @@ -116,10 +116,10 @@ private void setCompilerLevels(boolean is50orHigher, boolean is60orHigher) throw jp.setRawClasspath(newCP.toArray(new IClasspathEntry[newCP.size()]), null); } if (is60orHigher) { - JavaProjectHelper.addRTJar16(jp); + JavaProjectHelper.addRTJar18(jp); } if (!is50orHigher) { - JavaProjectHelper.addRTJar13(jp); + JavaProjectHelper.addRTJar18(jp); } } @@ -511,6 +511,7 @@ public void concatArrayLimit1_4() throws Exception { + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + + " @Override\r\n" + " public String toString() {\r\n" + " final int maxLen = 10;\r\n" + " return \"A [AArray=\" + (AArray != null ? arrayToString(AArray, AArray.length, maxLen) : null) + \", aBool=\" + aBool + \", anA=\" + anA + \", floatArray=\" + (floatArray != null ? arrayToString(floatArray, floatArray.length, maxLen) : null) + \", hashMap=\" + (hashMap != null ? toString(hashMap.entrySet(), maxLen) : null) + \", intArray=\" + (intArray != null ? arrayToString(intArray, intArray.length, maxLen) : null) + \", integerCollection=\" + (integerCollection != null ? toString(integerCollection, maxLen) : null) + \", list=\" + (list != null ? toString(list, maxLen) : null) + \", object=\" + object + \", stringArray=\" + (stringArray != null ? arrayToString(stringArray, stringArray.length, maxLen) : null) + \", wildCollection=\" + (wildCollection != null ? toString(wildCollection, maxLen) : null) + \", charArrayMethod()=\" + (charArrayMethod() != null ? arrayToString(charArrayMethod(), charArrayMethod().length, maxLen) : null) + \", floatArrayMethod()=\"\r\n" @@ -571,6 +572,7 @@ public void concatArrayLimit1_4Unique() throws Exception { + " Object len;\r\n" + " Object collection;\r\n" + " Object array;\r\n" + + " @Override\r\n" + " public String toString() {\r\n" + " final int maxLen2 = 10;\r\n" + " return \"A [aBool=\" + aBool + \", intArray=\" + (intArray != null ? arrayToString(intArray, intArray.length, maxLen2) : null) + \", stringArray=\" + (stringArray != null ? arrayToString(stringArray, stringArray.length, maxLen2) : null) + \", AArray=\" + (AArray != null ? arrayToString(AArray, AArray.length, maxLen2) : null) + \", list=\" + (list != null ? toString(list, maxLen2) : null) + \", hashMap=\" + (hashMap != null ? toString(hashMap.entrySet(), maxLen2) : null) + \", wildCollection=\" + (wildCollection != null ? toString(wildCollection, maxLen2) : null) + \", integerCollection=\" + (integerCollection != null ? toString(integerCollection, maxLen2) : null) + \", builder=\" + builder + \", buffer=\" + buffer + \", maxLen=\" + maxLen + \", len=\" + len + \", collection=\" + collection + \", array=\" + array + \"]\";\r\n" @@ -1351,7 +1353,9 @@ public void builderArrayLimit1_4() throws Exception { String expected= "package p;\r\n" + "\r\n" + "import java.util.Collection;\r\n" + "import java.util.HashMap;\r\n" + "import java.util.Iterator;\r\n" + "import java.util.List;\r\n" + "\r\n" + "public class A {\r\n" + "\r\n" + " boolean aBool;\r\n" + " Object object;\r\n" + " A anA;\r\n" + " int[] intArray;\r\n" + " float[] floatArray;\r\n" + " String[] stringArray;\r\n" + " A[] AArray;\r\n" + " char[] charArrayMethod() {\r\n" + " return new char[0];\r\n" + " }\r\n" + " float[] floatArrayMethod() {\r\n" + " return null;\r\n" + " }\r\n" - + " List list;\r\n" + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + " public String toString() {\r\n" + + " List list;\r\n" + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + + " @Override\r\n" + + " public String toString() {\r\n" + " final int maxLen = 10;\r\n" + " StringBuffer buffer = new StringBuffer();\r\n" + " buffer.append(\"A [AArray=\");\r\n" + " buffer.append(AArray != null ? arrayToString(AArray, AArray.length, maxLen) : null);\r\n" + " buffer.append(\", aBool=\");\r\n" + " buffer.append(aBool);\r\n" + " buffer.append(\", anA=\");\r\n" + " buffer.append(anA);\r\n" + " buffer.append(\", floatArray=\");\r\n" @@ -1403,7 +1407,9 @@ public void builderArrayLimit1_4Unique() throws Exception { String expected= "package p;\r\n" + "\r\n" + "import java.util.Collection;\r\n" + "import java.util.HashMap;\r\n" + "import java.util.Iterator;\r\n" + "import java.util.List;\r\n" + "\r\n" + "public class A {\r\n" + "\r\n" + " boolean aBool;\r\n" + " int[] intArray;\r\n" + " String[] stringArray;\r\n" + " A[] AArray;\r\n" + " List list;\r\n" + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + " Object builder;\r\n" + " Object buffer;\r\n" + " Object maxLen;\r\n" + " Object len;\r\n" - + " Object collection;\r\n" + " Object array;\r\n" + " public String toString() {\r\n" + " final int maxLen2 = 10;\r\n" + " StringBuffer buffer2 = new StringBuffer();\r\n" + + " Object collection;\r\n" + " Object array;\r\n" + + " @Override\r\n" + + " public String toString() {\r\n" + " final int maxLen2 = 10;\r\n" + " StringBuffer buffer2 = new StringBuffer();\r\n" + " buffer2.append(\"A [aBool=\");\r\n" + " buffer2.append(aBool);\r\n" + " buffer2.append(\", intArray=\");\r\n" + " buffer2.append(intArray != null ? arrayToString(intArray, intArray.length, maxLen2) : null);\r\n" + " buffer2.append(\", stringArray=\");\r\n" + " buffer2.append(stringArray != null ? arrayToString(stringArray, stringArray.length, maxLen2) : null);\r\n" + " buffer2.append(\", AArray=\");\r\n" @@ -1883,6 +1889,7 @@ public void chainedBuilderArrayLimit1_4() throws Exception { + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + + " @Override\r\n" + " public String toString() {\r\n" + " final int maxLen = 10;\r\n" + " StringBuffer buffer = new StringBuffer();\r\n" @@ -2452,6 +2459,7 @@ public void formatLimit1_4() throws Exception { + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + + " @Override\r\n" + " public String toString() {\r\n" + " final int maxLen = 10;\r\n" + " return MessageFormat.format(\"A [AArray={0}, aBool={1}, anA={2}, floatArray={3}, hashMap={4}, intArray={5}, integerCollection={6}, list={7}, object={8}, stringArray={9}, wildCollection={10}, charArrayMethod()={11}, floatArrayMethod()={12}]\", new Object[]{AArray, new Boolean(aBool), anA, floatArray, hashMap != null ? toString(hashMap.entrySet(), maxLen) : null, intArray, integerCollection != null ? toString(integerCollection, maxLen) : null, list != null ? toString(list, maxLen) : null, object, stringArray, wildCollection != null ? toString(wildCollection, maxLen) : null, charArrayMethod(), floatArrayMethod()});\r\n" @@ -3418,6 +3426,7 @@ public void builderArrayLimit1_4Prefixes() throws Exception { + " HashMap hashMap;\r\n" + " Collection wildCollection;\r\n" + " Collection integerCollection;\r\n" + + " @Override\r\n" + " public String toString() {\r\n" + " final int l_maxLen_l = 10;\r\n" + " StringBuffer l_buffer_l = new StringBuffer();\r\n" diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java index c2835c2e7e1..45b1e6446fc 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d5.java @@ -93,7 +93,7 @@ public interface MyMap { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(MY_MAP_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -173,7 +173,7 @@ public interface MyMap { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(MY_MAP_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -239,7 +239,7 @@ public interface MyMap { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(MY_MAP_PATH.replace('/', '.')); IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(MY_MAP_PATH + ".eea")); String initialContent= @@ -395,7 +395,7 @@ public interface X { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH + ".eea")); String initialContent= @@ -472,7 +472,7 @@ public X(String p) {} } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IFile annotationFile= fJProject1.getProject().getFile(new Path(ANNOTATION_PATH).append(X_PATH + ".eea")); String initialContent= @@ -548,7 +548,7 @@ public class Node { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(NODE_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -613,7 +613,7 @@ public class Node { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(NODE_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); @@ -682,7 +682,7 @@ public class Missing { "}\n" }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, unitResult -> !new Path(MISSINGPATH + ".java").equals(new Path(String.valueOf(unitResult.getFileName())))); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, unitResult -> !new Path(MISSINGPATH + ".java").equals(new Path(String.valueOf(unitResult.getFileName())))); IType type= fJProject1.findType(CLASS2_PATH.replace('/', '.')); JavaEditor javaEditor= (JavaEditor) JavaUI.openInEditor(type); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java index 47064dc25b1..d1fbf9f88df 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AnnotateAssistTest1d8.java @@ -1303,7 +1303,7 @@ public class Node { } """ }; - addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_5, null); + addLibrary(fJProject1, "lib.jar", "lib.zip", pathAndContents, ANNOTATION_PATH, JavaCore.VERSION_1_8, null); IType type= fJProject1.findType(NODE_PATH.replace('/', '.')); JavaEditor javaEditor= openInClassfileEditor(type, true, true); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java index e64cc023aa8..22dee729a2a 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest.java @@ -2990,7 +2990,7 @@ public void run() {\s AssistContext context= getCorrectionContext(cu, str1.indexOf(str), 0); List proposals= collectAssists(context, false); - assertNumberOfProposals(proposals, 1); + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); @@ -7374,7 +7374,7 @@ public void run() { AssistContext context= getCorrectionContext(cu, offset, 1); List proposals= collectAssists(context, false); - assertNumberOfProposals(proposals, 1); + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); String str1= """ @@ -7789,48 +7789,6 @@ public void foo() { assertProposalPreviewEquals(str1, NLS.bind(CorrectionMessages.QuickAssistProcessor_convert_to_string_buffer_description, "StringBuilder"), proposals); } - @Test - public void testConvertToStringBufferJava14() throws Exception { - - Map oldOptions= fJProject1.getOptions(false); - Map newOptions= new HashMap<>(oldOptions); - JavaCore.setComplianceOptions(JavaCore.VERSION_1_4, newOptions); - fJProject1.setOptions(newOptions); - - try { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - public class A { - public void foo() { - System.out.println("foo"+"bar"); - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("A.java", str, false, null); - - AssistContext context= getCorrectionContext(cu, str.indexOf("\"+\""), 0); - List proposals= collectAssists(context, false); - - assertCorrectLabels(proposals); - - String str1= """ - package test1; - public class A { - public void foo() { - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("foo"); - stringBuffer.append("bar"); - System.out.println(stringBuffer.toString()); - } - } - """; - assertProposalPreviewEquals(str1, NLS.bind(CorrectionMessages.QuickAssistProcessor_convert_to_string_buffer_description, "StringBuffer"), proposals); - } finally { - fJProject1.setOptions(oldOptions); - } - } - @Test public void testConvertToStringBufferExisting1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -7928,7 +7886,7 @@ public void foo(Object o1, Object o2) { public class A { public void foo(Object o1, Object o2) { - System.out.println(MessageFormat.format("foo{0} \\"bar\\" {1}", new Object[]{o1, o2})); + System.out.println(MessageFormat.format("foo{0} \\"bar\\" {1}", o1, o2)); } } """; @@ -7991,7 +7949,7 @@ public void foo(Object o1, Object o2) { public class A { public void foo(Object o1, Object o2) { - System.out.println(MessageFormat.format("foo{0} \\"bar\\" ", new Object[]{new Integer(1)})); + System.out.println(MessageFormat.format("foo{0} \\"bar\\" ", 1)); } } """; @@ -9435,7 +9393,7 @@ & Comparable> Iterable getIterabl import java.util.List; public class E { void foo() { - for (Iterable iterable : getIterable()) { + for (Comparable comparable : getIterable()) { \s } } @@ -9451,9 +9409,9 @@ & Comparable> Iterable getIterabl import java.util.List; public class E { void foo() { - for (Iterator> iterator = getIterable() - .iterator(); iterator.hasNext();) { - Iterable iterable = iterator.next(); + for (Iterator iterator = getIterable().iterator(); iterator + .hasNext();) { + Comparable comparable = iterator.next(); \s } } @@ -9754,59 +9712,6 @@ void foo(Collection collection) { } } - @Test - public void testGenerateForLowVersion() throws Exception { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - import java.util.Collection; - public class E { - void foo(Collection collection) { - collection - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - Map saveOptions= fJProject1.getOptions(false); - Map newOptions= new HashMap<>(); - JavaCore.setComplianceOptions(JavaCore.VERSION_1_4, newOptions); - newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); - try { - fJProject1.setOptions(newOptions); - - String selection= "collection"; - AssistContext context= getCorrectionContext(cu, str.lastIndexOf(selection) + selection.length(), 0); - List proposals= collectAssists(context, false); - - assertNumberOfProposals(proposals, 5); - assertProposalDoesNotExist(proposals, CorrectionMessages.QuickAssistProcessor_generate_enhanced_for_loop); - assertCorrectLabels(proposals); - - String[] expected= new String[1]; - - // no generics should be added to iterator since the version is too low - String str1= """ - package test1; - import java.util.Collection; - import java.util.Iterator; - public class E { - void foo(Collection collection) { - for (Iterator iterator = collection.iterator(); iterator.hasNext();) { - Object object = iterator.next(); - \s - } - } - } - """; - expected[0]= str1; - - assertExpectedExistInProposals(proposals, expected); - } finally { - fJProject1.setOptions(saveOptions); - } - } - @Test public void testGenerateForArray() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -10005,7 +9910,7 @@ static Set raw(int i) { Map saveOptions= fJProject1.getOptions(false); Map newOptions= new HashMap<>(); - JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, newOptions); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, newOptions); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); @@ -10103,7 +10008,7 @@ static Set raw(int i) { Map saveOptions= fJProject1.getOptions(false); Map newOptions= new HashMap<>(); - JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, newOptions); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, newOptions); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); @@ -10175,7 +10080,7 @@ static Date[] get() { Map saveOptions= fJProject1.getOptions(false); Map newOptions= new HashMap<>(); - JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, newOptions); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, newOptions); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_PUT_EMPTY_STATEMENT_ON_NEW_LINE, "true"); try { fJProject1.setOptions(newOptions); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest1d7.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest1d7.java index 3627d609075..6dbad9d3a93 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest1d7.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/AssistQuickFixTest1d7.java @@ -277,39 +277,6 @@ void foo() { assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); } - @Test - public void testConvertToMultiCatch6() throws Exception { - //Quick assist should not be offered in 1.5 mode - JavaProjectHelper.set15CompilerOptions(fJProject1); - try { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - public class E { - void foo() { - try { - System.out.println("foo"); - } catch (IllegalArgumentException e) { - e.printStackTrace(); - } catch (NullPointerException e) { - e.printStackTrace(); - } - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - int offset= str.indexOf("catch"); - AssistContext context= getCorrectionContext(cu, offset, 0); - assertNoErrors(context); - List proposals= collectAssists(context, false); - - assertProposalDoesNotExist(proposals, CONVERT_TO_A_SINGLE_MULTI_CATCH_BLOCK); - } finally { - JavaProjectHelper.set17CompilerOptions(fJProject1); - } - } - @Test public void testUnrollMultiCatch1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); From 22e6bef23e4bff0dfdf110ad68492af1b79b404f Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 25 Jul 2024 16:12:05 -0400 Subject: [PATCH 4/7] Fix local var cleanup to avoid method references (#1541) - fix VarCleanUpCore visitor maybeUserVar() method to return false for a method reference initializer - add new test to CleanUpTest11 - fixes #1524 --- .../jdt/internal/ui/fix/VarCleanUpCore.java | 6 +- .../jdt/ui/tests/quickfix/CleanUpTest11.java | 140 +++++++++++------- 2 files changed, 89 insertions(+), 57 deletions(-) diff --git a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VarCleanUpCore.java b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VarCleanUpCore.java index 2acfe405b1c..6a678edf81c 100644 --- a/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VarCleanUpCore.java +++ b/org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/internal/ui/fix/VarCleanUpCore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2023 Fabrice TIERCELIN and others. + * Copyright (c) 2020, 2024 Fabrice TIERCELIN and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -34,6 +34,7 @@ import org.eclipse.jdt.core.dom.ClassInstanceCreation; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionMethodReference; import org.eclipse.jdt.core.dom.FieldDeclaration; import org.eclipse.jdt.core.dom.IMethodBinding; import org.eclipse.jdt.core.dom.ITypeBinding; @@ -148,6 +149,9 @@ public boolean visit(final SingleVariableDeclaration node) { } private boolean maybeUseVar(final Type type, final Expression initializer, final int extraDimensions) { + if (initializer instanceof ExpressionMethodReference) { + return false; + } if (type.isVar() || initializer == null || initializer.resolveTypeBinding() == null diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest11.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest11.java index aaa3bc27fd5..3c2d848a631 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest11.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/CleanUpTest11.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2021 Red Hat Inc. and others. + * Copyright (c) 2020, 2024 Red Hat Inc. and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -56,9 +56,9 @@ public void testUseLocalVariableTypeInferenceInLambda1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Predicate - + public class E { public void foo() { Predicate cc = (String s) -> { return s.length() > 0; }; @@ -71,9 +71,9 @@ public void foo() { String expected= """ package test1; - + import java.util.function.Predicate - + public class E { public void foo() { Predicate cc = (var s) -> { return s.length() > 0; }; @@ -89,7 +89,7 @@ public void testUseLocalVariableTypeInferenceInLambda2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + public class E1 { private interface I1 { public void run(String s, int i, Boolean b); @@ -105,7 +105,7 @@ public void foo(int doNotRefactorParameter) { String expected= """ package test1; - + public class E1 { private interface I1 { public void run(String s, int i, Boolean b); @@ -125,14 +125,14 @@ public void testUseLocalVariableTypeInferenceInParamCallWithLambda() throws Exce IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Function; - + public class E1 { public void foo() { debug((String a) -> a.length()); } - + private void debug(Function function) { System.out.println(function); } @@ -144,14 +144,14 @@ private void debug(Function function) { String expected= """ package test1; - + import java.util.function.Function; - + public class E1 { public void foo() { debug((var a) -> a.length()); } - + private void debug(Function function) { System.out.println(function); } @@ -167,14 +167,14 @@ public void testDoNotUseLocalVariableTypeInferenceInWildCardParamCallWithLambda( IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Function; - + public class E1 { public void foo() { debug((String a) -> a.length()); } - + private void debug(Function function) { System.out.println(function); } @@ -193,14 +193,14 @@ public void testDoNotUseLocalVariableTypeInferenceInWildCardConstructorWithLambd IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Function; - + public class E1 { public static void main(String[] args) { new E1((String a) -> a.length()); } - + public E1(Function function) { System.out.println(function); } @@ -219,36 +219,36 @@ public void testDoNotUseLocalVariableTypeInferenceInWildCardSuperCallsWithLambda IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Function; - + public class E1 { public E1(Function function) { System.out.println(function); } - + public void method(Function function) { System.out.println(function); } - + } """; ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", sample, false, null); String sample2= """ package test1; - + import java.util.function.Function; - + public class E2 extends E1 { public E2(Function function) { super((String a) -> a.length()); } - + public void method(Function function) { super.method((String a) -> a.length()); } - + } """; ICompilationUnit cu2= pack1.createCompilationUnit("E2.java", sample2, false, null); @@ -264,9 +264,9 @@ public void testUseLocalVariableTypeInferenceInParamTypeDeclarationWithLambda() IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public void foo() { Predicate cc = (String s) -> (s.length() > 0); @@ -279,9 +279,9 @@ public void foo() { String expected= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public void foo() { Predicate cc = (var s) -> (s.length() > 0); @@ -298,9 +298,9 @@ public void testDoNotUseLocalVariableTypeInferenceInWildCardParamDeclarationWith IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public void foo() { Predicate cc = (String s) -> (s.length() > 0); @@ -320,9 +320,9 @@ public void testUseLocalVariableTypeInferenceInParamFieldDeclarationWithLambda() IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public Predicate cc = (String s) -> (s.length() > 0); } @@ -333,9 +333,9 @@ public class E1 { String expected= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public Predicate cc = (var s) -> (s.length() > 0); } @@ -350,9 +350,9 @@ public void testDoNotUseLocalVariableTypeInferenceInWildCardParamFieldDeclaratio IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + import java.util.function.Predicate; - + public class E1 { public Predicate cc = (String s) -> (s.length() > 0); } @@ -364,6 +364,34 @@ public class E1 { assertRefactoringHasNoChange(new ICompilationUnit[] { cu1 }); } + @Test + public void testDoNotUseLocalVariableTypeInferenceWithMethodRef() throws Exception { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=570058 + IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); + String sample= """ + package test1; + + interface MyIntf { + void bla(Object... o); + } + + public class E1 { + + private void bla(Object... o) { + } + + private void foo() { + MyIntf myin = this::bla; + } + + } + """; + ICompilationUnit cu1= pack1.createCompilationUnit("E1.java", sample, false, null); + + enable(CleanUpConstants.USE_VAR); + + assertRefactoringHasNoChange(new ICompilationUnit[] { cu1 }); + } @Test public void testUseStringIsBlank() throws Exception { @@ -371,14 +399,14 @@ public void testUseStringIsBlank() throws Exception { IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null); String given= """ package test1; - + import java.util.List; - + public class E { private static final int ZERO = 0; private static final int THREE = 3; private static final String EMPTY_STRING = ""; - + void isBlank(String text) { if (text.strip().isEmpty()) { System.err.println("Text must not be blank"); @@ -418,7 +446,7 @@ void isBlank(String text) { System.err.println("Text must not be blank"); } } - + void isNotBlank(String text, StringBuilder builder) { if (!text.strip().isEmpty()) { System.out.println(text) @@ -443,7 +471,7 @@ void isNotBlank(String text, StringBuilder builder) { System.out.println(text) } } - + void printList(List list) { list.stream().filter(s -> !s.strip().isEmpty()).map(String::strip); list.stream().filter(s -> s.strip().length() != 0).map(String::strip); @@ -453,14 +481,14 @@ void printList(List list) { String expected= """ package test1; - + import java.util.List; - + public class E { private static final int ZERO = 0; private static final int THREE = 3; private static final String EMPTY_STRING = ""; - + void isBlank(String text) { if (text.isBlank()) { System.err.println("Text must not be blank"); @@ -500,7 +528,7 @@ void isBlank(String text) { System.err.println("Text must not be blank"); } } - + void isNotBlank(String text, StringBuilder builder) { if (!text.isBlank()) { System.out.println(text) @@ -525,7 +553,7 @@ void isNotBlank(String text, StringBuilder builder) { System.out.println(text) } } - + void printList(List list) { list.stream().filter(s -> !s.isBlank()).map(String::strip); list.stream().filter(s -> !s.isBlank()).map(String::strip); @@ -547,37 +575,37 @@ public void testDoNotUseStringIsBlank() throws Exception { IPackageFragment pack= fSourceFolder.createPackageFragment("test1", false, null); String sample= """ package test1; - + public class NotAString { int mostlyZero= 0; private static int NON_FINAL_ZERO = 0; - + public String strip() { return ""; } - + void doNotUseStringIsBlank(NotAString noString, String text) { if (noString.strip().length() == 0) { System.err.println("Text must not be blank"); } - + if (text.strip().length() == mostlyZero) { System.err.println("Text must not be blank"); } else if (text.strip().length() <= NON_FINAL_ZERO) { System.err.println("Text must not be blank"); } } - + void doNotUseStringIsBlankWithUnknownString(String text, String emptyString) { if (text.strip().equals(emptyString)) { System.err.println("Text must not be blank"); } - + if (emptyString.equals(text.strip())) { System.err.println("Text must not be blank"); } } - + void bug_573831(String text) { if (equals(text.strip())) { System.err.println("Applying the cleanup should not cause NPE"); From b9befead9da37e4a901a9a35ddb92902ed4abd68 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 25 Jul 2024 22:43:12 +0200 Subject: [PATCH 5/7] Fixed tests failing after requiring minimal 1.8 compliance, part 4 - PullUpTests - InlineTempTests (all except test31()) - InlineConstantTests1d7 - ExtractMethodTests - ExtractInterfaceTests See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../resources/ExtractInterface/test108/out/A.java | 1 + .../ExtractMethodTests/destination_out/A_test1059.java | 8 ++++---- .../ExtractMethodTests/destination_out/A_test1060.java | 6 +++--- .../resources/InlineConstant/canInline17/test0/out/C.java | 2 +- .../resources/InlineTemp/canInline/A_test37_out.java | 2 +- .../resources/InlineTemp/canInline/A_test38_out.java | 2 +- .../resources/InlineTemp/canInline/A_test39_out.java | 2 +- .../resources/PullUp/test46/out/A.java | 1 + .../resources/PullUp/test47/out/A.java | 1 + .../resources/PullUp/test51/out/A.java | 1 + .../resources/PullUp/test52/out/A.java | 4 ++++ .../resources/PullUp/test53/out/A.java | 1 + 12 files changed, 20 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractInterface/test108/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractInterface/test108/out/A.java index 5aa6edc9044..80436890925 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractInterface/test108/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractInterface/test108/out/A.java @@ -1,6 +1,7 @@ package p; public class A implements I { + @Override public void m() { for (A a : getCollection()) { a.abc(); diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1059.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1059.java index 29504e965d4..9ac7126f5b3 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1059.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1059.java @@ -4,10 +4,10 @@ public class A_test1059 { interface B { @interface C { int i= /*[*/extracted();/*]*/ - } - } + } - protected static int extracted() { - return 0; + static int extracted() { + return 0; + } } } \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1060.java b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1060.java index dee74a668f7..a5117650dc9 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1060.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/destination_out/A_test1060.java @@ -7,9 +7,9 @@ int foo() { return extracted(); } } - } - protected static int extracted() { - /*[*/return 0;/*]*/ + static int extracted() { + /*[*/return 0;/*]*/ + } } } \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline17/test0/out/C.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline17/test0/out/C.java index 2217fe85083..914c09918bd 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline17/test0/out/C.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineConstant/canInline17/test0/out/C.java @@ -9,7 +9,7 @@ public C(T param){ field1 = param; } public static void main(String[] args) { - C.testFunction(new C(null).getField()); + C.testFunction(new C<>(null).getField()); } public static void testFunction(String param){ System.out.println("S " + param); diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test37_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test37_out.java index 6e7401ad50e..e7bb98b66e7 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test37_out.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test37_out.java @@ -2,7 +2,7 @@ class A { String x() { - return A.bar(); + return bar(); } static T bar() { diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test38_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test38_out.java index d603f015e92..1988751a75a 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test38_out.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test38_out.java @@ -2,7 +2,7 @@ class A { String x() { - return this.bar(); + return bar(); } T bar() { diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test39_out.java b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test39_out.java index 6ae975fda21..4fb99c96239 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test39_out.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/InlineTemp/canInline/A_test39_out.java @@ -2,7 +2,7 @@ class A extends Super { String x() { - return super.bar(); + return super.bar(); } T bar() { diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test46/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test46/out/A.java index e418cf58b75..83492bc7ade 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test46/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test46/out/A.java @@ -7,6 +7,7 @@ interface A{ } class B implements A { + @Override public int getConst() { return CONST; } diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test47/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test47/out/A.java index e2c42ed8696..6bc1cba7625 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test47/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test47/out/A.java @@ -4,6 +4,7 @@ public interface A { void method(); } class B implements A { + @Override public final void method() { } diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test51/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test51/out/A.java index 8802828dc72..3f338bf6d2a 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test51/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test51/out/A.java @@ -4,6 +4,7 @@ public class A implements B.Foo { + @Override public void b() { List l = null; } diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test52/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test52/out/A.java index eb7c39a5e92..7cdb1bb86b3 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test52/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test52/out/A.java @@ -43,12 +43,16 @@ interface Foo { } static class B implements Foo { + @Override public void baz1() { } + @Override public void baz2() { } + @Override public void baz3() { } + @Override public void baz4() { } } diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test53/out/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test53/out/A.java index 61d4ac49352..3b2447a0382 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test53/out/A.java +++ b/org.eclipse.jdt.ui.tests.refactoring/resources/PullUp/test53/out/A.java @@ -4,6 +4,7 @@ interface A{ int[] m()[]; } class B implements A{ + @Override public int[] m()[] { return null; } From 5b5d424b3cfd6e7db8aeb6f202346f18b3fac5f2 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Thu, 25 Jul 2024 17:06:31 -0400 Subject: [PATCH 6/7] Fix MoveMembersTest failures due to moving to Java 1.8 as min version - remove testFail19() and testFail21() tests which assume static methods in interfaces are forbidden which they are not in 1.8 --- .../resources/MoveMembers/testFail19/in/A.java | 4 ---- .../resources/MoveMembers/testFail19/in/B.java | 3 --- .../resources/MoveMembers/testFail21/in/A.java | 4 ---- .../resources/MoveMembers/testFail21/in/B.java | 3 --- .../jdt/ui/tests/refactoring/MoveMembersTests.java | 8 ++------ 5 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/A.java delete mode 100644 org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/B.java delete mode 100644 org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/A.java delete mode 100644 org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/B.java diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/A.java deleted file mode 100644 index 289da818c9f..00000000000 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/A.java +++ /dev/null @@ -1,4 +0,0 @@ -package p; -public class A{ - public static void m(){} -} \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/B.java b/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/B.java deleted file mode 100644 index 93910c8f267..00000000000 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail19/in/B.java +++ /dev/null @@ -1,3 +0,0 @@ -package p; -interface B{ -} \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/A.java b/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/A.java deleted file mode 100644 index 1df588d1ab1..00000000000 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/A.java +++ /dev/null @@ -1,4 +0,0 @@ -package p; -public interface A{ - static void m(); -} \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/B.java b/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/B.java deleted file mode 100644 index d110d65e7a0..00000000000 --- a/org.eclipse.jdt.ui.tests.refactoring/resources/MoveMembers/testFail21/in/B.java +++ /dev/null @@ -1,3 +0,0 @@ -package p; -class B{ -} \ No newline at end of file diff --git a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveMembersTests.java b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveMembersTests.java index c71d354dc81..027a13a5d03 100644 --- a/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveMembersTests.java +++ b/org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/MoveMembersTests.java @@ -674,9 +674,7 @@ public void testFail18() throws Exception{ @Test public void testFail19() throws Exception{ - fieldMethodTypeHelper_failing(new String[0], - new String[]{"m"}, new String[][]{new String[0]}, new String[0], - RefactoringStatus.ERROR, "p.B"); + // no longer failure due to min JDK 1.8...move static to interface tested in MoveMemberTest1d8 } @Test @@ -686,9 +684,7 @@ public void testFail20() throws Exception{ @Test public void testFail21() throws Exception{ - fieldMethodTypeHelper_failing(new String[0], - new String[]{"m"}, new String[][]{new String[0]}, new String[0], - RefactoringStatus.FATAL, "p.B"); + // no longer failure due to min JDK 1.8...move static to interface tested in MoveMemberTest1d8 } // Issue 1299 From 3d32db85395701cf0d955d5fac56eb66b383cdd8 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Thu, 25 Jul 2024 23:28:16 +0200 Subject: [PATCH 7/7] Fixed tests failing after requiring minimal 1.8 compliance, part 5 - UnresolvedMethodsQuickFixTest - TypeMismatchQuickFixTests - ReturnTypeQuickFixTest - ModifierCorrectionsQuickFixTest See https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2536 --- .../ModifierCorrectionsQuickFixTest.java | 462 +++++------------- .../quickfix/ReturnTypeQuickFixTest.java | 32 +- .../quickfix/TypeMismatchQuickFixTests.java | 143 +++--- .../UnresolvedMethodsQuickFixTest.java | 306 ++++++------ 4 files changed, 353 insertions(+), 590 deletions(-) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java index ea846852765..4d21daf477a 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ModifierCorrectionsQuickFixTest.java @@ -502,7 +502,7 @@ public class E extends test1.C { package test1; public class C { protected class Inner{ - + public Inner() { } } @@ -633,7 +633,7 @@ public class C { package test1; public class E extends C { private int fXoo; - + public void foo() { fXoo= 1; } @@ -996,7 +996,7 @@ public void testAbstractMethodWithBody3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String str= """ package test1; - + enum E { A { public void foo() {} @@ -1015,7 +1015,7 @@ public abstract void foo() {} String[] expected= new String[1]; expected[0]= """ package test1; - + enum E { A { public void foo() {} @@ -1124,181 +1124,6 @@ public class E { assertEqualStringsIgnoreOrder(new String[] { preview1, preview2 }, new String[] { expected1, expected2 }); } - @Test - public void testOuterLocalMustBeFinal() throws Exception { - - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - public class E { - public void foo() { - int i= 9; - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - public class E { - public void foo() { - final int i= 9; - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - """; - assertEqualString(preview, str1); - } - - @Test - public void testOuterLocalMustBeFinal2() throws Exception { - - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - import java.util.List; - public class E { - public void foo() { - List i= null, j= null; - Runnable run= new Runnable() { - public void run() { - Object x= i; - } - }; - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - import java.util.List; - public class E { - public void foo() { - final List i= null; - List j= null; - Runnable run= new Runnable() { - public void run() { - Object x= i; - } - }; - } - } - """; - assertEqualString(preview, str1); - } - - - @Test - public void testOuterParameterMustBeFinal() throws Exception { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - public class E { - public void foo(int i) { - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - public class E { - public void foo(final int i) { - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - """; - assertEqualString(preview, str1); - } - - @Test - public void testOuterForParamMustBeFinal() throws Exception { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - public class E { - public void foo() { - for (int i= 1; true;) { - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - } - """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - public class E { - public void foo() { - for (final int i= 1; true;) { - Runnable run= new Runnable() { - public void run() { - int x= i; - } - }; - } - } - } - """; - assertEqualString(preview, str1); - } - - @Test public void testMethodRequiresBody() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); @@ -2235,20 +2060,8 @@ public interface E { ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - public interface E { - void foo(); - } - """; - assertEqualString(preview, str1); + ArrayList proposals= collectCorrections(cu, astRoot, 2); + assertNumberOfProposals(proposals, 0); } @Test @@ -2412,7 +2225,7 @@ public void testInvalidConstructorModifiers() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class Bug { public static Bug() { } @@ -2429,7 +2242,7 @@ public static Bug() { String[] expected= new String[1]; expected[0]= """ package pack; - + public class Bug { public Bug() { } @@ -3034,7 +2847,7 @@ public void testSuppressNLSWarningAnnotation5() throws Exception { String str= """ package test1;\s import java.util.ArrayList; - + public class A { public void foo(ArrayList c) { new ArrayList(c); @@ -3053,7 +2866,7 @@ public void foo(ArrayList c) { expected[0]= """ package test1;\s import java.util.ArrayList; - + public class A { @SuppressWarnings("unchecked") public void foo(ArrayList c) { @@ -3076,7 +2889,7 @@ public void testSuppressWarningsForLocalVariables() throws Exception { String str= """ package test1;\s import java.util.ArrayList; - + public class A { public void foo() { @SuppressWarnings("unused") @@ -3095,7 +2908,7 @@ public void foo() { expected[0]= """ package test1;\s import java.util.ArrayList; - + public class A { public void foo() { @SuppressWarnings({"unused", "rawtypes"}) @@ -3107,7 +2920,7 @@ public void foo() { expected[1]= """ package test1;\s import java.util.ArrayList; - + public class A { @SuppressWarnings("rawtypes") public void foo() { @@ -3130,7 +2943,7 @@ public void testSuppressWarningsForFieldVariables() throws Exception { String str= """ package test1;\s import java.util.*; - + public class A { List myList = new ArrayList(); } @@ -3147,7 +2960,7 @@ public class A { expected[0]= """ package test1;\s import java.util.*; - + public class A { @SuppressWarnings("unchecked") List myList = new ArrayList(); @@ -3168,7 +2981,7 @@ public void testSuppressWarningsForFieldVariables2() throws Exception { String str= """ package test1;\s import java.util.ArrayList; - + class A { @SuppressWarnings("rawtypes") ArrayList array; @@ -3187,7 +3000,7 @@ class A { expected[0]= """ package test1;\s import java.util.ArrayList; - + class A { @SuppressWarnings("rawtypes") ArrayList array; @@ -3210,7 +3023,7 @@ public void testSuppressWarningsForMethodParameters() throws Exception { String str= """ package test1;\s import java.util.*; - + public class A { public int foo(int param1, List param2) { return param1; @@ -3228,7 +3041,7 @@ public int foo(int param1, List param2) { expected[0]= """ package test1;\s import java.util.*; - + public class A { public int foo(int param1, @SuppressWarnings("rawtypes") List param2) { return param1; @@ -3239,7 +3052,7 @@ public int foo(int param1, @SuppressWarnings("rawtypes") List param2) { expected[1]= """ package test1;\s import java.util.*; - + public class A { @SuppressWarnings("rawtypes") public int foo(int param1, List param2) { @@ -3263,7 +3076,7 @@ public void testSuppressWarningsAnonymousClass1() throws Exception { String str= """ package test1;\s import java.util.*; - + public class A { public void foo() { @SuppressWarnings("unused") @@ -3290,7 +3103,7 @@ public void foo() { expected[0]= """ package test1;\s import java.util.*; - + public class A { public void foo() { @SuppressWarnings("unused") @@ -3310,7 +3123,7 @@ public void foo() { expected[1]= """ package test1;\s import java.util.*; - + public class A { public void foo() { @SuppressWarnings({"unused", "rawtypes"}) @@ -3329,7 +3142,7 @@ public void foo() { expected[1]= """ package test1;\s import java.util.*; - + public class A { @SuppressWarnings("rawtypes") public void foo() { @@ -3359,7 +3172,7 @@ public void testSuppressWarningsAnonymousClass2() throws Exception { String str= """ package test1;\s import java.util.*; - + public class A { final Runnable r= new Runnable() { public void run() { @@ -3384,7 +3197,7 @@ public void run() { expected[0]= """ package test1;\s import java.util.*; - + public class A { final Runnable r= new Runnable() { @SuppressWarnings("unchecked") @@ -3407,7 +3220,7 @@ public void testMisspelledSuppressToken() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("a", false, null); String str= """ package a; - + public class A { @SuppressWarnings("unusd") public static void main(String[] args) { @@ -3425,7 +3238,7 @@ public static void main(String[] args) { String[] expected= new String[2]; expected[0]= """ package a; - + public class A { @SuppressWarnings("unused") public static void main(String[] args) { @@ -3435,7 +3248,7 @@ public static void main(String[] args) { expected[1]= """ package a; - + public class A { public static void main(String[] args) { } @@ -3451,7 +3264,7 @@ public void testSuppressBug169446() throws Exception { IPackageFragment other= fSourceFolder.createPackageFragment("other", false, null); String str= """ package other;\s - + public @interface SuppressWarnings { String value(); } @@ -3462,7 +3275,7 @@ public void testSuppressBug169446() throws Exception { String str1= """ package a.b; - + public class E { @Deprecated() public void foo() { @@ -3473,9 +3286,9 @@ public void foo() { String str2= """ package a.b; - + import other.SuppressWarnings; - + public class Test { @SuppressWarnings("BC") public void foo() { @@ -3494,9 +3307,9 @@ public void foo() { String[] expected= new String[1]; expected[0]= """ package a.b; - + import other.SuppressWarnings; - + public class Test { @java.lang.SuppressWarnings("deprecation") @SuppressWarnings("BC") @@ -3514,9 +3327,9 @@ public void testSuppressWarningInImports() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); String str= """ package p; - + import java.util.Vector; - + public class A { } """; @@ -3531,9 +3344,9 @@ public class A { expected[0]= """ package p; - + import java.util.Vector; - + @SuppressWarnings("unused") public class A { } @@ -3552,10 +3365,10 @@ public void testUnusedSuppressWarnings1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); String str= """ package p; - + @SuppressWarnings(value="unused") public class E { - + } """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -3569,9 +3382,9 @@ public class E { String[] expected= new String[1]; expected[0]= """ package p; - + public class E { - + } """; @@ -3587,10 +3400,10 @@ public void testUnusedSuppressWarnings2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); String str= """ package p; - + @SuppressWarnings("unused") public class E { - + } """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -3604,9 +3417,9 @@ public class E { String[] expected= new String[1]; expected[0]= """ package p; - + public class E { - + } """; @@ -3622,10 +3435,10 @@ public void testUnusedSuppressWarnings3() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); String str= """ package p; - + @SuppressWarnings({ "unused", "X" }) public class E { - + } """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -3639,63 +3452,14 @@ public class E { String[] expected= new String[1]; expected[0]= """ package p; - + @SuppressWarnings({ "X" }) public class E { - - } - """; - - assertExpectedExistInProposals(proposals, expected); - } - - @Test - public void testMakeFinalBug129165() throws Exception { - IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); - String str= """ - package test1; - import java.io.Serializable; - public class E { - @SuppressWarnings("serial") - public void foo() { - int i= 1, j= i + 1, h= j + 1; - Serializable ser= new Serializable() { - public void bar() { - System.out.println(j); - } - }; - } } """; - ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); - CompilationUnit astRoot= getASTRoot(cu); - ArrayList proposals= collectCorrections(cu, astRoot); - assertNumberOfProposals(proposals, 1); - assertCorrectLabels(proposals); - - CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); - String preview= getPreviewContent(proposal); - - String str1= """ - package test1; - import java.io.Serializable; - public class E { - @SuppressWarnings("serial") - public void foo() { - int i= 1; - final int j= i + 1; - int h= j + 1; - Serializable ser= new Serializable() { - public void bar() { - System.out.println(j); - } - }; - } - } - """; - assertEqualString(preview, str1); + assertExpectedExistInProposals(proposals, expected); } @Test @@ -3703,7 +3467,7 @@ public void testStaticFieldInInnerClass() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { class F { static int x; @@ -3721,7 +3485,7 @@ class F { String[] expected= new String[2]; expected[0]= """ package pack; - + public class E { class F { int x; @@ -3731,7 +3495,7 @@ class F { expected[1]= """ package pack; - + public class E { static class F { static int x; @@ -3747,7 +3511,7 @@ public void testStaticMethodInInnerClass() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { class F { static int foo() { @@ -3766,7 +3530,7 @@ static int foo() { String[] expected= new String[2]; expected[0]= """ package pack; - + public class E { class F { int foo() { @@ -3777,7 +3541,7 @@ int foo() { expected[1]= """ package pack; - + public class E { static class F { static int foo() { @@ -3794,7 +3558,7 @@ public void testFinalVolatileField() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { class F { volatile final int x; @@ -3812,7 +3576,7 @@ class F { String[] expected= new String[2]; expected[0]= """ package pack; - + public class E { class F { final int x; @@ -3822,7 +3586,7 @@ class F { expected[1]= """ package pack; - + public class E { class F { volatile int x; @@ -3840,7 +3604,7 @@ public void testOverrideAnnotationButNotOverriding() throws Exception { String str= """ package pack; - + public class OtherMachine { } """; @@ -3848,9 +3612,9 @@ public class OtherMachine { String str1= """ package pack; - + import java.io.IOException; - + public class Machine extends OtherMachine { @Override public boolean isAlive(OtherMachine m) throws IOException { @@ -3869,9 +3633,9 @@ public boolean isAlive(OtherMachine m) throws IOException { String[] expected= new String[2]; expected[0]= """ package pack; - + import java.io.IOException; - + public class Machine extends OtherMachine { public boolean isAlive(OtherMachine m) throws IOException { return true; @@ -3881,11 +3645,11 @@ public boolean isAlive(OtherMachine m) throws IOException { expected[1]= """ package pack; - + import java.io.IOException; - + public class OtherMachine { - + public boolean isAlive(OtherMachine m) throws IOException { return false; } @@ -3901,7 +3665,7 @@ public void testCreateMethodWhenOverrideAnnotation() throws Exception { String str= """ package pack; - + public abstract class OtherMachine { } """; @@ -3909,7 +3673,7 @@ public abstract class OtherMachine { String str1= """ package pack; - + public abstract class Machine extends OtherMachine { @Override public abstract void m1(); @@ -3926,16 +3690,16 @@ public abstract class Machine extends OtherMachine { String[] expected= new String[2]; expected[0]= """ package pack; - + public abstract class OtherMachine { - + public abstract void m1(); } """; expected[1]= """ package pack; - + public abstract class Machine extends OtherMachine { public abstract void m1(); } @@ -3958,12 +3722,12 @@ public class E { public void foo() { } } \s - + class F extends E { public void foo() { } } - + """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -3981,13 +3745,13 @@ public class E { public void foo() { } } \s - + class F extends E { @Deprecated public void foo() { } } - + """; expected[1]= """ @@ -3997,13 +3761,13 @@ public class E { public void foo() { } } \s - + class F extends E { @SuppressWarnings("deprecation") public void foo() { } } - + """; assertExpectedExistInProposals(proposals, expected); @@ -4023,14 +3787,14 @@ public class E { public void foo() { } } \s - + class F extends E { /** */ public void foo() { } } - + """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -4048,7 +3812,7 @@ public class E { public void foo() { } } \s - + class F extends E { /** * @deprecated @@ -4057,7 +3821,7 @@ class F extends E { public void foo() { } } - + """; expected[1]= """ @@ -4067,7 +3831,7 @@ public class E { public void foo() { } } \s - + class F extends E { /** */ @@ -4075,7 +3839,7 @@ class F extends E { public void foo() { } } - + """; assertExpectedExistInProposals(proposals, expected); @@ -4086,7 +3850,7 @@ public void testAbstractMethodInEnumWithoutEnumConstants() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + enum E { ; public abstract boolean foo(); @@ -4103,7 +3867,7 @@ enum E { String[] expected= new String[1]; expected[0]= """ package r; - + enum E { ; public boolean foo() { @@ -4120,7 +3884,7 @@ public void testInvalidEnumModifier() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + private final strictfp enum E { } """; @@ -4135,7 +3899,7 @@ private final strictfp enum E { String[] expected= new String[1]; expected[0]= """ package r; - + strictfp enum E { } """; @@ -4148,7 +3912,7 @@ public void testInvalidEnumModifier2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + public abstract enum E { } """; @@ -4163,7 +3927,7 @@ public abstract enum E { String[] expected= new String[1]; expected[0]= """ package r; - + public enum E { } """; @@ -4176,7 +3940,7 @@ public void testInvalidEnumConstantModifier() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + enum E { private final WHITE; } @@ -4192,7 +3956,7 @@ enum E { String[] expected= new String[1]; expected[0]= """ package r; - + enum E { WHITE; } @@ -4206,10 +3970,10 @@ public void testInvalidEnumConstructorModifier() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + enum E { WHITE(1); - + public final E(int foo) { } } @@ -4225,10 +3989,10 @@ public final E(int foo) { String[] expected= new String[1]; expected[0]= """ package r; - + enum E { WHITE(1); - + E(int foo) { } } @@ -4242,7 +4006,7 @@ public void testInvalidMemberEnumModifier() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + class E { final enum A { } @@ -4259,7 +4023,7 @@ final enum A { String[] expected= new String[1]; expected[0]= """ package r; - + class E { enum A { } @@ -4274,7 +4038,7 @@ public void testMissingSynchronizedOnInheritedMethod() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("r", false, null); String str= """ package r; - + public class A { protected synchronized void foo() { } @@ -4284,7 +4048,7 @@ protected synchronized void foo() { String str1= """ package r; - + class B extends A { protected void foo() { } @@ -4301,7 +4065,7 @@ protected void foo() { String[] expected= new String[1]; expected[0]= """ package r; - + class B extends A { protected synchronized void foo() { } @@ -4498,7 +4262,7 @@ public void testProposesVisibilityFromOneInterfaceMethod() throws Exception { String sample= """ package test1; - + public interface Interface1 { String getName(); } @@ -4507,7 +4271,7 @@ public interface Interface1 { sample= """ package test2; - + public class AbsImpl implements test1.Interface1 { String getName() { return "name"; @@ -4536,7 +4300,7 @@ public void testDoNotProposeVisibilityFromDifferentInterfaceMethods() throws Exc String sample= """ package test; - + public interface Interface1 { String getName(); } @@ -4545,7 +4309,7 @@ public interface Interface1 { sample= """ package test; - + protected interface Interface2 { protected String getName(); } @@ -4554,7 +4318,7 @@ protected interface Interface2 { sample= """ package test; - + public class AbsImpl implements Interface1, Interface2 { String getName() { return "name"; @@ -4585,7 +4349,7 @@ public void testProposeVisibilityFromIdenticalInterfaceMethods() throws Exceptio String sample= """ package test1; - + public interface Interface1 { String getName(); } @@ -4594,7 +4358,7 @@ public interface Interface1 { sample= """ package test2; - + public interface Interface2 { String getName(); } @@ -4603,7 +4367,7 @@ public interface Interface2 { sample= """ package test3; - + public class AbsImpl implements test1.Interface1, test2.Interface2 { String getName() { return "name"; @@ -4634,7 +4398,7 @@ public void testProposeVisibilityFromMotherInterfaceMethods() throws Exception { String sample= """ package test1; - + public interface Interface1 { String getName(); } @@ -4643,7 +4407,7 @@ public interface Interface1 { sample= """ package test2; - + public interface Interface2 extends test1.Interface1 { } """; @@ -4651,7 +4415,7 @@ public interface Interface2 extends test1.Interface1 { sample= """ package test3; - + public class AbsImpl implements test2.Interface2 { String getName() { return "name"; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java index 8d6b5d4bcc6..0484989ac5a 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/ReturnTypeQuickFixTest.java @@ -670,9 +670,9 @@ public E() { String str1= """ package test1; - + import java.util.Properties; - + public class E { public Properties E() { return System.getProperties(); @@ -844,9 +844,9 @@ public void testCorrectReturnStatementInConditional() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String input= """ package test1; - + import java.util.Map; - + public class E { V foo(K1 key1, Map> map) { Map map2 = map.get(key1); @@ -866,13 +866,13 @@ V foo(K1 key1, Map> map) { String expected1= """ package test1; - + import java.util.Map; - + public class E { V foo(K1 key1, Map> map) { Map map2 = map.get(key1); - return (V) (map2 == null ? null : map2.entrySet()); + return map2 == null ? null : (V) map2.entrySet(); } } """; // @@ -882,11 +882,11 @@ V foo(K1 key1, Map> map) { String expected2= """ package test1; - + import java.util.Map; import java.util.Map.Entry; import java.util.Set; - + public class E { Set> foo(K1 key1, Map> map) { Map map2 = map.get(key1); @@ -904,9 +904,9 @@ public void testCorrectReturnStatementInChainedConditional() throws Exception { String input= """ package test1; - + import java.util.Map; - + public class E { V foo(K1 key1, Map> aMap) { Map newMap = aMap.get(key1); @@ -926,13 +926,13 @@ V foo(K1 key1, Map> aMap) { String expected1= """ package test1; - + import java.util.Map; - + public class E { V foo(K1 key1, Map> aMap) { Map newMap = aMap.get(key1); - return (V) (newMap == null ? null : aMap == null ? null : newMap.entrySet()); + return newMap == null ? null : aMap == null ? null : (V) newMap.entrySet(); } } """; // @@ -942,11 +942,11 @@ V foo(K1 key1, Map> aMap) { String expected2= """ package test1; - + import java.util.Map; import java.util.Map.Entry; import java.util.Set; - + public class E { Set> foo(K1 key1, Map> aMap) { Map newMap = aMap.get(key1); diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java index 349b7b4916c..0adde951779 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/TypeMismatchQuickFixTests.java @@ -17,7 +17,7 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.util.ArrayList; import java.util.Arrays; @@ -410,9 +410,9 @@ public void foo() { String expected3= """ package test1; - + import test0.PrimaryContainer; - + public class Container { public static PrimaryContainer getContainer() { return null; @@ -425,9 +425,9 @@ public static PrimaryContainer getContainer() { String expected4= """ package test1; - + import test0.PrimaryContainer; - + public class Container implements PrimaryContainer { public static Container getContainer() { return null; @@ -496,9 +496,9 @@ public void foo(PrimaryContainer primary) { String expected2= """ package test1; - + import test0.PrimaryContainer; - + public class Container { public static PrimaryContainer getContainer() { return null; @@ -511,9 +511,9 @@ public static PrimaryContainer getContainer() { String expected3= """ package test1; - + import test0.PrimaryContainer; - + public class Container implements PrimaryContainer { public static Container getContainer() { return null; @@ -526,9 +526,9 @@ public static Container getContainer() { String expected4= """ package test0; - + import test1.Container; - + public interface PrimaryContainer { PrimaryContainer duplicate(Container container); } @@ -539,12 +539,12 @@ public interface PrimaryContainer { String expected5= """ package test0; - + import test1.Container; - + public interface PrimaryContainer { PrimaryContainer duplicate(PrimaryContainer container); - + void duplicate(Container container); } """; @@ -621,9 +621,9 @@ public void foo(Container c) { String expected3= """ package test1; - + import test0.PrimaryContainer; - + public class Container { public PrimaryContainer getContainer() { return null; @@ -636,9 +636,9 @@ public PrimaryContainer getContainer() { String expected4= """ package test1; - + import test0.PrimaryContainer; - + public class Container implements PrimaryContainer { public Container getContainer() { return null; @@ -722,9 +722,9 @@ public void foo(Container> c) { String expected3= """ package test1; - + import test0.PrimaryContainer; - + public class Container { public PrimaryContainer getContainer() { return null; @@ -1351,9 +1351,9 @@ public String[] getCollection() { String expected1= """ package test1; - + import java.util.List; - + public class E implements IBase { public List getCollection() { return null; @@ -1550,12 +1550,11 @@ public void getAnnotation(Class annotationClass) { String expected1= """ package test1; - import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; public class E { void m() { new AccessibleObject() { - public Annotation getAnnotation(Class annotationClass) { + public T getAnnotation(Class annotationClass) { } }; } @@ -1740,9 +1739,9 @@ public String[] getValues() throws IOException { String expected1= """ package test1; - + import java.io.IOException; - + public interface IBase { String[] getValues() throws IOException; } @@ -1753,7 +1752,7 @@ public interface IBase { String expected2= """ package test1; - + public class E implements IBase { public String[] getValues() { return null; @@ -1946,9 +1945,9 @@ public String[] getValues() throws IOException { String expected1= """ package test1; - + import java.io.IOException; - + public interface IBase { T[] getValues() throws IOException; } @@ -1959,7 +1958,7 @@ public interface IBase { String expected2= """ package test1; - + public class E implements IBase { public String[] getValues() { return null; @@ -2261,9 +2260,9 @@ public void testTypeMismatchInForEachProposalsList() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2283,9 +2282,9 @@ public void foo() { String[] expected= new String[1]; expected[0]= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2303,9 +2302,9 @@ public void testTypeMismatchInForEachProposalsListExtends() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2325,9 +2324,9 @@ public void foo() { String[] expected= new String[1]; expected[0]= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2345,9 +2344,9 @@ public void testTypeMismatchInForEachProposalsListSuper() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2367,9 +2366,9 @@ public void foo() { String[] expected= new String[1]; expected[0]= """ package pack; - + import java.util.List; - + public class E { public void foo() { List l= null; \s @@ -2387,9 +2386,9 @@ public void testTypeMismatchInForEachProposalsArrays() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + import java.util.List; - + public class E { public void foo() { String[] l= null; @@ -2409,9 +2408,9 @@ public void foo() { String[] expected= new String[1]; expected[0]= """ package pack; - + import java.util.List; - + public class E { public void foo() { String[] l= null; @@ -2429,7 +2428,7 @@ public void testTypeMismatchInForEachMissingType() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { public void foo(String[] strings) { for (s: strings) { @@ -2448,7 +2447,7 @@ public void foo(String[] strings) { String[] expected= new String[1]; expected[0]= """ package pack; - + public class E { public void foo(String[] strings) { for (String s: strings) { @@ -2465,14 +2464,14 @@ public void testNullCheck() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { public static void main(String arg) { while (arg) { } } } - + """; ICompilationUnit cu= pack1.createCompilationUnit("E.java", str, false, null); @@ -2485,26 +2484,26 @@ public static void main(String arg) { String[] expected= new String[2]; expected[0]= """ package pack; - + public class E { public static void main(boolean arg) { while (arg) { } } } - + """; expected[1]= """ package pack; - + public class E { public static void main(String arg) { while (arg != null) { } } } - + """; assertExpectedExistInProposals(proposals, expected); @@ -2516,8 +2515,8 @@ public void testTypeMismatchObjectAndPrimitiveType() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - - + + public class E { public void foo() { Object o= new Object(); @@ -2534,25 +2533,25 @@ public void foo() { assertNumberOfProposals(proposals, 3); ICompletionProposal proposal= proposals.get(0); - assertNotEquals(-1, proposal.getDisplayString().indexOf("Integer")); + assertNotEquals(-1, proposal.getDisplayString().indexOf("int")); String[] expected= new String[3]; expected[0]= """ package pack; - - + + public class E { public void foo() { Object o= new Object(); - int i= (Integer) o; + int i= (int) o; } } """; expected[1]= """ package pack; - - + + public class E { public void foo() { int o= new Object(); @@ -2563,8 +2562,8 @@ public void foo() { expected[2]= """ package pack; - - + + public class E { public void foo() { Object o= new Object(); @@ -2581,8 +2580,8 @@ public void testTypeMismatchPrimitiveTypes() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - - + + public class E { public void foo(long o) { int i= o; @@ -2609,8 +2608,8 @@ public void foo(long o) { String[] expected= new String[3]; expected[0]= """ package pack; - - + + public class E { public void foo(long o) { int i= (int) o; @@ -2620,8 +2619,8 @@ public void foo(long o) { expected[1]= """ package pack; - - + + public class E { public void foo(int o) { int i= o; @@ -2631,8 +2630,8 @@ public void foo(int o) { expected[2]= """ package pack; - - + + public class E { public void foo(long o) { long i= o; diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java index 8e1ef1901ca..fc1de3fa21e 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedMethodsQuickFixTest.java @@ -111,7 +111,7 @@ public class E { void foo(Vector vec) { int i= goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -149,7 +149,7 @@ void foo() { for (int i= 0, j= goo(3); i < 0; i++) { } } - + private int goo(int i) { return 0; } @@ -185,7 +185,7 @@ public class E { private boolean foo() { return f(1) || f(2); } - + private boolean f(int i) { return false; } @@ -221,7 +221,7 @@ public class E { private boolean foo() { return f(1) == f(2); } - + private Object f(int i) { return null; } @@ -237,7 +237,7 @@ public void testMethodSpacing0EmptyLines() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } void foo(Vector vec) { @@ -259,7 +259,7 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } void foo(Vector vec) { @@ -280,10 +280,10 @@ public void testMethodSpacing1EmptyLine() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } - + void foo(Vector vec) { int i= goo(vec, true); } @@ -303,14 +303,14 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } - + void foo(Vector vec) { int i= goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -326,7 +326,7 @@ public void testMethodSpacing2EmptyLines() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } \s @@ -350,7 +350,7 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } \s @@ -358,8 +358,8 @@ void fred() { void foo(Vector vec) { int i= goo(vec, true); } - - + + private int goo(Vector vec, boolean b) { return 0; } @@ -375,12 +375,12 @@ public void testMethodSpacingComment() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } - + //comment - + void foo(Vector vec) { int i= goo(vec, true); } @@ -400,16 +400,16 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } - + //comment - + void foo(Vector vec) { int i= goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -425,10 +425,10 @@ public void testMethodSpacingJavadoc() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } - + /** * javadoc */ @@ -451,17 +451,17 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } - + /** * javadoc */ void foo(Vector vec) { int i= goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -477,10 +477,10 @@ public void testMethodSpacingNonJavadoc() throws Exception { package test1; import java.util.Vector; public class E { - + void fred() { } - + /* * non javadoc */ @@ -503,17 +503,17 @@ void foo(Vector vec) { package test1; import java.util.Vector; public class E { - + void fred() { } - + /* * non javadoc */ void foo(Vector vec) { int i= goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -551,7 +551,7 @@ public class E { void foo(Vector vec) { int i= this.goo(vec, true); } - + private int goo(Vector vec, boolean b) { return 0; } @@ -601,7 +601,7 @@ public interface Y { String expected1= """ package test1; public class X { - + public boolean goo(int i, double d) { return false; } @@ -637,7 +637,7 @@ public void method() { help.help(this); } } - + class Help { } """; @@ -659,9 +659,9 @@ public void method() { help.help(this); } } - + class Help { - + public void help(Bork bork) { } } @@ -700,7 +700,7 @@ public E() { public void run() {} }); } - + private void foo(Runnable runnable) { } } @@ -750,7 +750,7 @@ void foo(X x) { String expected1= """ package test1; public class X { - + public boolean goo(X x) { return false; } @@ -798,7 +798,7 @@ public class E { void foo(Vector vec) { vec.add(goo()); } - + private Object goo() { return null; } @@ -833,7 +833,7 @@ public class E { void foo(Vector vec) { vec.add(goo()); } - + private Number goo() { return null; } @@ -868,7 +868,7 @@ public class E { void foo(Vector vec) { goo(vec.get(0)); } - + private void goo(Object object) { } } @@ -888,7 +888,7 @@ public class E { void testMethod(Vector vec) { goo(vec.get(0)); } - + private void goo(int i) { } } @@ -906,10 +906,10 @@ public class E { void testMethod(Vector vec) { goo(vec.get(0)); } - + private void goo(Number number) { } - + private void goo(int i) { } } @@ -922,7 +922,7 @@ public class E { void testMethod(Vector vec) { goo(vec.get(0)); } - + private void goo(Number number) { } } @@ -1001,7 +1001,7 @@ public abstract class E> { void testMethod(T t) { t.goo(); } - + private void goo() { } } @@ -1047,7 +1047,7 @@ int foo(X x) { package test1; public class E { public class X { - + public int goo(X x) { return 0; } @@ -1118,7 +1118,7 @@ void foo(X x) { String expected1= """ package test1; public class X { - + public boolean goo(X x) { return false; } @@ -1177,7 +1177,7 @@ public void foo() { public void run() { xoo(); } - + private void xoo() { } }; @@ -1198,7 +1198,7 @@ public void run() { } }; } - + protected void xoo() { } } @@ -1263,7 +1263,7 @@ public void run() { String expected1= """ package other; public class A { - + public static void xoo() { } } @@ -1306,7 +1306,7 @@ public static void foo() { public void run() { xoo(); } - + private void xoo() { } }; @@ -1327,7 +1327,7 @@ public void run() { } }; } - + protected static void xoo() { } } @@ -1390,7 +1390,7 @@ public void run() { } }; } - + protected void foobar() { } } @@ -1449,7 +1449,7 @@ public void foo() { public int compareTo(String s) { xoo(); } - + private void xoo() { } }; @@ -1470,7 +1470,7 @@ public int compareTo(String s) { } }; } - + protected void xoo() { } } @@ -1589,7 +1589,7 @@ public void foo() { public void run() { run(1); } - + private void run(int i) { } }; @@ -1692,7 +1692,7 @@ public void foo() { public void run() { run(1); } - + private void run(int i) { } }; @@ -1786,7 +1786,7 @@ public class Inner { public void run() { run(1); } - + private void run(int i) { } } @@ -1831,7 +1831,7 @@ public static class Inner { public void run() { run(1); } - + private void run(int i) { } } @@ -1907,7 +1907,7 @@ public interface X { String expected1= """ package test1; public interface X { - + boolean goo(Class class1); } """; @@ -1933,7 +1933,7 @@ public void testMethodInArrayAccess() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("p", false, null); String str= """ package p; - + public class E { void foo() { int i = bar()[0]; @@ -1951,12 +1951,12 @@ void foo() { String[] expected= new String[1]; expected[0]= """ package p; - + public class E { void foo() { int i = bar()[0]; } - + private int[] bar() { return null; } @@ -2011,7 +2011,7 @@ public void foo(int i) { long x= 0; foo(x + 1); } - + private void foo(long l) { } } @@ -2084,7 +2084,7 @@ public void foo(int i) { public class X { public static void xoo(int i, Object o) { } - + public static void xoo(float x, E o) { } } @@ -2145,7 +2145,7 @@ public class E { public void foo(Integer i) { foo(1.0); } - + private void foo(double d) { } } @@ -2290,9 +2290,9 @@ public void goo(long x) { String expected2= """ package test1; - + import java.util.Vector; - + public class E { public void foo(A a, Vector x) { a.goo(x); @@ -2309,7 +2309,7 @@ public void foo(A a, Vector x) { public class A { public void goo(Vector v) { } - + public void goo(long x) { } } @@ -2324,9 +2324,9 @@ public void testParameterMismatchKeepModifiers() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null); String str= """ package test1; - + import java.util.Collections; - + class E { void foo(@Deprecated final String map){} {foo(Collections.EMPTY_MAP);} @@ -2343,10 +2343,10 @@ void foo(@Deprecated final String map){} String[] expected= new String[2]; expected[0]= """ package test1; - + import java.util.Collections; import java.util.Map; - + class E { void foo(@Deprecated final Map emptyMap){} {foo(Collections.EMPTY_MAP);} @@ -2355,10 +2355,10 @@ void foo(@Deprecated final Map emptyMap){} expected[1]= """ package test1; - + import java.util.Collections; import java.util.Map; - + class E { void foo(@Deprecated final String map){} {foo(Collections.EMPTY_MAP);} @@ -2484,9 +2484,9 @@ public void foo(X x, int y) { String expected1= """ package test1; - + import java.util.Vector; - + public class X { Vector count= 0; } @@ -2784,7 +2784,7 @@ public void foo(String s, int i, Object o) { int x= 0; foo(x); } - + private void foo(int x) { } } @@ -2856,7 +2856,7 @@ public void foo() { public class X { public static void xoo(int i, Object o) { } - + public static void xoo(Object object) { } } @@ -2936,7 +2936,7 @@ public class X { */ public static void xoo(int i, Object o) { } - + public static void xoo(int i) { } } @@ -3011,7 +3011,7 @@ public void meth(E e, String s) { int x= 0; e.foo(x); } - + private void foo(int x) { } } @@ -3037,7 +3037,7 @@ public void meth(E e, String s) { int x= 0; e.foo(x); } - + protected abstract void foo(int x); } """; @@ -3073,7 +3073,7 @@ private class B { void test () { foo (); } - + private void foo() { } } @@ -3088,7 +3088,7 @@ void test () { foo (); } } - + public void foo() { } } @@ -3102,7 +3102,7 @@ void test () { foo (); } } - + protected abstract void foo(); } """; @@ -3146,7 +3146,7 @@ private abstract class B { void test () { foo (); } - + private void foo() { } } @@ -3161,7 +3161,7 @@ void test () { foo (); } } - + public void foo() { } } @@ -3175,7 +3175,7 @@ void test () { foo (); } } - + protected abstract void foo(); } """; @@ -3187,7 +3187,7 @@ private abstract class B { void test () { foo (); } - + protected abstract void foo(); } } @@ -3253,13 +3253,13 @@ public E() { String expected2= """ package test1; - + import java.util.Vector; - + public class X { public X(Object o, int i) { } - + public X(Vector vector) { } } @@ -3555,7 +3555,7 @@ public void xoo(int i, int j, String o) { public class X { public void xoo(int i, String o) { } - + public void xoo(int i, int j, String string) { } } @@ -3608,7 +3608,7 @@ public void foo(String s) { int x= 0; foo(s, x); } - + private void foo(String s, int x) { } } @@ -3682,9 +3682,9 @@ public void foo(X x) { String expected2= """ package test1; - + import java.util.Set; - + public class X { /** * @param emptySet\s @@ -3702,9 +3702,9 @@ public void xoo(Set emptySet, int i, int k) { String expected3= """ package test1; - + import java.util.Set; - + public class X { /** * @param i The int value @@ -3712,7 +3712,7 @@ public class X { public void xoo(int i) { int j= 0; } - + public void xoo(Set emptySet, int i, int j) { } } @@ -3766,7 +3766,7 @@ public void foo() { Object[] o= null; foo(o.length); } - + private void foo(int length) { } } @@ -3842,7 +3842,7 @@ public class X { */ public void xoo(String s) { } - + public void xoo(String string, X x, int i) { } } @@ -3899,13 +3899,13 @@ public E() { String expected2= """ package test1; - + import java.util.Vector; - + public class X { public X() { } - + public X(Vector vector) { } } @@ -3916,9 +3916,9 @@ public X(Vector vector) { String expected3= """ package test1; - + import java.util.Vector; - + public class X { public X(Vector vector) { } @@ -4130,7 +4130,7 @@ public class E { public void foo(int i, String[] o) { foo(new String[] { }, i - 1); } - + private void foo(String[] strings, int i) { } } @@ -4199,7 +4199,7 @@ public void b(T[] t, int i) { public class A { public void b(int i, T[] t) { } - + public void b(String[] strings, int i) { } } @@ -4452,7 +4452,7 @@ public class E { public void foo(int i, Object o, boolean b) { foo(false, o, i - 1); } - + private void foo(boolean b, Object o, int i) { } } @@ -4510,7 +4510,7 @@ public class A { String expected1= """ package test1; public class A { - + public A(int i) { } } @@ -4564,7 +4564,7 @@ public class A { String expected1= """ package test1; public class A { - + public A(int i) { } } @@ -4615,7 +4615,7 @@ public void foo(int i) { A a= new A("test"); } class A { - + public A(String string) { } } @@ -4671,7 +4671,7 @@ public class A { String expected1= """ package test1; public class A { - + public A(int i) { } } @@ -4751,7 +4751,7 @@ public void foo(int i) { public class A { public A(int i) { } - + public A(int i, String valueOf, boolean b) { } } @@ -4818,7 +4818,7 @@ public A(int i, boolean b, String ... strings) { public class A { public A(boolean b, String ... strings) { } - + public A(int i, boolean b) { } } @@ -4887,7 +4887,7 @@ public void foo(int i) { public class A { public A(int i) { } - + public A(int i, String valueOf, boolean b) { } } @@ -4954,7 +4954,7 @@ public void foo(int i) { public class A { public A(int i, String s) { } - + public A() { } } @@ -5023,7 +5023,7 @@ public void foo(int i) { public class A { public A(int i, String s) { } - + public A() { } } @@ -5060,7 +5060,7 @@ public class E { public E(int i) { this(i, true); } - + public E(int i, boolean b) { } } @@ -5097,7 +5097,7 @@ public class E { public E(int i) { this(i, true); } - + public E(int i, boolean b) { } } @@ -5137,7 +5137,7 @@ public class A { String str2= """ package test1; public class A { - + public void foo(int i) { } } @@ -5204,7 +5204,7 @@ public A(int i, boolean b, String ... strings) { public class A { public A(boolean b, String ... strings) { } - + public A(int i, boolean b) { } } @@ -5262,9 +5262,9 @@ public void xoo() { String expected2= """ package test1; - + import java.util.Vector; - + public class X { public int foo(Vector vector) { return 0; @@ -5277,14 +5277,14 @@ public int foo(Vector vector) { String expected3= """ package test1; - + import java.util.Vector; - + public class X { public int foo() { return 0; } - + public void foo(Vector vector) { } } @@ -5355,14 +5355,14 @@ public int foo(Object o) { String expected3= """ package test1; - + import java.util.Vector; - + public class X { public int foo(Object o, boolean b) { return 0; } - + public void foo(Vector vector) { } } @@ -5567,7 +5567,7 @@ public class E { public void foo(Object[] array) { throw RuntimeException(); } - + private Exception RuntimeException() { return null; } @@ -5586,7 +5586,7 @@ public void testMissingAnnotationAttribute1() throws Exception { public class E { public @interface Annot { } - + @Annot(count= 1) public void foo() { } @@ -5605,10 +5605,10 @@ public void foo() { package pack; public class E { public @interface Annot { - + int count(); } - + @Annot(count= 1) public void foo() { } @@ -5626,7 +5626,7 @@ public void testMissingAnnotationAttribute2() throws Exception { public class E { public @interface Annot { } - + @Annot(1) public void foo() { } @@ -5645,10 +5645,10 @@ public void foo() { package pack; public class E { public @interface Annot { - + int value(); } - + @Annot(1) public void foo() { } @@ -5666,7 +5666,7 @@ public void testStaticImportFavorite1() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { private int foo() { return max(1, 2); @@ -5683,9 +5683,9 @@ private int foo() { String[] expected= new String[1]; expected[0]= """ package pack; - + import static java.lang.Math.max; - + public class E { private int foo() { return max(1, 2); @@ -5707,7 +5707,7 @@ public void testStaticImportFavorite2() throws Exception { IPackageFragment pack1= fSourceFolder.createPackageFragment("pack", false, null); String str= """ package pack; - + public class E { private int max() { return max(1, 2); @@ -5724,7 +5724,7 @@ private int max() { String[] expected= new String[1]; expected[0]= """ package pack; - + public class E { private int max() { return Math.max(1, 2); @@ -5807,7 +5807,7 @@ void foo(Snippet c) { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 1); - assertNumberOfProposals(proposals, 0); + assertNumberOfProposals(proposals, 1); } @Test @@ -5826,7 +5826,7 @@ interface Ref { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 1); - assertNumberOfProposals(proposals, 0); + assertNumberOfProposals(proposals, 1); } @Test @@ -5844,7 +5844,7 @@ interface I { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 1); - assertNumberOfProposals(proposals, 1); + assertNumberOfProposals(proposals, 2); assertCorrectLabels(proposals); CUCorrectionProposal proposal= (CUCorrectionProposal) proposals.get(0); @@ -5854,10 +5854,10 @@ interface I { public class XX { interface I { int i= n(); - } - - protected static int n() { - return 0; + + static int n() { + return 0; + } } } """; @@ -5877,7 +5877,7 @@ interface I { CompilationUnit astRoot= getASTRoot(cu); ArrayList proposals= collectCorrections(cu, astRoot, 1); - assertNumberOfProposals(proposals, 0); + assertNumberOfProposals(proposals, 1); } @Test @@ -5907,7 +5907,7 @@ void foo(Snippet c) { package test1; interface Snippet { abstract String name(); - + abstract int[] values(); } class Ref {