Skip to content

Commit

Permalink
Capture the variable name of an output port
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Dec 11, 2023
1 parent 0958200 commit 1228a60
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ private void analyzeSendAction(SimpleNameReferenceNode receiverNode, ExpressionN
this.toWorker = receiverNode.name().text();
Optional<TypeSymbol> typeSymbol = this.semanticModel.typeOf(expressionNode);
this.type = typeSymbol.isPresent() ? typeSymbol.get().typeKind() : TypeDescKind.NONE;
this.addOutputPort(String.valueOf(++this.portId), this.type, this.toWorker);

// Capture the name if the expression is a variable
String name = expressionNode.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE ?
((SimpleNameReferenceNode) expressionNode).name().text() : null;

this.addOutputPort(String.valueOf(++this.portId), this.type, name, this.toWorker);
this.hasProcessed = true;
}

Expand Down Expand Up @@ -157,8 +162,8 @@ public void addInputPort(String id, TypeDescKind type, String name, String sende
}

@Override
public void addOutputPort(String id, TypeDescKind type, String receiver) {
this.outputPorts.add(new OutputPort(id, type, receiver));
public void addOutputPort(String id, TypeDescKind type, String name, String receiver) {
this.outputPorts.add(new OutputPort(id, type, name, receiver));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @param id id of the port
* @param type type of the port
* @param name name of the port
* @param name variable assigned to the port
* @param sender id of the sender node
* @since 2201.9.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
*
* @param id id of the port
* @param type type of the port
* @param name variable assigned to the port
* @param receiver id of the receiver node
* @since 2201.9.0
*/
public record OutputPort(String id, TypeDescKind type, String receiver) {
public record OutputPort(String id, TypeDescKind type, String name, String receiver) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface WorkerNodeJsonBuilder {
*
* @param id id of the port
* @param type type of the port
* @param name name of the port
* @param name variable assigned to the port
* @param sender id of the sender node
*/
void addInputPort(String id, TypeDescKind type, String name, String sender);
Expand All @@ -73,9 +73,10 @@ public interface WorkerNodeJsonBuilder {
*
* @param id id of the port
* @param type type of the port
* @param name variable assigned to the port
* @param receiver id of the receiver node
*/
void addOutputPort(String id, TypeDescKind type, String receiver);
void addOutputPort(String id, TypeDescKind type, String name, String receiver);

/**
* Sets the code block of the node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void testGeneratedModel(Path config) throws IOException {

boolean flowEquality = modifiedFlow.equals(testConfig.getFlow());
if (!fileNameEquality || !flowEquality) {
updateConfig(configJsonPath, testConfig, modifiedFlow);
// updateConfig(configJsonPath, testConfig, modifiedFlow);
logModelDifference(testConfig.getFlow(), modifiedFlow);
Assert.fail(String.format("Failed test: '%s' (%s)", testConfig.getDescription(), configJsonPath));
}
Expand Down Expand Up @@ -140,15 +140,19 @@ private void logModelDifference(Flow expectedFlow, Flow actualFlow) {

List<WorkerNode> missingNodes = new ArrayList<>();
List<WorkerNode> irrelevantNodes = new ArrayList<>(actualFlow.nodes());
if (expectedFlow.nodes() == null) {
LOG.info("No worker nodes found in the response");
return;
}
for (WorkerNode expectedNode : expectedFlow.nodes()) {
boolean removed = irrelevantNodes.remove(expectedNode);
if (!removed) {
missingNodes.add(expectedNode);
}
}
if (!missingNodes.isEmpty() || !irrelevantNodes.isEmpty()) {
LOG.info("Completion items which are in response but not in test config : " + irrelevantNodes);
LOG.info("Completion items which are in test config but not in response : " + missingNodes);
LOG.info("Worker nodes which are in response but not in test config : " + irrelevantNodes);
LOG.info("Worker nodes which are in test config but not in response : " + missingNodes);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
{
"id": "2",
"type": "INT",
"name": "b",
"receiver": "function"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
{
"id": "2",
"type": "INT",
"name": "x1",
"receiver": "function"
}
],
Expand Down Expand Up @@ -109,6 +110,7 @@
{
"id": "2",
"type": "INT",
"name": "x2",
"receiver": "function"
}
],
Expand Down

0 comments on commit 1228a60

Please sign in to comment.