
org.snapscript.tree.define.SuperDispatcher 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.define;
import org.snapscript.core.Context;
import org.snapscript.core.InternalStateException;
import org.snapscript.core.Module;
import org.snapscript.core.Scope;
import org.snapscript.core.Type;
import org.snapscript.core.Value;
import org.snapscript.core.function.Invocation;
import org.snapscript.core.platform.Platform;
import org.snapscript.core.platform.PlatformProvider;
import org.snapscript.tree.dispatch.InvocationDispatcher;
public class SuperDispatcher implements InvocationDispatcher{
private final Scope scope;
private final Type type;
public SuperDispatcher(Scope scope, Type type) {
this.scope = scope;
this.type = type;
}
@Override
public Value dispatch(String name, Object... list) throws Exception {
Type real = (Type)list[0];
Module module = scope.getModule();
Context context = module.getContext();
Class base = type.getType();
if(base == null) {
throw new InternalStateException("Base type of '" + type + "' is null");
}
Object[] copy = new Object[list.length - 1];
if(copy.length > 0) {
System.arraycopy(list, 1, copy, 0, copy.length);
}
PlatformProvider provider = context.getProvider();
Platform platform = provider.create();
Invocation invocation = platform.createSuperConstructor(real, type);
Object instance = invocation.invoke(scope, real, copy);
return Value.getTransient(instance, type);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy