![JAR search and dependency download from the Maven repository](/logo.png)
org.snapscript.bridge.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.bridge.generate;
import static org.snapscript.core.Reserved.TYPE_THIS;
import java.util.List;
import org.snapscript.core.State;
import org.snapscript.core.Type;
import org.snapscript.core.Value;
import org.snapscript.core.ValueType;
import org.snapscript.core.define.Instance;
import org.snapscript.core.property.Property;
import org.snapscript.core.property.PropertyValue;
public class BridgeInstanceConverter {
private final Type type;
public BridgeInstanceConverter(Type type) {
this.type = type;
}
public void convert(Instance instance) {
Value self = ValueType.getReference(instance);
List types = type.getTypes();
State state = instance.getState();
Object bridge = instance.getBridge();
update(state, bridge, type);
for(Type type : types) {
update(state, bridge, type);
}
state.add(TYPE_THIS, self);
}
private void update(State state, Object object, Type type) {
List properties = type.getProperties();
for(Property prop : properties) {
String name = prop.getName();
if(!name.equals(TYPE_THIS)) {
Object current = state.get(name);
if(current == null) {
Value value = new PropertyValue(prop, object, name);
state.add(name, value);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy