diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index 39b40dc..24fa338 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -30,7 +30,8 @@ if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { type.addField(new FieldDeclaration(new Type(rename, rename), ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName())); - type.addConstructors(new VariableDeclaration(new Type(rename, rename),((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); + type.addConstructors(new VariableDeclaration(new Type(rename, rename), + ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName())); } } for (Edge e : rn.getInEdges()) { @@ -41,7 +42,8 @@ if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { type.addField(new FieldDeclaration(new Type(rename, rename), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); - type.addConstructors(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()) @@ -57,14 +59,21 @@ for (TypeDeclaration type : codeTree) { codes.add("public class " + type.getTypeName() + "{"); for (FieldDeclaration field : type.getFields()) { - if(type.getTypeName() != "Main") { - codes.add("\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName() + ";"); - }else { - String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName() + " = new " + field.getType().getTypeName() + "("; - for(VariableDeclaration constructor:type.getConstructors()) { - cons += constructor.getName() + ","; + if (type.getTypeName() != "Main") { + codes.add("\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName() + + ";"); + } else { + String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " + + field.getName() + " = new " + field.getType().getTypeName() + "("; + for (TypeDeclaration tree:codeTree) { + if(field.getType().getTypeName() == tree.getTypeName()) { + for(VariableDeclaration var:tree.getConstructors()) { + cons += var.getType().getTypeName() + " " + var.getName() + ","; + } + if(!tree.getConstructors().isEmpty()) cons = cons.substring(0, cons.length() - 1); + break; + } } - if(!type.getConstructors().isEmpty()) cons = cons.substring(0, cons.length() - 1); cons += ");"; codes.add(cons); } @@ -72,15 +81,16 @@ codes.add(""); if (type.getTypeName() != "Main") { String cons = "\t" + "public " + type.getTypeName() + "("; - for(VariableDeclaration constructor:type.getConstructors()) { + for (VariableDeclaration constructor : type.getConstructors()) { cons += constructor.getType().getTypeName() + " " + constructor.getName() + ","; } - if(!type.getConstructors().isEmpty()) 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()) { - for(VariableDeclaration vari:type.getConstructors()) { - if(field.getType().getTypeName().equals(vari.getType().getTypeName())) { + for (VariableDeclaration vari : type.getConstructors()) { + if (field.getType().getTypeName().equals(vari.getType().getTypeName())) { codes.add("\t\t" + "this." + field.getName() + " = " + field.getName()); } }