Skip to content

Commit

Permalink
Introduce a new node to data mapper call function
Browse files Browse the repository at this point in the history
  • Loading branch information
KavinduZoysa committed Jan 10, 2025
1 parent 9b6794b commit f6c7034
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void setDefaultNodes() {
.node(NodeKind.VARIABLE)
.node(NodeKind.ASSIGN)
.node(function)
.node(NodeKind.DATA_MAPPER);
.node(NodeKind.DATA_MAPPER_CALL);

this.rootBuilder.stepIn(Category.Name.CONTROL)
.node(NodeKind.IF)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.ballerina.compiler.api.symbols.FunctionSymbol;
import io.ballerina.compiler.api.symbols.FunctionTypeSymbol;
import io.ballerina.compiler.api.symbols.MethodSymbol;
import io.ballerina.compiler.api.symbols.ParameterKind;
import io.ballerina.compiler.api.symbols.ParameterSymbol;
import io.ballerina.compiler.api.symbols.Symbol;
import io.ballerina.compiler.api.symbols.SymbolKind;
Expand Down Expand Up @@ -1075,7 +1074,6 @@ public void visit(FunctionCallExpressionNode functionCallExpressionNode) {

Optional<Documentation> documentation = functionSymbol.documentation();
String description = documentation.flatMap(Documentation::description).orElse("");
SeparatedNodeList<FunctionArgumentNode> arguments = functionCallExpressionNode.arguments();

String functionName = switch (nameReferenceNode.kind()) {
case QUALIFIED_NAME_REFERENCE -> ((QualifiedNameReferenceNode) nameReferenceNode).identifier().text();
Expand All @@ -1089,52 +1087,30 @@ public void visit(FunctionCallExpressionNode functionCallExpressionNode) {
startNode(NodeKind.FUNCTION_CALL, functionCallExpressionNode.parent());
}

// if (dataMappings.containsKey(functionName)) {
// startNode(NodeKind.DATA_MAPPER, functionCallExpressionNode.parent()).properties()
// .functionName(functionName)
// .output(this.typedBindingPatternNode);
// Optional<List<ParameterSymbol>> funcParams = functionSymbol.typeDescriptor().params();
// if (funcParams.isPresent()) {
// List<ParameterSymbol> params = funcParams.get().stream()
// .filter(p -> p.paramKind() != ParameterKind.INCLUDED_RECORD)
// .toList();
// nodeBuilder.properties().inputs(arguments, params);
// }
// nodeBuilder.properties().view(dataMappings.get(functionName));
// } else {
// startNode(NodeKind.FUNCTION_CALL, functionCallExpressionNode.parent());
if (CommonUtils.isDefaultPackage(functionSymbol, moduleInfo)) {
functionSymbol.getLocation()
.flatMap(location -> CommonUtil.findNode(functionSymbol,
CommonUtils.getDocument(project, location).syntaxTree()))
.ifPresent(node -> nodeBuilder.properties().view(node.lineRange()));
}
nodeBuilder
.symbolInfo(functionSymbol)
.metadata()
.label(functionName)
.description(description)
.stepOut()
.codedata()
.symbol(functionName);
if (CommonUtils.isDefaultPackage(functionSymbol, moduleInfo)) {
functionSymbol.getLocation()
.flatMap(location -> CommonUtil.findNode(functionSymbol,
CommonUtils.getDocument(project, location).syntaxTree()))
.ifPresent(node -> nodeBuilder.properties().view(node.lineRange()));
}

DatabaseManager dbManager = DatabaseManager.getInstance();
ModuleID id = functionSymbol.getModule().get().id();
Optional<FunctionResult> functionResult = dbManager.getAction(id.orgName(), id.moduleName(),
functionSymbol.getName().get(), null, DatabaseManager.FunctionKind.FUNCTION);
DatabaseManager dbManager = DatabaseManager.getInstance();
ModuleID id = functionSymbol.getModule().get().id();
Optional<FunctionResult> functionResult = dbManager.getAction(id.orgName(), id.moduleName(),
functionSymbol.getName().get(), null, DatabaseManager.FunctionKind.FUNCTION);

final Map<String, Node> namedArgValueMap = new HashMap<>();
final Queue<Node> positionalArgs = new LinkedList<>();
calculateFunctionArgs(namedArgValueMap, positionalArgs, functionCallExpressionNode.arguments());
final Map<String, Node> namedArgValueMap = new HashMap<>();
final Queue<Node> positionalArgs = new LinkedList<>();
SeparatedNodeList<FunctionArgumentNode> arguments = functionCallExpressionNode.arguments();
calculateFunctionArgs(namedArgValueMap, positionalArgs, arguments);

if (functionResult.isPresent()) { // function details are indexed
analyzeAndHandleExprArgs(functionCallExpressionNode.arguments(), dbManager, functionResult.get(),
functionSymbol, positionalArgs, namedArgValueMap);
} else {
handleFunctionCallActionCallsParams(functionCallExpressionNode.arguments(), functionSymbol);
}
handleCheckFlag(functionCallExpressionNode, SyntaxKind.CHECK_EXPRESSION, functionSymbol.typeDescriptor());
// }
if (functionResult.isPresent()) { // function details are indexed
analyzeAndHandleExprArgs(arguments, dbManager, functionResult.get(), functionSymbol, positionalArgs,
namedArgValueMap);
} else {
handleFunctionCallActionCallsParams(arguments, functionSymbol);
}
handleCheckFlag(functionCallExpressionNode, SyntaxKind.CHECK_EXPRESSION, functionSymbol.typeDescriptor());

nodeBuilder
.symbolInfo(functionSymbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com)
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com)
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
Expand All @@ -20,10 +20,18 @@

import io.ballerina.flowmodelgenerator.core.model.NodeKind;

/**
* Represents the properties of a data mapper call node.
*
* @since 2.0.0
*/
public class DataMapperCallBuilder extends FunctionCall {

public static final String LABEL = "Map Data";

@Override
public void setConcreteConstData() {
metadata().label(LABEL);
codedata().node(NodeKind.DATA_MAPPER_CALL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4079,11 +4079,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17215,11 +17215,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
},
{
"metadata": {
"label": "Data Mapper",
"description": "Map data from multiple variables to a record type"
"label": "Map Data"
},
"codedata": {
"node": "DATA_MAPPER"
"node": "DATA_MAPPER_CALL"
},
"enabled": true
}
Expand Down
Loading

0 comments on commit f6c7034

Please sign in to comment.