2020package org .elasticsearch .painless ;
2121
2222import org .elasticsearch .painless .Definition .Method ;
23- import org .elasticsearch .painless .Definition .Type ;
24- import org .elasticsearch .painless .api .Augmentation ;
2523
2624import java .lang .invoke .MethodType ;
2725import java .lang .reflect .Modifier ;
@@ -75,8 +73,9 @@ public class FunctionRef {
7573 * @param call the right hand side of a method reference expression
7674 * @param numCaptures number of captured arguments
7775 */
78- public FunctionRef (Definition definition , Type expected , String type , String call , int numCaptures ) {
79- this (expected , expected .struct .getFunctionalMethod (), lookup (definition , expected , type , call , numCaptures > 0 ), numCaptures );
76+ public FunctionRef (Definition definition , Class <?> expected , String type , String call , int numCaptures ) {
77+ this (expected , definition .ClassToType (expected ).struct .getFunctionalMethod (),
78+ lookup (definition , expected , type , call , numCaptures > 0 ), numCaptures );
8079 }
8180
8281 /**
@@ -86,11 +85,11 @@ public FunctionRef(Definition definition, Type expected, String type, String cal
8685 * @param delegateMethod implementation method
8786 * @param numCaptures number of captured arguments
8887 */
89- public FunctionRef (Type expected , Method interfaceMethod , Method delegateMethod , int numCaptures ) {
88+ public FunctionRef (Class <?> expected , Method interfaceMethod , Method delegateMethod , int numCaptures ) {
9089 MethodType delegateMethodType = delegateMethod .getMethodType ();
9190
9291 interfaceMethodName = interfaceMethod .name ;
93- factoryMethodType = MethodType .methodType (expected . clazz ,
92+ factoryMethodType = MethodType .methodType (expected ,
9493 delegateMethodType .dropParameterTypes (numCaptures , delegateMethodType .parameterCount ()));
9594 interfaceMethodType = interfaceMethod .getMethodType ().dropParameterTypes (0 , 1 );
9695
@@ -128,9 +127,10 @@ public FunctionRef(Type expected, Method interfaceMethod, Method delegateMethod,
128127 * Creates a new FunctionRef (low level).
129128 * It is for runtime use only.
130129 */
131- public FunctionRef (Type expected , Method interfaceMethod , String delegateMethodName , MethodType delegateMethodType , int numCaptures ) {
130+ public FunctionRef (Class <?> expected ,
131+ Method interfaceMethod , String delegateMethodName , MethodType delegateMethodType , int numCaptures ) {
132132 interfaceMethodName = interfaceMethod .name ;
133- factoryMethodType = MethodType .methodType (expected . clazz ,
133+ factoryMethodType = MethodType .methodType (expected ,
134134 delegateMethodType .dropParameterTypes (numCaptures , delegateMethodType .parameterCount ()));
135135 interfaceMethodType = interfaceMethod .getMethodType ().dropParameterTypes (0 , 1 );
136136
@@ -150,14 +150,14 @@ public FunctionRef(Type expected, Method interfaceMethod, String delegateMethodN
150150 /**
151151 * Looks up {@code type::call} from the whitelist, and returns a matching method.
152152 */
153- private static Definition .Method lookup (Definition definition , Definition . Type expected ,
153+ private static Definition .Method lookup (Definition definition , Class <?> expected ,
154154 String type , String call , boolean receiverCaptured ) {
155155 // check its really a functional interface
156156 // for e.g. Comparable
157- Method method = expected .struct .getFunctionalMethod ();
157+ Method method = definition . ClassToType ( expected ) .struct .getFunctionalMethod ();
158158 if (method == null ) {
159159 throw new IllegalArgumentException ("Cannot convert function reference [" + type + "::" + call + "] " +
160- "to [" + expected . name + "], not a functional interface" );
160+ "to [" + Definition . ClassToName ( expected ) + "], not a functional interface" );
161161 }
162162
163163 // lookup requested method
0 commit comments