diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java index 1f86cc0..5166228 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java @@ -64,7 +64,7 @@ if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { if (pushPull.getOptions().get(0) == PushPullValue.PUSH) { // for push data transfer - MethodDeclaration update = getUpdateMethod(dstType); + MethodDeclaration update = getUpdateMethod(dstType, srcType); Expression updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pushAccessor); String curState = updateExp.toImplementation(); String updateStatement; @@ -81,10 +81,11 @@ getter.addStatement("return " + dstResourceName + ";"); } // src side (for a chain of update method invocations) - MethodDeclaration srcUpdate = getUpdateMethod(srcType); - if (srcUpdate != null) srcUpdate.addStatement(dstResourceName + ".update(" + srcResourceName + ");"); + for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { + srcUpdate.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(" + srcResourceName + ");"); + } MethodDeclaration srcInput = getInputMethod(srcType, src, model); - if (srcInput != null) srcInput.addStatement(dstResourceName + ".update(" + srcResourceName + ");"); + if (srcInput != null) srcInput.addStatement(dstResourceName + ".update" + srcType.getTypeName() + "(" + srcResourceName + ");"); } else { // for pull (or push/pull) data transfer MethodDeclaration getter = getGetterMethod(dstType); @@ -113,10 +114,6 @@ input.addFirstStatement("this." + resourceName + " = " + resourceName + ";"); if (mainType != null) { MethodDeclaration mainInput = getMethod(mainType, input.getName()); - if (mainInput == null) { - // to be removed later - mainInput = getMethod(mainType, "input"); - } if (mainInput != null) { mainInput.addStatement("this." + resourceName + "." + input.getName() + "(" + resourceName + ");"); } @@ -133,13 +130,23 @@ return types; } - private static MethodDeclaration getUpdateMethod(TypeDeclaration type) { + private static MethodDeclaration getUpdateMethod(TypeDeclaration type, TypeDeclaration from) { for (MethodDeclaration m: type.getMethods()) { - if (m.getName().startsWith("update")) return m; + if (m.getName().equals("update" + from.getTypeName())) return m; } return null; } + private static ArrayList getUpdateMethods(TypeDeclaration type) { + ArrayList updates = new ArrayList<>(); + for (MethodDeclaration m: type.getMethods()) { + if (m.getName().startsWith("update")) { + updates.add(m); + } + } + return updates; + } + private static MethodDeclaration getGetterMethod(TypeDeclaration type) { for (MethodDeclaration m: type.getMethods()) { if (m.getName().startsWith("get")) return m;