| |
---|
| | import models.algebra.Type; |
---|
| | import models.algebra.UnificationFailed; |
---|
| | import models.algebra.ValueUndefined; |
---|
| | import models.algebra.Variable; |
---|
| | import models.controlFlowModel.CallEdge; |
---|
| | import models.controlFlowModel.ControlFlowGraph; |
---|
| | import models.controlFlowModel.EntryPointObjectNode; |
---|
| | import models.controlFlowModel.ObjectNode; |
---|
| | import models.controlFlowModel.StatefulObjectNode; |
---|
| |
---|
| | Node dstNode = outEdge.getDestination(); |
---|
| | MethodDeclaration calleeMethod = declareAndFillUpdateAndInputMethods(dstNode, outEdge, node, dataFlowInform, componentMap, langSpec); |
---|
| | if (input == null) { |
---|
| | // Declare an input method. |
---|
| | input = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters())); |
---|
| | if (calleeMethod.getParameters() != null) { |
---|
| | input = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters())); |
---|
| | } else { |
---|
| | input = langSpec.newMethodDeclaration(calleeMethod.getName(), null); |
---|
| | } |
---|
| | } |
---|
| | // Add a statement to call the destination method. |
---|
| | addInvocationInMediatorUpdate(input, calleeMethod, ((ObjectNode) dstNode).getName(), dataFlowInform, langSpec); |
---|
| | } |
---|
| |
---|
| | Node dstNode = outEdge.getDestination(); |
---|
| | MethodDeclaration calleeMethod = declareAndFillUpdateAndInputMethods(dstNode, outEdge, prevResNode, dataFlowInform, componentMap, langSpec); |
---|
| | if (updateOrInput == null && prevResNode instanceof EntryPointObjectNode) { |
---|
| | // Declare an input method. |
---|
| | updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters())); |
---|
| | if (calleeMethod.getParameters() != null) { |
---|
| | updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), false, null, new ArrayList<>(calleeMethod.getParameters())); |
---|
| | } else { |
---|
| | updateOrInput = langSpec.newMethodDeclaration(calleeMethod.getName(), null); |
---|
| | } |
---|
| | component.addMethod(updateOrInput); |
---|
| | } |
---|
| | // Add a statement to call the destination method. |
---|
| | addInvocationInMediatorUpdate(updateOrInput, calleeMethod, ((ObjectNode) dstNode).getName(), dataFlowInform, langSpec); |
---|
| |
---|
| | |
---|
| | private static void addInvocationInResourceUpdate(Node node, MethodDeclaration resourceUpdateMethod, MethodDeclaration calleeMethod, String dstNodeName, ILanguageSpecific langSpec) { |
---|
| | List<String> params = new ArrayList<>(); |
---|
| | params.add(langSpec.getFieldAccessor(fieldOfResourceState)); |
---|
| | for (VariableDeclaration v: calleeMethod.getParameters()) { |
---|
| | if (!((ObjectNode) node).getName().equals(v.getName())) { |
---|
| | params.add(v.getName()); |
---|
| | if (calleeMethod.getParameters() != null) { |
---|
| | for (VariableDeclaration v: calleeMethod.getParameters()) { |
---|
| | if (!((ObjectNode) node).getName().equals(v.getName())) { |
---|
| | params.add(v.getName()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | // for (ChannelMember rc: re.getChannelGenerator().getReferenceChannelMembers()) { |
---|
| | // // to get the value of reference member. |
---|
| |
---|
| | |
---|
| | private static void addInvocationInMediatorUpdate(MethodDeclaration resourceUpdateMethod, MethodDeclaration calleeMethod, String dstNodeName, Map<Edge, Map<PushPullValue, List<ResourceNode>>> dataFlowInform, ILanguageSpecific langSpec) { |
---|
| | Map<MethodDeclaration, Set<IdentifierTemplate>> referredResources = new HashMap<>(); |
---|
| | List<String> params = new ArrayList<>(); |
---|
| | for (VariableDeclaration v: calleeMethod.getParameters()) { |
---|
| | params.add(v.getName()); |
---|
| | if (calleeMethod.getParameters() != null) { |
---|
| | for (VariableDeclaration v: calleeMethod.getParameters()) { |
---|
| | params.add(v.getName()); |
---|
| | } |
---|
| | } |
---|
| | resourceUpdateMethod.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstNodeName), |
---|
| | calleeMethod.getName(), |
---|
| | params) + langSpec.getStatementDelimiter()); // this.dst.updateSrc(value, refParams); |
---|
| |
---|
| | mainInput = langSpec.newMethodDeclaration(str, false, null, params); |
---|
| | mainComponent.addMethod(mainInput); |
---|
| | } else { |
---|
| | // Add type to a parameter without type. |
---|
| | for (VariableDeclaration param: mainInput.getParameters()) { |
---|
| | if (param.getType() == null) { |
---|
| | for (VariableDeclaration p: params) { |
---|
| | if (param.getName().equals(p.getName()) && p.getType() != null) { |
---|
| | param.setType(p.getType()); |
---|
| | if (mainInput.getParameters() != null) { |
---|
| | for (VariableDeclaration param: mainInput.getParameters()) { |
---|
| | if (param.getType() == null) { |
---|
| | for (VariableDeclaration p: params) { |
---|
| | if (param.getName().equals(p.getName()) && p.getType() != null) { |
---|
| | param.setType(p.getType()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| |
---|
| | |