protected void generatePackageDecl(String subPackageName, PrintWriter out) { String topPackageName = getPackageName(); if ((topPackageName.length() + subPackageName.length()) > 0) { printWords(out, "package"); printWords(out, topPackageName); if ((topPackageName.length() > 0) && (subPackageName.length() > 0)) { print(out, "."); } print(out, subPackageName); print(out, ";"); newline(out); newline(out); } }
protected void generatePublicClassConstructors(String className, PrintWriter out) { newline(out); printConstructor(out, "public", className); startMethodBody(out); print(out, "super();"); endMethodBody(out); }
printMethod(out, methodModifiers, typeName, "get" + capitalizedSlotName, makeArg("int", "index")); startMethodBody(out); print(out, "return ("); print(out, typeName); print(out, ")"); print(out, slotAccessExpression); print(out, ".get(index);"); endMethodBody(out); makeArg("int", "index2")); startMethodBody(out); print(out, getCollectionTypeFor(role)); print(out, " collection = "); print(out, slotAccessExpression); println(out, ";"); print(out, getTypeFullName(role.getType())); println(out, " el1 = collection.get(index1);"); println(out, "collection.set(index1, collection.get(index2));"); print(out, "collection.set(index2, el1);"); endMethodBody(out);
protected void generateStaticRoleSlots(Role role, PrintWriter out) { onNewline(out); Role otherRole = role.getOtherRole(); // The Role slot String roleType = getRoleType(role); printWords(out, "public", "final", "static", roleType, getRoleHandlerName(role, false), "=", "new", roleType); print(out, "("); print(out, getRoleArgs(role)); print(out, ")"); newBlock(out); boolean multOne = (role.getMultiplicityUpper() == 1); if (multOne) { generateStaticRoleSlotsMultOne(role, otherRole, out); } else { generateStaticRoleSlotsMultStar(role, otherRole, out); } generateRoleMethodGetInverseRole(role, otherRole, out); closeBlock(out, false); println(out, ";"); }
protected void generateRoleMethodGetInverseRole(Role role, Role otherRole, PrintWriter out) { // the getInverseRole method String inverseRoleType = makeGenericType("pt.ist.fenixframework.dml.runtime.Role", getTypeFullName(role.getType()), getTypeFullName(otherRole.getType())); printMethod(out, "public", inverseRoleType, "getInverseRole"); startMethodBody(out); print(out, "return "); if (otherRole.getName() == null) { print(out, "new "); print(out, getRoleType(otherRole)); print(out, "(this)"); } else { print(out, getRoleHandlerName(otherRole, true)); } print(out, ";"); endMethodBody(out); }
protected void generateSlot(Slot slot, PrintWriter out) { onNewline(out); printWords(out, "private", slot.getTypeName(), slot.getName()); print(out, ";"); }
protected void generateInitInstanceNoArg(DomainClass domClass, PrintWriter out) { onNewline(out); newline(out); printMethod(out, "private", "void", "initInstance"); startMethodBody(out); print(out, "init$Instance(true);"); endMethodBody(out); }
public void printUnsupported(PrintWriter out) { print(out, "throw new UnsupportedOperationException(\"Not implemented in default code generator\");"); }
protected void generateBaseClassConstructorsBody(DomainClass domClass, PrintWriter out) { print(out, "super();"); }
protected void generateRelationGetterBody(Role role, PrintWriter out) { print(out, "return "); print(out, "new "); print(out, getRelationAwareTypeFor(role)); print(out, "(("); print(out, getTypeFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, getRelationMethodNameFor(role)); print(out, ", "); print(out, role.getName()); print(out, ", "); print(out, "keyFunction$$"); print(out, role.getName()); print(out, ");"); }
protected void generateRelationAddMethodCall(Role role, String otherArg, String indexParam, PrintWriter out) { print(out, getRelationMethodNameFor(role, true)); print(out, ".add("); if (role.isDirect()) { print(out, "("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, otherArg); } else { print(out, otherArg); print(out, ", ("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this"); } print(out, ");"); }
protected void generateRelationRemoveMethodCall(Role role, String otherArg, PrintWriter out) { print(out, getRelationMethodNameFor(role, true)); print(out, ".remove("); if (role.isDirect()) { print(out, "("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this, "); print(out, otherArg); } else { print(out, otherArg); print(out, ", ("); print(out, getEntityFullName(role.getOtherRole().getType())); print(out, ")this"); } print(out, ");"); }
protected void println(PrintWriter out, String text) { print(out, text); newline(out); }
protected void generateStaticRoleSlotsMultStar(Role role, Role otherRole, PrintWriter out) { print(out, "public "); print(out, makeGenericType("pt.ist.fenixframework.dml.runtime.RelationBaseSet", getTypeFullName(role.getType()))); print(out, " "); print(out, "getSet("); print(out, getTypeFullName(otherRole.getType())); print(out, " o1)"); startMethodBody(out); print(out, "return (" + getConcreteSetTypeDeclarationFor(role) + ") (("); print(out, otherRole.getType().getBaseName()); print(out, ") o1)."); print(out, role.getName()); print(out, ";"); endMethodBody(out); }
protected void closeBlock(PrintWriter out, boolean withNewLine) { indentLess(); newline(out); print(out, "}"); if (withNewLine) { newline(out); } }