Skip to content

Commit 1d01bcf

Browse files
authored
Remove Painless Type in favor of Java Class in FunctionRef. (#28429)
1 parent f13da9f commit 1d01bcf

File tree

6 files changed

+18
-20
lines changed

6 files changed

+18
-20
lines changed

modules/lang-painless/src/main/java/org/elasticsearch/painless/Def.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ private static MethodHandle lookupReferenceInternal(Definition definition, Looku
363363
}
364364
throw new IllegalArgumentException("Unknown call [" + call + "] with [" + arity + "] arguments.");
365365
}
366-
ref = new FunctionRef(clazz, interfaceMethod, call, handle.type(), captures.length);
366+
ref = new FunctionRef(clazz.clazz, interfaceMethod, call, handle.type(), captures.length);
367367
} else {
368368
// whitelist lookup
369-
ref = new FunctionRef(definition, clazz, type, call, captures.length);
369+
ref = new FunctionRef(definition, clazz.clazz, type, call, captures.length);
370370
}
371371
final CallSite callSite = LambdaBootstrap.lambdaBootstrap(
372372
lookup,

modules/lang-painless/src/main/java/org/elasticsearch/painless/FunctionRef.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
package org.elasticsearch.painless;
2121

2222
import org.elasticsearch.painless.Definition.Method;
23-
import org.elasticsearch.painless.Definition.Type;
24-
import org.elasticsearch.painless.api.Augmentation;
2523

2624
import java.lang.invoke.MethodType;
2725
import 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

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ECapturingFunctionRef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void analyze(Locals locals) {
7777
if (captured.type.dynamic == false) {
7878
try {
7979
ref = new FunctionRef(
80-
locals.getDefinition(), locals.getDefinition().ClassToType(expected), captured.type.name, call, 1);
80+
locals.getDefinition(), expected, captured.type.name, call, 1);
8181

8282
// check casts between the interface method and the delegate method are legal
8383
for (int i = 0; i < ref.interfaceMethod.arguments.size(); ++i) {

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/EFunctionRef.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void analyze(Locals locals) {
7676
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
7777
"to [" + Definition.ClassToName(expected) + "], function not found");
7878
}
79-
ref = new FunctionRef(locals.getDefinition().ClassToType(expected), interfaceMethod, delegateMethod, 0);
79+
ref = new FunctionRef(expected, interfaceMethod, delegateMethod, 0);
8080

8181
// check casts between the interface method and the delegate method are legal
8282
for (int i = 0; i < interfaceMethod.arguments.size(); ++i) {
@@ -91,7 +91,7 @@ void analyze(Locals locals) {
9191
}
9292
} else {
9393
// whitelist lookup
94-
ref = new FunctionRef(locals.getDefinition(), locals.getDefinition().ClassToType(expected), type, call, 0);
94+
ref = new FunctionRef(locals.getDefinition(), expected, type, call, 0);
9595
}
9696

9797
} catch (IllegalArgumentException e) {

modules/lang-painless/src/main/java/org/elasticsearch/painless/node/ELambda.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ void analyze(Locals locals) {
183183
} else {
184184
defPointer = null;
185185
try {
186-
ref = new FunctionRef(locals.getDefinition().ClassToType(expected), interfaceMethod, desugared.method, captures.size());
186+
ref = new FunctionRef(expected, interfaceMethod, desugared.method, captures.size());
187187
} catch (IllegalArgumentException e) {
188188
throw createError(e);
189189
}

modules/lang-painless/src/test/java/org/elasticsearch/painless/AnalyzerCasterTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
package org.elasticsearch.painless;
2121

2222
import org.elasticsearch.painless.Definition.Cast;
23-
import org.elasticsearch.painless.spi.Whitelist;
23+
2424
import org.elasticsearch.test.ESTestCase;
2525

2626
public class AnalyzerCasterTests extends ESTestCase {
2727

28-
private static final Definition definition = new Definition(Whitelist.BASE_WHITELISTS);
29-
3028
private static void assertCast(Class<?> actual, Class<?> expected, boolean mustBeExplicit) {
3129
Location location = new Location("dummy", 0);
3230

0 commit comments

Comments
 (0)