org.snapscript.tree.define.InstanceInvocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.define;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.function.Invocation;
import org.snapscript.core.function.InvocationBuilder;
import org.snapscript.core.scope.Scope;
import org.snapscript.core.scope.ScopeBinder;
public class InstanceInvocation implements Invocation {
private final InvocationBuilder builder;
private final ScopeBinder binder;
private final String name;
private final boolean trait;
public InstanceInvocation(InvocationBuilder builder, String name, boolean trait) {
this.binder = new ScopeBinder();
this.builder = builder;
this.trait = trait;
this.name = name;
}
@Override
public Object invoke(Scope scope, Scope instance, Object... list) throws Exception {
if(trait) {
throw new InternalStateException("Function '" + name + "' is abstract");
}
Scope outer = binder.bind(scope, instance);
Invocation invocation = builder.create(outer);
return invocation.invoke(outer, instance, list);
}
}