Skip to content

Commit

Permalink
Merge pull request #536 from KavinduZoysa/top-level-data-mapper
Browse files Browse the repository at this point in the history
Add new node to represent data mapping function calls
  • Loading branch information
KavinduZoysa authored Jan 10, 2025
2 parents 9c82ad6 + f6c7034 commit 6cdf30c
Show file tree
Hide file tree
Showing 25 changed files with 289 additions and 257 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 @@ -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

0 comments on commit 6cdf30c

Please sign in to comment.