diff --git a/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java b/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java index fad7629..5f5aafc 100644 --- a/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java +++ b/AlgebraicDataflowArchitectureModel/src/code/ast/MethodDeclaration.java @@ -109,6 +109,10 @@ } thrws.addException(exception); } + + public Throws getThrows() { + return thrws; + } @Override public Annotation getAnnotation(String name) { diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index cb60a92..e2bb32d 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -245,7 +245,16 @@ jsonMember.addChild(new Constant("\"" + var.getName() + "\"")); Expression param = jsonMember.reduce(); if (param != null) { - params.add(param.toImplementation(new String[] {""})); + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } + } + params.add(param.toImplementation(null)); } else { params.add(var.getName()); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index 3913217..f4e9710 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -834,7 +834,16 @@ jsonMember.addChild(new Constant("\"" + var.getName() + "\"")); Expression param = jsonMember.reduce(); if (param != null) { - constructorInvocation = constructorInvocation + delimiter + param.toImplementation(new String[] {""}); + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } + } + constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); } else { constructorInvocation = constructorInvocation + delimiter + var.getName(); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index bf351c6..35e6717 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -496,21 +496,13 @@ callParams += delimiter + paramEnt.getValue().getValue(); delimiter = ", "; } - if (!chainedCalls.contains(srcUpdate)) { - // The first call to an update method in this method - if (srcComponent != dstComponent) { - srcUpdate.addStatement("String result = this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); - } else { - srcUpdate.addStatement("String result = this." + updateMethodName + "(" + callParams + ");"); - } - chainedCalls.add(srcUpdate); + if (srcComponent != dstComponent) { + srcUpdate.addStatement("this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); } else { - // After the second time of call to update methods in this method - if (srcComponent != dstComponent) { - srcUpdate.addStatement("result = this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); - } else { - srcUpdate.addStatement("result = this." + updateMethodName + "(" + callParams + ");"); - } + srcUpdate.addStatement("this." + updateMethodName + "(" + callParams + ");"); + } + if (update != null && update.getThrows() != null && update.getThrows().getExceptions().contains("JsonProcessingException")) { + srcUpdate.addThrow("JsonProcessingException"); } } } @@ -619,21 +611,13 @@ callParams += delimiter + paramEnt.getValue().getValue(); delimiter = ", "; } - if (!chainedCalls.contains(srcInput)) { - // The first call to an update method in this method - if (srcComponent != dstComponent) { - srcInput.addStatement("String result = this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); - } else { - srcInput.addStatement("String result = this." + updateMethodName + "(" + callParams + ");"); - } - chainedCalls.add(srcInput); + if (srcComponent != dstComponent) { + srcInput.addStatement("this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); } else { - // After the second time of call to update methods in this method - if (srcComponent != dstComponent) { - srcInput.addStatement("result = this." + JerseyCodeGenerator.toVariableName(dstResourceName) + "." + updateMethodName + "(" + callParams + ");"); - } else { - srcInput.addStatement("result = this." + updateMethodName + "(" + callParams + ");"); - } + srcInput.addStatement("this." + updateMethodName + "(" + callParams + ");"); + } + if (update != null && update.getThrows() != null && update.getThrows().getExceptions().contains("JsonProcessingException")) { + srcInput.addThrow("JsonProcessingException"); } } } @@ -946,6 +930,9 @@ } } inputAccessor.addStatement(resourceAccess + "." + input.getName() + "(" + args + ");"); + if (input != null && input.getThrows() != null && input.getThrows().getExceptions().contains("JsonProcessingException")) { + inputAccessor.addThrow("JsonProcessingException"); + } } } } @@ -975,7 +962,16 @@ jsonMember.addChild(new Constant("\"" + var.getName() + "\"")); Expression param = jsonMember.reduce(); if (param != null) { - constructorInvocation = constructorInvocation + delimiter + param.toImplementation(new String[] {""}); + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } + } + constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); } else { constructorInvocation = constructorInvocation + delimiter + var.getName(); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 5890932..e1e4e98 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -55,7 +55,6 @@ public String generate(Type type, String[] children, String[] childrenSideEffects, String[] sideEffect) { String compType = ""; if (type != null) { - String temp = "temp_nil"; String interfaceType = type.getInterfaceTypeName(); if (interfaceType.contains("<")) { compType = interfaceType.substring(interfaceType.indexOf("<") + 1, interfaceType.lastIndexOf(">")); @@ -64,8 +63,13 @@ if (implType.indexOf('<') >= 0) { implType = implType.substring(0, implType.indexOf('<')); } - sideEffect[0] = interfaceType + " " + temp + " = " + "new " + implType + "<" + compType + ">();\n"; - return temp; + if (sideEffect == null) { + return "new " + implType + "<>()"; + } else { + String temp = "temp_nil"; + sideEffect[0] = interfaceType + " " + temp + " = " + "new " + implType + "<" + compType + ">();\n"; + return temp; + } } return "new ArrayList<" + compType + ">()"; }