diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index a50bc46..daf30a2 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -46,18 +46,21 @@ ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); type.addConstructors(new VariableDeclaration(new Type(rename, rename), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); - }else { - vars.add(new VariableDeclaration(DataConstraintModel.typeInt, + } else { + vars.add(new VariableDeclaration( + ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); flag = true; } } - if(flag) type.addMethod(new MethodDeclaration("update", false, new Type("Void", "void"), vars)); + if (flag) + type.addMethod(new MethodDeclaration("update", false, new Type("Void", "void"), vars)); if (((StoreAttribute) rn.getAttribute()).isStored()) { - type.addField(new FieldDeclaration(DataConstraintModel.typeInt, + type.addField(new FieldDeclaration(rn.getIdentifierTemplate().getResourceStateType(), rn.getIdentifierTemplate().getResourceName())); } - type.addMethod(new MethodDeclaration("get" + type.getTypeName(),DataConstraintModel.typeInt)); + type.addMethod(new MethodDeclaration("get" + type.getTypeName(), + rn.getIdentifierTemplate().getResourceStateType())); codes.add(type); } return codes; @@ -90,22 +93,24 @@ } codes.add(""); if (type.getTypeName() != "Main") { - String cons = "\t" + "public " + type.getTypeName() + "("; - for (VariableDeclaration constructor : type.getConstructors()) { - cons += constructor.getType().getTypeName() + " " + constructor.getName() + ","; - } - 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())) { - codes.add("\t\t" + "this." + field.getName() + " = " + field.getName() + ";"); + if (!type.getConstructors().isEmpty()) { + String cons = "\t" + "public " + type.getTypeName() + "("; + for (VariableDeclaration constructor : type.getConstructors()) { + cons += constructor.getType().getTypeName() + " " + constructor.getName() + ","; + } + 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())) { + codes.add("\t\t" + "this." + field.getName() + " = " + field.getName() + ";"); + } } } + codes.add("\t" + "}"); } - codes.add("\t" + "}"); } codes.add(""); for (MethodDeclaration method : type.getMethods()) { @@ -115,7 +120,8 @@ for (VariableDeclaration var : method.getParameters()) { varstr += var.getType().getImplementationTypeName() + " " + var.getName() + ","; } - if (!method.getParameters().isEmpty()) varstr = varstr.substring(0, varstr.length() - 1); + if (!method.getParameters().isEmpty()) + varstr = varstr.substring(0, varstr.length() - 1); } codes.add(varstr + ")" + "{"); codes.add("\t" + "}");