diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 193647a..85c9ad1 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -313,7 +313,7 @@ if (node instanceof StatefulObjectNode) { // Add data-flow attributes to the path to node. ResourceNode resNode = ((StatefulObjectNode) node).getResource(); - if (resNode.getOutdegree() > 0) { + for (Edge outE: resNode.getOutEdges()) { // If resNode is the source of data-flow. for (Edge e: path) { // Add pull attributes to the path to resNode. @@ -327,9 +327,7 @@ pullSrcs = new ArrayList<>(); edgeAttributes.put(PushPullValue.PULL, pullSrcs); } - if (!pullSrcs.contains(resNode)) { - pullSrcs.add(resNode); - } + pullSrcs.add(resNode); } } for (Edge inE: resNode.getInEdges()) { @@ -347,9 +345,7 @@ pushSrcs = new ArrayList<>(); edgeAttributes.put(PushPullValue.PUSH, pushSrcs); } - if (!pushSrcs.contains(srcOfDataFlowNode)) { - pushSrcs.add(srcOfDataFlowNode); - } + pushSrcs.add(srcOfDataFlowNode); } } } @@ -369,8 +365,12 @@ List pullFlows = dataFlowInform.get(e).get(PushPullValue.PULL); if (pushFlows == null || pullFlows == null) return; List pushFlowsOrg = new ArrayList<>(pushFlows); - pushFlows.removeAll(pullFlows); - pullFlows.removeAll(pushFlowsOrg); + for (ResourceNode r: pullFlows) { + pushFlows.remove(r); + } + for (ResourceNode r: pushFlowsOrg) { + pullFlows.remove(r); + } dataFlowInform.get(e).put(PushPullValue.PUSH, pushFlows); dataFlowInform.get(e).put(PushPullValue.PULL, pullFlows); removeRedundantAttributes(e.getDestination(), dataFlowInform); @@ -515,11 +515,18 @@ private static MethodDeclaration declareAndFillUpdateAndInputMethods(Node node, Edge inEdge, Node prevResNode, Map>> dataFlowInform, Map componentMap, ILanguageSpecific langSpec) { TypeDeclaration component = componentMap.get(node); + List resourcesToReturn = null; + List resourcesToReceive = null; + if (dataFlowInform.get(inEdge) != null) { + resourcesToReturn = dataFlowInform.get(inEdge).get(PushPullValue.PULL); + resourcesToReceive = dataFlowInform.get(inEdge).get(PushPullValue.PUSH); + } if (node instanceof StatefulObjectNode) { // Declare update or input method in the resource component. ResourceNode resourceNode = ((StatefulObjectNode) node).getResource(); MethodDeclaration updateOrInput = null; - if (!(prevResNode instanceof EntryPointObjectNode)) { + if (!(prevResNode instanceof EntryPointObjectNode) + || (resourcesToReceive != null && resourcesToReceive.size() > 0)) { updateOrInput = getUpdateMethod(inEdge, component, dataFlowInform, langSpec); if (updateOrInput != null) return updateOrInput; // Declare an update method. @@ -563,7 +570,8 @@ List updateMethods = getUpdateMethods(component); if (updateMethods.size() > 0) return updateMethods.get(0); MethodDeclaration updateOrInput = null; - if (!(prevResNode instanceof EntryPointObjectNode)) { + if (!(prevResNode instanceof EntryPointObjectNode) + || (resourcesToReceive != null && resourcesToReceive.size() > 0)) { // Declare an update method. updateOrInput = declareUpdateMethod(node, inEdge, component, dataFlowInform, langSpec); component.addMethod(updateOrInput);