From db80bb0a2168245dbae2e1ec565a830e92a7c684 Mon Sep 17 00:00:00 2001 From: Rawi01 Date: Thu, 19 Nov 2020 17:36:40 +0100 Subject: [fixes #2648] Reset inference context, remove generic information copy In Java >= 8 ecj uses the inference context to resolve the generic information. This one is already set before lombok tries rewrite the method call. Simply copying the information does not cover all the different cases but reseting the inference contexts and running type inference again does. --- .../after-delombok/ExtensionMethodFunctional.java | 15 +++++++++- .../after-delombok/ExtensionMethodGeneric.java | 33 ++++++++++++++++++++ .../after-ecj/ExtensionMethodFunctional.java | 15 ++++++++-- .../resource/after-ecj/ExtensionMethodGeneric.java | 35 ++++++++++++++++++++++ .../resource/before/ExtensionMethodFunctional.java | 18 +++++++++-- .../resource/before/ExtensionMethodGeneric.java | 34 +++++++++++++++++++++ 6 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 test/transform/resource/after-delombok/ExtensionMethodGeneric.java create mode 100644 test/transform/resource/after-ecj/ExtensionMethodGeneric.java create mode 100644 test/transform/resource/before/ExtensionMethodGeneric.java (limited to 'test') diff --git a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java index bd301543..fb58eb91 100644 --- a/test/transform/resource/after-delombok/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-delombok/ExtensionMethodFunctional.java @@ -1,5 +1,8 @@ -import java.util.function.Function; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; class ExtensionMethodFunctional { public void test() { @@ -7,6 +10,8 @@ class ExtensionMethodFunctional { test = ExtensionMethodFunctional.Extensions.map(test, s -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); + ExtensionMethodFunctional.Extensions.toList(Stream.of("a", "b", "c").map(String::toUpperCase)); + List i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } static class Extensions { @@ -24,5 +29,13 @@ class ExtensionMethodFunctional { consumer[i].accept(o); } } + + public static List toList(Stream stream) { + return (List) stream.collect(Collectors.toList()); + } + + public static List toList2(Stream stream) { + return null; + } } } diff --git a/test/transform/resource/after-delombok/ExtensionMethodGeneric.java b/test/transform/resource/after-delombok/ExtensionMethodGeneric.java new file mode 100644 index 00000000..8559b7ff --- /dev/null +++ b/test/transform/resource/after-delombok/ExtensionMethodGeneric.java @@ -0,0 +1,33 @@ +import java.util.List; +import java.util.Map; + +class ExtensionMethodGeneric { + public void test() { + List stringList = null; + List numberList = null; + ExtensionMethodGeneric.Extensions.test(stringList); + ExtensionMethodGeneric.Extensions.test(stringList, numberList); + ExtensionMethodGeneric.Extensions.test(ExtensionMethodGeneric.Extensions.test(stringList, stringList), numberList); + Integer i = ExtensionMethodGeneric.Extensions.test2(stringList); + Map map = null; + List l = ExtensionMethodGeneric.Extensions.test(map, stringList, numberList); + } + + static class Extensions { + public static List test(List obj, List list) { + return null; + } + + public static K test(Map obj, K k, V v) { + return k; + } + + public static T test(List list) { + return null; + } + + public static U test2(List list) { + return null; + } + } +} diff --git a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java index 0190eabb..e847c1f0 100644 --- a/test/transform/resource/after-ecj/ExtensionMethodFunctional.java +++ b/test/transform/resource/after-ecj/ExtensionMethodFunctional.java @@ -1,7 +1,10 @@ -import java.util.function.Function; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.experimental.ExtensionMethod; -@ExtensionMethod(ExtensionMethodFunctional.Extensions.class) class ExtensionMethodFunctional { +@ExtensionMethod(value = ExtensionMethodFunctional.Extensions.class,suppressBaseMethods = false) class ExtensionMethodFunctional { static class Extensions { Extensions() { super(); @@ -18,6 +21,12 @@ import lombok.experimental.ExtensionMethod; consumer[i].accept(o); } } + public static List toList(Stream stream) { + return (List) stream.collect(Collectors.toList()); + } + public static List toList2(Stream stream) { + return null; + } } ExtensionMethodFunctional() { super(); @@ -27,5 +36,7 @@ import lombok.experimental.ExtensionMethod; test = ExtensionMethodFunctional.Extensions.map(test, ( s) -> ExtensionMethodFunctional.Extensions.reverse(s)); ExtensionMethodFunctional.Extensions.consume(test, ( s) -> System.out.println(("1: " + s)), ( s) -> System.out.println(("2: " + s))); ExtensionMethodFunctional.Extensions.consume(test, System.out::println, System.out::println); + ExtensionMethodFunctional.Extensions.toList(Stream.of("a", "b", "c").map(String::toUpperCase)); + List i2 = ExtensionMethodFunctional.Extensions.toList2(Stream.of("a", "b", "c").map(String::toUpperCase)); } } diff --git a/test/transform/resource/after-ecj/ExtensionMethodGeneric.java b/test/transform/resource/after-ecj/ExtensionMethodGeneric.java new file mode 100644 index 00000000..2bfab9cc --- /dev/null +++ b/test/transform/resource/after-ecj/ExtensionMethodGeneric.java @@ -0,0 +1,35 @@ +import java.util.List; +import java.util.Map; +import lombok.experimental.ExtensionMethod; +@ExtensionMethod(ExtensionMethodGeneric.Extensions.class) class ExtensionMethodGeneric { + static class Extensions { + Extensions() { + super(); + } + public static List test(List obj, List list) { + return null; + } + public static K test(Map obj, K k, V v) { + return k; + } + public static T test(List list) { + return null; + } + public static U test2(List list) { + return null; + } + } + ExtensionMethodGeneric() { + super(); + } + public void test() { + List stringList = null; + List numberList = null; + ExtensionMethodGeneric.Extensions.test(stringList); + ExtensionMethodGeneric.Extensions.test(stringList, numberList); + ExtensionMethodGeneric.Extensions.test(ExtensionMethodGeneric.Extensions.test(stringList, stringList), numberList); + Integer i = ExtensionMethodGeneric.Extensions.test2(stringList); + Map map = null; + List l = ExtensionMethodGeneric.Extensions.test(map, stringList, numberList); + } +} \ No newline at end of file diff --git a/test/transform/resource/before/ExtensionMethodFunctional.java b/test/transform/resource/before/ExtensionMethodFunctional.java index 19983258..a9e7dd9f 100644 --- a/test/transform/resource/before/ExtensionMethodFunctional.java +++ b/test/transform/resource/before/ExtensionMethodFunctional.java @@ -1,10 +1,13 @@ // version 8: -import java.util.function.Function; import java.util.function.Consumer; +import java.util.function.Function; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import lombok.experimental.ExtensionMethod; -@ExtensionMethod(ExtensionMethodFunctional.Extensions.class) +@ExtensionMethod(value = ExtensionMethodFunctional.Extensions.class, suppressBaseMethods = false) class ExtensionMethodFunctional { public void test() { String test = "test"; @@ -12,6 +15,9 @@ class ExtensionMethodFunctional { test.consume(s -> System.out.println("1: " + s), s -> System.out.println("2: " + s)); test.consume(System.out::println, System.out::println); + + Stream.of("a", "b", "c").map(String::toUpperCase).toList(); + List i2 = Stream.of("a", "b", "c").map(String::toUpperCase).toList2(); } static class Extensions { @@ -29,5 +35,13 @@ class ExtensionMethodFunctional { consumer[i].accept(o); } } + + public static List toList(Stream stream) { + return (List) stream.collect(Collectors.toList()); + } + + public static List toList2(Stream stream) { + return null; + } } } diff --git a/test/transform/resource/before/ExtensionMethodGeneric.java b/test/transform/resource/before/ExtensionMethodGeneric.java new file mode 100644 index 00000000..d44c663b --- /dev/null +++ b/test/transform/resource/before/ExtensionMethodGeneric.java @@ -0,0 +1,34 @@ +import java.util.List; +import java.util.Map; + +import lombok.experimental.ExtensionMethod; + +@ExtensionMethod(ExtensionMethodGeneric.Extensions.class) +class ExtensionMethodGeneric { + public void test() { + List stringList = null; + List numberList = null; + stringList.test(); + stringList.test(numberList); + stringList.test(stringList).test(numberList); + Integer i = stringList.test2(); + + Map map = null; + List l = map.test(stringList, numberList); + } + + static class Extensions { + public static List test(List obj, List list) { + return null; + } + public static K test(Map obj, K k, V v) { + return k; + } + public static T test(List list) { + return null; + } + public static U test2(List list) { + return null; + } + } +} -- cgit