diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index 090c121..e4ab063 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -41,6 +41,7 @@ String name = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() + rn.getIdentifierTemplate().getResourceName().substring(1); String consstr = "new " + name + "("; + TypeDeclaration type = new TypeDeclaration(name); for (Edge e : rn.getOutEdges()) { ResourceDependency re = (ResourceDependency) e; String rename = ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName() @@ -59,6 +60,11 @@ if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { consstr += rename.toLowerCase() + ","; f = true; + } else { + if (rn.getIndegree() > 1) + type.addField(new FieldDeclaration( + ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(), + rename)); } } if (f) @@ -66,7 +72,6 @@ consstr += ")"; FieldDeclaration field = new FieldDeclaration(new Type(name, name), rn.getIdentifierTemplate().getResourceName(), consstr); - TypeDeclaration type = new TypeDeclaration(name); codes.get(0).addField(field); MethodDeclaration cons = new MethodDeclaration(name, true); Block block = new Block(); @@ -85,8 +90,6 @@ } } block = new Block(); - ArrayList vars = new ArrayList<>(); - boolean flag = false; for (Edge e : rn.getInEdges()) { ResourceDependency re = (ResourceDependency) e; String rename = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName() @@ -100,30 +103,31 @@ block.addStatement("this." + rename.toLowerCase() + " = " + rename.toLowerCase() + ";"); cons.setBody(block); } else { + ArrayList vars = new ArrayList<>(); vars.add(new VariableDeclaration( ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(), ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceName())); - flag = true; + type.addMethod(new MethodDeclaration("update" + rename, false, typeVoid, vars)); } } - type.addMethod(cons); + if (cons.getParameters() != null) + type.addMethod(cons); for (ChannelGenerator cg : model.getIOChannelGenerators()) { for (ChannelMember cm : cg.getChannelMembers()) { if (cm.getIdentifierTemplate().getResourceName().equals(type.getTypeName().toLowerCase())) { if (cm.getStateTransition().getMessageExpression().getClass() == Term.class) { ArrayList params = new ArrayList<>(); - params.add(new VariableDeclaration(cm.getIdentifierTemplate().getResourceStateType(),cm.getIdentifierTemplate().getResourceName())); + params.add(new VariableDeclaration(cm.getIdentifierTemplate().getResourceStateType(), + cm.getIdentifierTemplate().getResourceName())); MethodDeclaration io = new MethodDeclaration( - ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(),false, - typeVoid,params); + ((Term) cm.getStateTransition().getMessageExpression()).getSymbol().getImplName(), + false, typeVoid, params); type.addMethod(io); codes.get(0).addMethod(io); } } } } - if (flag) - type.addMethod(new MethodDeclaration("update", false, typeVoid, vars)); if (((StoreAttribute) rn.getAttribute()).isStored()) { String str = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() + "()";