diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java index fbdc6dc..d6bea99 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java @@ -68,6 +68,12 @@ CompilationUnit mainCU = new CompilationUnit(mainType); mainCU.addImport(new ImportDeclaration("java.util.*")); codes.add(mainCU); + + // Declare the constructor of the main type. + MethodDeclaration mainConstructor = new MethodDeclaration(mainTypeName, true); + mainType.addMethod(mainConstructor); + + // For each resource. for (ResourceNode rn: resources) { boolean f = false; String resourceName = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() @@ -121,8 +127,14 @@ fieldInitializer = fieldInitializer.substring(0, fieldInitializer.length() - 1); fieldInitializer += ")"; FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), - rn.getIdentifierTemplate().getResourceName(), fieldInitializer); + rn.getIdentifierTemplate().getResourceName()); mainType.addField(field); + Block manConstructorBody = mainConstructor.getBody(); + if (manConstructorBody == null) { + manConstructorBody = new Block(); + mainConstructor.setBody(manConstructorBody); + } + manConstructorBody.addStatement(rn.getIdentifierTemplate().getResourceName() + " = " + fieldInitializer + ";"); // Declare a constructor, fields and update methods in the type of each resource. MethodDeclaration constructor = new MethodDeclaration(resourceName, true);