Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ private static MethodHandle lookupReferenceInternal(Definition definition, Looku
}
throw new IllegalArgumentException("Unknown call [" + call + "] with [" + arity + "] arguments.");
}
ref = new FunctionRef(clazz, interfaceMethod, call, handle.type(), captures.length);
ref = new FunctionRef(clazz.clazz, interfaceMethod, call, handle.type(), captures.length);
} else {
// whitelist lookup
ref = new FunctionRef(definition, clazz, type, call, captures.length);
ref = new FunctionRef(definition, clazz.clazz, type, call, captures.length);
}
final CallSite callSite = LambdaBootstrap.lambdaBootstrap(
lookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -86,11 +85,11 @@ public FunctionRef(Definition definition, Type expected, String type, String cal
* @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);

Expand Down Expand Up @@ -128,9 +127,10 @@ public FunctionRef(Type expected, Method interfaceMethod, Method delegateMethod,
* 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);

Expand All @@ -150,14 +150,14 @@ public FunctionRef(Type expected, Method interfaceMethod, String delegateMethodN
/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void analyze(Locals locals) {
if (captured.type.dynamic == false) {
try {
ref = new FunctionRef(
locals.getDefinition(), locals.getDefinition().ClassToType(expected), captured.type.name, call, 1);
locals.getDefinition(), expected, captured.type.name, call, 1);

// check casts between the interface method and the delegate method are legal
for (int i = 0; i < ref.interfaceMethod.arguments.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void analyze(Locals locals) {
throw new IllegalArgumentException("Cannot convert function reference [" + type + "::" + call + "] " +
"to [" + Definition.ClassToName(expected) + "], function not found");
}
ref = new FunctionRef(locals.getDefinition().ClassToType(expected), interfaceMethod, delegateMethod, 0);
ref = new FunctionRef(expected, interfaceMethod, delegateMethod, 0);

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

} catch (IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void analyze(Locals locals) {
} else {
defPointer = null;
try {
ref = new FunctionRef(locals.getDefinition().ClassToType(expected), interfaceMethod, desugared.method, captures.size());
ref = new FunctionRef(expected, interfaceMethod, desugared.method, captures.size());
} catch (IllegalArgumentException e) {
throw createError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
package org.elasticsearch.painless;

import org.elasticsearch.painless.Definition.Cast;
import org.elasticsearch.painless.spi.Whitelist;

import org.elasticsearch.test.ESTestCase;

public class AnalyzerCasterTests extends ESTestCase {

private static final Definition definition = new Definition(Whitelist.BASE_WHITELISTS);

private static void assertCast(Class<?> actual, Class<?> expected, boolean mustBeExplicit) {
Location location = new Location("dummy", 0);

Expand Down