/**
* Useful type functionality
*/
public class TypeDeclUtils {
public static Environment getTypeEquivalentEnvironment(Environment src) {
Environment tev = Environment.getEmptyEnvironment();
for (Binding b : src.getBindings()) {
// System.out.println("Processing: " + b + " which class is " + b.getClass());
if (b instanceof AssignableNameBinding) {
//Indicates that there is a settable value
String name = b.getName();
Type type = b.getType();
tev = tev.extend(
new NameBindingImpl("set" + name.substring(0,1).toUpperCase() + name.substring(1),
new Arrow(type, Unit.getInstance())));
continue;
}
if (b instanceof TypeBinding) {
if (b.getType() instanceof TypeType) {
tev = tev.extend(b);
continue;
}
if (b.getType() instanceof ClassType) {
TypeType tt = ((ClassType) b.getType()).getEquivType();
tev = tev.extend(new NameBindingImpl(b.getName(), tt));
continue;
}
continue;
}
if (!(b instanceof NameBinding))
continue;
if (b.getType() instanceof Arrow) {
tev = tev.extend(b);
continue;
}
if (b.getType() instanceof TypeType) {
tev = tev.extend(b);
continue;
}
// System.out.println("Assume it is a getter even if it is wrong! :-)");