/** * Generates the relation field over the model sigs for called relations Must be run before the * relation constraint is created (otherwise recursive calls will fail) * * @return the Alloy field for this relation * @throws EchoError * @todo Support for n models */ private Field addRelationFields() throws EchoError { Field field = null; Decl fst = rootvar2alloydecl.get(relation.getDomains().get(0).getRootVariable().getName()); /*Decl snd = rootvar2alloydecl.get(relation.getDomains().get(1) .getVariable().getName());*/ try { Sig s = (Sig) fst.expr.type().toExpr(); for (Field f : s.getFields()) { if (f.label.equals(AlloyUtil.relationFieldName(relation, dependency.target))) field = f; } if (field == null) { field = s.addField( AlloyUtil.relationFieldName(relation, dependency.target), /*type.setOf()*/ Sig.UNIV.setOf()); } } catch (Err a) { throw new ErrorAlloy( ErrorAlloy.FAIL_CREATE_FIELD, "Failed to create relation field representation: " + relation.getName(), a, Task.TRANSLATE_TRANSFORMATION); } return field; }