diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java index 31e7fa2..e37166e 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java @@ -76,8 +76,7 @@ // For each resource. for (ResourceNode rn: resources) { boolean f = false; - String resourceName = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() - + rn.getIdentifierTemplate().getResourceName().substring(1); + String resourceName = getTypeName(rn.getIdentifierTemplate().getResourceName()); TypeDeclaration type = new TypeDeclaration(resourceName); // Declare the field to refer to each resource in the main type. @@ -86,20 +85,22 @@ for (Edge e : rn.getOutEdges()) { ResourceDependency re = (ResourceDependency) e; IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); - String resName = dstRes.getResourceName().substring(0, 1).toUpperCase() + dstRes.getResourceName().substring(1); + String resName = dstRes.getResourceName(); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { + // for push data transfer depends.add(dstRes); - fieldInitializer += resName.toLowerCase() + ","; + fieldInitializer += resName + ","; f = true; } } for (Edge e : rn.getInEdges()) { ResourceDependency re = (ResourceDependency) e; IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); - String resName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); + String resName = srcRes.getResourceName(); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { + // for pull data transfer depends.add(srcRes); - fieldInitializer += resName.toLowerCase() + ","; + fieldInitializer += resName + ","; f = true; } else { if (rn.getIndegree() > 1) { @@ -118,22 +119,23 @@ if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); - fieldInitializer += refResName.toLowerCase() + ","; + fieldInitializer += refResName + ","; f = true; } } } } + // declare and initialize the filed to refer to a resource. if (f) fieldInitializer = fieldInitializer.substring(0, fieldInitializer.length() - 1); fieldInitializer += ")"; FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), rn.getIdentifierTemplate().getResourceName()); mainType.addField(field); - Block manConstructorBody = mainConstructor.getBody(); - if (manConstructorBody == null) { - manConstructorBody = new Block(); - mainConstructor.setBody(manConstructorBody); + Block mainConstructorBody = mainConstructor.getBody(); + if (mainConstructorBody == null) { + mainConstructorBody = new Block(); + mainConstructor.setBody(mainConstructorBody); } - manConstructorBody.addStatement(rn.getIdentifierTemplate().getResourceName() + " = " + fieldInitializer + ";"); + mainConstructorBody.addStatement(rn.getIdentifierTemplate().getResourceName() + " = " + fieldInitializer + ";"); // Declare a constructor, fields and update methods in the type of each resource. MethodDeclaration constructor = new MethodDeclaration(resourceName, true); @@ -142,25 +144,25 @@ for (Edge e : rn.getOutEdges()) { ResourceDependency re = (ResourceDependency) e; IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); - String dstResName = dstRes.getResourceName().substring(0, 1).toUpperCase() + dstRes.getResourceName().substring(1); + String dstResName = getTypeName(dstRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // Declare a field to refer to the destination resource of push transfer. depends.add(dstRes); type.addField(new FieldDeclaration(new Type(dstResName, dstResName), dstRes.getResourceName())); constructor.addParameter(new VariableDeclaration(new Type(dstResName, dstResName), dstRes.getResourceName())); - block.addStatement("this." + dstResName.toLowerCase() + " = " + dstResName.toLowerCase() + ";"); + block.addStatement("this." + dstRes.getResourceName() + " = " + dstRes.getResourceName() + ";"); } } for (Edge e : rn.getInEdges()) { ResourceDependency re = (ResourceDependency) e; IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); - String srcResName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); + String srcResName = getTypeName(srcRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { // Declare a field to refer to the source resource of pull transfer. depends.add(srcRes); type.addField(new FieldDeclaration(new Type(srcResName, srcResName), srcRes.getResourceName())); constructor.addParameter(new VariableDeclaration(new Type(srcResName, srcResName), srcRes.getResourceName())); - block.addStatement("this." + srcResName.toLowerCase() + " = " + srcResName.toLowerCase() + ";"); + block.addStatement("this." + srcRes.getResourceName() + " = " + srcRes.getResourceName() + ";"); } else { // Declare an update method in the type of the destination resource. ArrayList vars = new ArrayList<>(); @@ -183,7 +185,7 @@ if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); - refResName = refResName.substring(0, 1).toUpperCase() + refResName.substring(1); + refResName = getTypeName(refResName); type.addField(new FieldDeclaration(new Type(refResName, refResName), id.getResourceName())); constructor.addParameter(new VariableDeclaration(new Type(refResName, refResName), id.getResourceName())); block.addStatement("this." + id.getResourceName() + " = " + id.getResourceName() + ";"); @@ -324,6 +326,10 @@ return codes; } + public static String getTypeName(String resourceName) { + return resourceName.substring(0, 1).toUpperCase() + resourceName.substring(1); + } + private static String getInitializer(IdentifierTemplate resId) { Type stateType = resId.getResourceStateType(); String initializer = null;