org.snapscript.platform.generate.BridgeInstanceConverter 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.platform.generate;
import static org.snapscript.core.Reserved.TYPE_THIS;
import java.util.List;
import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.convert.proxy.ProxyWrapper;
import org.snapscript.core.property.Property;
import org.snapscript.core.scope.State;
import org.snapscript.core.type.Type;
import org.snapscript.core.variable.Value;
public class BridgeInstanceConverter {
private final ProxyWrapper wrapper;
public BridgeInstanceConverter(ProxyWrapper wrapper) {
this.wrapper = wrapper;
}
public void convert(BridgeInstance instance) {
Type base = instance.getBase(); // this might be the wrong type
Value self = Value.getReference(instance);
List types = base.getTypes();
State state = instance.getState();
update(instance, state, base);
for(Constraint type : types) {
Type match = type.getType(instance);
if(match != null) {
update(instance, state, match);
}
}
state.addValue(TYPE_THIS, self);
}
private void update(BridgeInstance instance, State state, Type type) {
List properties = type.getProperties();
for(Property property : properties) {
String name = property.getName();
if(!name.equals(TYPE_THIS)) {
Object current = state.getValue(name);
if(current == null) {
Value value = new BridgeValue(instance, wrapper, property, name);
state.addValue(name, value);
}
}
}
}
}