org.snapscript.tree.function.FunctionHandleBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.function;
import static java.util.Collections.EMPTY_LIST;
import static org.snapscript.core.ModifierType.PUBLIC;
import static org.snapscript.core.Reserved.DEFAULT_PARAMETER;
import static org.snapscript.core.constraint.Constraint.NONE;
import static org.snapscript.core.function.Origin.SYSTEM;
import java.util.ArrayList;
import java.util.List;
import org.snapscript.core.function.Function;
import org.snapscript.core.function.FunctionSignature;
import org.snapscript.core.function.FunctionType;
import org.snapscript.core.function.Invocation;
import org.snapscript.core.function.InvocationFunction;
import org.snapscript.core.function.Parameter;
import org.snapscript.core.function.Signature;
import org.snapscript.core.function.bind.FunctionMatcher;
import org.snapscript.core.module.Module;
import org.snapscript.core.type.Type;
import org.snapscript.core.variable.Value;
public class FunctionHandleBuilder {
private final FunctionMatcher matcher;
private final Parameter parameter;
private final boolean constructor;
public FunctionHandleBuilder(FunctionMatcher matcher, boolean constructor) {
this.parameter = new Parameter(DEFAULT_PARAMETER, NONE, 0, false, true);
this.constructor = constructor;
this.matcher = matcher;
}
public Function create(Module module, Value value, String method) throws Exception {
List parameters = new ArrayList();
Signature signature = new FunctionSignature(parameters, EMPTY_LIST, module, null, SYSTEM, true, true);
Invocation invocation = new FunctionHandleInvocation(matcher, module, value, constructor);
Type type = new FunctionType(signature, module, null);
parameters.add(parameter);
return new InvocationFunction(signature, invocation, type, null, method, PUBLIC.mask);
}
}