diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index 802aeff..39b40dc 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -30,7 +30,7 @@ if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { type.addField(new FieldDeclaration(new Type(rename, rename), ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName())); - type.addConstructor(new VariableDeclaration(new Type(rename, rename),((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); + type.addConstructors(new VariableDeclaration(new Type(rename, rename),((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); } } for (Edge e : rn.getInEdges()) { @@ -41,7 +41,7 @@ if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { type.addField(new FieldDeclaration(new Type(rename, rename), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); - type.addConstructor(new VariableDeclaration(new Type(rename, rename),((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); + type.addConstructors(new VariableDeclaration(new Type(rename, rename),((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); } } if (((StoreAttribute) rn.getAttribute()).isStored()) @@ -58,22 +58,32 @@ codes.add("public class " + type.getTypeName() + "{"); for (FieldDeclaration field : type.getFields()) { if(type.getTypeName() != "Main") { - codes.add("\t" + field.getType().getImplementationTypeName() + " " + field.getName() + " = null;"); + codes.add("\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName() + ";"); }else { - codes.add("\t" + field.getType().getImplementationTypeName() + " " + field.getName() + " = new " + field.getType().getTypeName() + "(" + ");"); + String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName() + " = new " + field.getType().getTypeName() + "("; + for(VariableDeclaration constructor:type.getConstructors()) { + cons += constructor.getName() + ","; + } + if(!type.getConstructors().isEmpty()) cons = cons.substring(0, cons.length() - 1); + cons += ");"; + codes.add(cons); } } codes.add(""); if (type.getTypeName() != "Main") { - String cons = "\t" + type.getTypeName() + "("; - for(VariableDeclaration constructor:type.getConstructor()) { + String cons = "\t" + "public " + type.getTypeName() + "("; + for(VariableDeclaration constructor:type.getConstructors()) { cons += constructor.getType().getTypeName() + " " + constructor.getName() + ","; } - cons = cons.substring(0, cons.length() - 1); + if(!type.getConstructors().isEmpty()) cons = cons.substring(0, cons.length() - 1); cons += ");"; codes.add(cons); for (FieldDeclaration field : type.getFields()) { - if(type.getTypeName().toLowerCase() != field.getName()) codes.add("\t\t" + "this." + field.getName() + " = " + field.getName()); + for(VariableDeclaration vari:type.getConstructors()) { + if(field.getType().getTypeName().equals(vari.getType().getTypeName())) { + codes.add("\t\t" + "this." + field.getName() + " = " + field.getName()); + } + } } codes.add("\t" + "}"); } @@ -87,6 +97,7 @@ codes.add(""); } codes.add("}"); + codes.add(""); } return codes; }