* @param bl The list of variable bindings.
* @param retType The type of that expression.
* @return the converted node.
*/
private Node convertToLet(Node n, List<LetBinding> bl, Object retType) {
Node block = null;
if ("Block".equals(n.getName())) {
block = GNode.create("Block", n);
} else {
// fix cast here
if (mapper.hasTypeVariables(retType)) {
block = GNode.create("Block", factory.ret(n));
} else {
block = GNode.create("Block", factory.ret(factory.cast(n)));
}
}
Node letclass = GNode.create("ClassBody");
letclass = GNode.ensureVariable((GNode)letclass);
GNode letbody = GNode.create("Block");
for (LetBinding bind : bl) {
if (!bind.name.equals(spareVar)) {
letclass.add(makeVarDec2(bind.name, bind.type , null));
}
if (mapper.hasTypeVariables(bind.typeObject)) {
letbody.add(factory.assign(toIdentifier(bind.name), bind.value));
} else {
letbody.add(factory.assign(toIdentifier(bind.name),
factory.cast(bind.value)));
}
}
if (letbody.size() > 0) {
letclass.add(letbody);
}
letclass.add(GNode.create("MethodDeclaration",
toModifiers("public"),null, mapper.toTypeNode(retType, false),
"apply", GNode.create("FormalParameters"), null, null, block));
Node let = factory.letExpression(mapper.toTypeNode(retType, false));
let.getGeneric(0).set(4, letclass);
return let;
}