mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 20:15:09 +00:00
[fixes #3402] Delay replacement of extension methods in arguments
This commit is contained in:
1 parent
3f51b25ac9
commit
4edd8a42d6
7 files changed
+109
-1
No files matched your search
@@ -152,8 +152,10 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho
|
||||
|
||||
@Override
|
||||
public Void visitMethodInvocation(final MethodInvocationTree tree, final Void p) {
|
||||
super.visitMethodInvocation(tree, p);
|
||||
scan(tree.getTypeArguments(), p);
|
||||
scan(tree.getMethodSelect(), p);
|
||||
handleMethodCall((JCMethodInvocation) tree);
|
||||
scan(tree.getArguments(), p);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -181,6 +183,7 @@ public class HandleExtensionMethod extends JavacAnnotationHandler<ExtensionMetho
|
||||
JCTree resolvedReceiver = resolution.get(receiver);
|
||||
if (resolvedReceiver == null || resolvedReceiver.type == null) return;
|
||||
Type receiverType = resolvedReceiver.type;
|
||||
if (receiverType.isErroneous()) return;
|
||||
|
||||
// Skip static method access
|
||||
Symbol sym = null;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// version 8:
|
||||
import java.util.function.Function;
|
||||
|
||||
public class ExtensionMethodInLambda {
|
||||
public void testSimple() {
|
||||
String test = "test";
|
||||
test = ExtensionMethodInLambda.Extensions.map(test, s -> ExtensionMethodInLambda.Extensions.reverse(s));
|
||||
}
|
||||
|
||||
public void testSameName() {
|
||||
String test = "test";
|
||||
test = ExtensionMethodInLambda.Extensions.map(test, s -> s.trim());
|
||||
}
|
||||
|
||||
public void testArgumentOfInvalidMethod() {
|
||||
String test = "test";
|
||||
test.invalid(s -> s.reverse());
|
||||
}
|
||||
|
||||
|
||||
static class Extensions {
|
||||
public static <T, R> R map(T value, Function<T, R> mapper) {
|
||||
return mapper.apply(value);
|
||||
}
|
||||
|
||||
public static String reverse(String string) {
|
||||
return new StringBuilder(string).reverse().toString();
|
||||
}
|
||||
|
||||
public static String trim(Integer integer) {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import java.util.function.Function;
|
||||
import lombok.experimental.ExtensionMethod;
|
||||
public @ExtensionMethod(value = ExtensionMethodInLambda.Extensions.class) class ExtensionMethodInLambda {
|
||||
static class Extensions {
|
||||
Extensions() {
|
||||
super();
|
||||
}
|
||||
public static <T, R>R map(T value, Function<T, R> mapper) {
|
||||
return mapper.apply(value);
|
||||
}
|
||||
public static String reverse(String string) {
|
||||
return new StringBuilder(string).reverse().toString();
|
||||
}
|
||||
public static String trim(Integer integer) {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
public ExtensionMethodInLambda() {
|
||||
super();
|
||||
}
|
||||
public void testSimple() {
|
||||
String test = "test";
|
||||
test = ExtensionMethodInLambda.Extensions.map(test, (<no type> s) -> ExtensionMethodInLambda.Extensions.reverse(s));
|
||||
}
|
||||
public void testSameName() {
|
||||
String test = "test";
|
||||
test = ExtensionMethodInLambda.Extensions.map(test, (<no type> s) -> s.trim());
|
||||
}
|
||||
public void testArgumentOfInvalidMethod() {
|
||||
String test = "test";
|
||||
test.invalid((<no type> s) -> s.reverse());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// version 8:
|
||||
import java.util.function.Function;
|
||||
import lombok.experimental.ExtensionMethod;
|
||||
|
||||
@ExtensionMethod(value = ExtensionMethodInLambda.Extensions.class)
|
||||
public class ExtensionMethodInLambda {
|
||||
public void testSimple() {
|
||||
String test = "test";
|
||||
test = test.map(s -> s.reverse());
|
||||
}
|
||||
|
||||
public void testSameName() {
|
||||
String test = "test";
|
||||
test = test.map(s -> s.trim());
|
||||
}
|
||||
|
||||
public void testArgumentOfInvalidMethod() {
|
||||
String test = "test";
|
||||
test.invalid(s -> s.reverse());
|
||||
}
|
||||
|
||||
static class Extensions {
|
||||
public static <T, R> R map(T value, Function<T, R> mapper) {
|
||||
return mapper.apply(value);
|
||||
}
|
||||
|
||||
public static String reverse(String string) {
|
||||
return new StringBuilder(string).reverse().toString();
|
||||
}
|
||||
|
||||
public static String trim(Integer integer) {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
19 cannot find symbol symbol: method invalid((s)->s.reverse()) location: variable test of type java.lang.String
|
||||
@@ -0,0 +1 @@
|
||||
19 The method invalid((<no type> s) -> {}) is undefined for the type String
|
||||
@@ -0,0 +1 @@
|
||||
17 cannot find symbol symbol: method invalid((s)->s.reverse()) location: variable test of type java.lang.String
|
||||
Reference in new issue
Block a user