Merge pull request #2376 from Rawi01/extensionMethod

Set missing argumentTypes for eclipse extension methods
This commit is contained in:
Reinier Zwitserloot authored and GitHub committed 2020-02-27 23:00:24 +01:00
commit f129fa85ba
2 files changed
+24

No files matched your search

+1
View File
@@ -28,6 +28,7 @@ Peter Grant <petercgrant@users.noreply.github.com>
Philipp Eichhorn <peichhor@web.de>
Philippe Charles <philippe.charles@nbb.be>
Rabea Gransberger <rgra@users.noreply.github.com>
Raul Wißfeld <Rawi01@users.noreply.github.com>
Reinier Zwitserloot <reinier@zwitserloot.com>
Robbert Jan Grootjans <grootjans@gmail.com>
Robert Wertman <robert.wertman@gmail.com>
@@ -24,6 +24,7 @@ package lombok.eclipse.agent;
import static lombok.eclipse.handlers.EclipseHandlerUtil.createAnnotation;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
@@ -39,6 +40,7 @@ import lombok.eclipse.EclipseNode;
import lombok.eclipse.TransformEclipseAST;
import lombok.eclipse.handlers.EclipseHandlerUtil;
import lombok.experimental.ExtensionMethod;
import lombok.permit.Permit;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
import org.eclipse.jdt.internal.compiler.ast.Annotation;
@@ -293,6 +295,13 @@ public class PatchExtensionMethod {
methodCall.actualReceiverType = extensionMethod.declaringClass;
methodCall.binding = fixedBinding;
methodCall.resolvedType = methodCall.binding.returnType;
if (Reflection.argumentTypes != null) {
try {
Reflection.argumentTypes.set(methodCall, argumentTypes.toArray(new TypeBinding[0]));
} catch (IllegalAccessException ignore) {
// ignore
}
}
}
return methodCall.resolvedType;
}
@@ -329,4 +338,18 @@ public class PatchExtensionMethod {
return new QualifiedNameReference(sources, poss, source.sourceStart, source.sourceEnd);
}
}
private static final class Reflection {
public static final Field argumentTypes;
static {
Field a = null;
try {
a = Permit.getField(MessageSend.class, "argumentTypes");
} catch (Throwable t) {
//ignore - old eclipse versions don't know this one
}
argumentTypes = a;
}
}
}