Skip to content

Commit

Permalink
Improve client tool constant generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmibharambe authored Oct 8, 2023
1 parent 891158d commit da01339
Showing 1 changed file with 8 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,41 +304,14 @@ private static VariableDeclarationNode getInputDeclarationStatement(Method metho
method.getInputType() + " ")),
getCaptureBindingPatternNode(getRequestName(method.getMethodName())));
ExpressionNode node = null;
switch (method.getInputType()) {
case "int":
case "float":
case "decimal":
node = getNumericLiteralNode(1);
break;
case "boolean":
node = getBooleanLiteralNode(true);
break;
case "string":
node = getStringLiteralNode("ballerina");
break;
case "byte[]":
node = getByteArrayLiteralNode("[72,101,108,108,111]");
break;
case "time:Utc":
node = getTupleLiteralNode("[1659688553,0.310073000d]");
break;
case "time:Seconds":
node = getDecimalLiteralNode("0.310073000d");
break;
case "map<anydata>":
node = createBasicLiteralNode(SyntaxKind.MAP_TYPE_DESC, "{message: \"Hello Ballerina\"}");
break;
case "'any:Any":
node = getCheckExpressionNode(getFunctionCallExpressionNode("'any", "pack", "\"ballerina\""));
break;
default:
if (msgMap.containsKey(method.getInputType())) {
Message msg = msgMap.get(method.getInputType());
node = NodeFactory.createMappingConstructorExpressionNode(
SyntaxTreeConstants.SYNTAX_TREE_OPEN_BRACE,
NodeFactory.createSeparatedNodeList(getFieldNodes(msg, msgMap)),
SyntaxTreeConstants.SYNTAX_TREE_CLOSE_BRACE);
}
if(INPUT_TYPE_EXPR_NODES.containsKey(method.getInputType())) {
node = INPUT_TYPE_EXPR_NODES.get(method.getInputType());
} else if (msgMap.containsKey(method.getInputType())) {
Message msg = msgMap.get(method.getInputType());
node = NodeFactory.createMappingConstructorExpressionNode(
SyntaxTreeConstants.SYNTAX_TREE_OPEN_BRACE,
NodeFactory.createSeparatedNodeList(getFieldNodes(msg, msgMap)),
SyntaxTreeConstants.SYNTAX_TREE_CLOSE_BRACE);
}
VariableDeclaration valueVariable = new VariableDeclaration(bindingPatternNode, node);
return valueVariable.getVariableDeclarationNode();
Expand Down

0 comments on commit da01339

Please sign in to comment.