Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new node to represent data mapping function calls #536

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1084,51 +1082,35 @@ public void visit(FunctionCallExpressionNode functionCallExpressionNode) {
};

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));
startNode(NodeKind.DATA_MAPPER_CALL, functionCallExpressionNode.parent());
} 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);
}

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);
if (CommonUtils.isDefaultPackage(functionSymbol, moduleInfo)) {
functionSymbol.getLocation()
.flatMap(location -> CommonUtil.findNode(functionSymbol,
CommonUtils.getDocument(project, location).syntaxTree()))
.ifPresent(node -> nodeBuilder.properties().view(node.lineRange()));
}

final Map<String, Node> namedArgValueMap = new HashMap<>();
final Queue<Node> positionalArgs = new LinkedList<>();
calculateFunctionArgs(namedArgValueMap, positionalArgs, functionCallExpressionNode.arguments());
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);

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());
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(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
Expand Up @@ -59,7 +59,7 @@ public class FunctionGenerator {
private final Category.Builder rootBuilder;

private static final String INCLUDE_AVAILABLE_FUNCTIONS_FLAG = "includeAvailableFunctions";
private static final String DATA_MAPPER_FILE_NAME = "data_mapper.bal";
private static final String DATA_MAPPER_FILE_NAME = "data_mappings.bal";

public FunctionGenerator(Module module) {
gson = new Gson();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.ballerina.flowmodelgenerator.core.model.node.ConfigVariableBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.ContinueBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.DataMapperBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.DataMapperCallBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.ErrorHandlerBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.EventStartBuilder;
import io.ballerina.flowmodelgenerator.core.model.node.ExpressionBuilder;
Expand Down Expand Up @@ -123,6 +124,7 @@ public abstract class NodeBuilder implements DiagnosticHandler.DiagnosticCapable
put(NodeKind.COMMENT, CommentBuilder::new);
put(NodeKind.MATCH, MatchBuilder::new);
put(NodeKind.CONFIG_VARIABLE, ConfigVariableBuilder::new);
put(NodeKind.DATA_MAPPER_CALL, DataMapperCallBuilder::new);
}};

public static NodeBuilder getNodeFromKind(NodeKind kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public enum NodeKind {
ENUM,
ARRAY,
UNION,
ERROR
ERROR,
DATA_MAPPER_CALL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.ballerina.flowmodelgenerator.core.model.node;

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
Loading