|
@@ -20,8 +20,6 @@
|
|
|
package org.elasticsearch.painless;
|
|
|
|
|
|
import org.elasticsearch.painless.Definition.Method;
|
|
|
-import org.elasticsearch.painless.Definition.Type;
|
|
|
-import org.elasticsearch.painless.api.Augmentation;
|
|
|
|
|
|
import java.lang.invoke.MethodType;
|
|
|
import java.lang.reflect.Modifier;
|
|
@@ -75,8 +73,9 @@ public class FunctionRef {
|
|
|
* @param call the right hand side of a method reference expression
|
|
|
* @param numCaptures number of captured arguments
|
|
|
*/
|
|
|
- public FunctionRef(Definition definition, Type expected, String type, String call, int numCaptures) {
|
|
|
- this(expected, expected.struct.getFunctionalMethod(), lookup(definition, expected, type, call, numCaptures > 0), numCaptures);
|
|
|
+ public FunctionRef(Definition definition, Class<?> expected, String type, String call, int numCaptures) {
|
|
|
+ this(expected, definition.ClassToType(expected).struct.getFunctionalMethod(),
|
|
|
+ lookup(definition, expected, type, call, numCaptures > 0), numCaptures);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -86,11 +85,11 @@ public class FunctionRef {
|
|
|
* @param delegateMethod implementation method
|
|
|
* @param numCaptures number of captured arguments
|
|
|
*/
|
|
|
- public FunctionRef(Type expected, Method interfaceMethod, Method delegateMethod, int numCaptures) {
|
|
|
+ public FunctionRef(Class<?> expected, Method interfaceMethod, Method delegateMethod, int numCaptures) {
|
|
|
MethodType delegateMethodType = delegateMethod.getMethodType();
|
|
|
|
|
|
interfaceMethodName = interfaceMethod.name;
|
|
|
- factoryMethodType = MethodType.methodType(expected.clazz,
|
|
|
+ factoryMethodType = MethodType.methodType(expected,
|
|
|
delegateMethodType.dropParameterTypes(numCaptures, delegateMethodType.parameterCount()));
|
|
|
interfaceMethodType = interfaceMethod.getMethodType().dropParameterTypes(0, 1);
|
|
|
|
|
@@ -128,9 +127,10 @@ public class FunctionRef {
|
|
|
* Creates a new FunctionRef (low level).
|
|
|
* It is for runtime use only.
|
|
|
*/
|
|
|
- public FunctionRef(Type expected, Method interfaceMethod, String delegateMethodName, MethodType delegateMethodType, int numCaptures) {
|
|
|
+ public FunctionRef(Class<?> expected,
|
|
|
+ Method interfaceMethod, String delegateMethodName, MethodType delegateMethodType, int numCaptures) {
|
|
|
interfaceMethodName = interfaceMethod.name;
|
|
|
- factoryMethodType = MethodType.methodType(expected.clazz,
|
|
|
+ factoryMethodType = MethodType.methodType(expected,
|
|
|
delegateMethodType.dropParameterTypes(numCaptures, delegateMethodType.parameterCount()));
|
|
|
interfaceMethodType = interfaceMethod.getMethodType().dropParameterTypes(0, 1);
|
|
|
|
|
@@ -150,14 +150,14 @@ public class FunctionRef {
|
|
|
/**
|
|
|
* Looks up {@code type::call} from the whitelist, and returns a matching method.
|
|
|
*/
|
|
|
- private static Definition.Method lookup(Definition definition, Definition.Type expected,
|
|
|
+ private static Definition.Method lookup(Definition definition, Class<?> expected,
|
|
|
String type, String call, boolean receiverCaptured) {
|
|
|
// check its really a functional interface
|
|
|
// for e.g. Comparable
|
|
|
- Method method = expected.struct.getFunctionalMethod();
|
|
|
+ Method method = definition.ClassToType(expected).struct.getFunctionalMethod();
|
|
|
if (method == null) {
|
|
|
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
|
|
|
- "to [" + expected.name + "], not a functional interface");
|
|
|
+ "to [" + Definition.ClassToName(expected) + "], not a functional interface");
|
|
|
}
|
|
|
|
|
|
// lookup requested method
|