Skip to content

Commit

Permalink
Fix formatting of multiple receive actions
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Dec 14, 2023
1 parent e116c9b commit 27eb93f
Show file tree
Hide file tree
Showing 26 changed files with 641 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
import io.ballerina.compiler.syntax.tree.ReUnicodePropertyEscapeNode;
import io.ballerina.compiler.syntax.tree.ReUnicodeScriptNode;
import io.ballerina.compiler.syntax.tree.ReceiveActionNode;
import io.ballerina.compiler.syntax.tree.ReceiveFieldNode;
import io.ballerina.compiler.syntax.tree.ReceiveFieldsNode;
import io.ballerina.compiler.syntax.tree.RecordFieldNode;
import io.ballerina.compiler.syntax.tree.RecordFieldWithDefaultValueNode;
Expand Down Expand Up @@ -2548,18 +2549,18 @@ public BLangNode transform(ReceiveActionNode receiveActionNode) {
}

ReceiveFieldsNode receiveFieldsNode = (ReceiveFieldsNode) receiveWorkers;
SeparatedNodeList<NameReferenceNode> receiveFields = receiveFieldsNode.receiveFields();
SeparatedNodeList<Node> receiveFields = receiveFieldsNode.receiveFields();
List<BLangMultipleWorkerReceive.BLangReceiveField> fields = new ArrayList<>(receiveFields.size());
for (NameReferenceNode nameRef : receiveFields) {
for (Node receiveField : receiveFields) {
BLangMultipleWorkerReceive.BLangReceiveField rvField = new BLangMultipleWorkerReceive.BLangReceiveField();
if (nameRef.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
Token name = ((SimpleNameReferenceNode) nameRef).name();
if (receiveField.kind() == SyntaxKind.SIMPLE_NAME_REFERENCE) {
Token name = ((SimpleNameReferenceNode) receiveField).name();
rvField.setKey(createIdentifier(name));
rvField.setWorkerReceive(createSimpleWorkerReceive(name));
} else {
QualifiedNameReferenceNode qualifiedNameRef = (QualifiedNameReferenceNode) nameRef;
rvField.setKey(createIdentifier(qualifiedNameRef.modulePrefix()));
rvField.setWorkerReceive(createSimpleWorkerReceive(qualifiedNameRef.identifier()));
ReceiveFieldNode receiveFieldNode = (ReceiveFieldNode) receiveField;
rvField.setKey(createIdentifier(receiveFieldNode.fieldName().name()));
rvField.setWorkerReceive(createSimpleWorkerReceive(receiveFieldNode.peerWorker().name()));
}
fields.add(rvField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13218,21 +13218,23 @@ private STNode parseReceiveField() {
return STNodeFactory.createSimpleNameReferenceNode(functionKeyword);
case IDENTIFIER_TOKEN:
STNode identifier = parseIdentifier(ParserRuleContext.RECEIVE_FIELD_NAME);
return createQualifiedReceiveField(identifier);
return createReceiveField(identifier);
default:
recover(peek(), ParserRuleContext.RECEIVE_FIELD);
return parseReceiveField();
}
}

private STNode createQualifiedReceiveField(STNode identifier) {
private STNode createReceiveField(STNode identifier) {
if (peek().kind != SyntaxKind.COLON_TOKEN) {
return STNodeFactory.createSimpleNameReferenceNode(identifier);
}

identifier = STNodeFactory.createSimpleNameReferenceNode(identifier);
STNode colon = parseColon();
STNode peerWorker = parsePeerWorkerIdentifier();
return createQualifiedNameReferenceNode(identifier, colon, peerWorker);
peerWorker = STNodeFactory.createSimpleNameReferenceNode(peerWorker);
return STNodeFactory.createReceiveFieldNode(identifier, colon, peerWorker);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2719,5 +2719,16 @@ public static STNode createMemberTypeDescriptorNode(
annotations,
typeDescriptor);
}

public static STNode createReceiveFieldNode(
STNode fieldName,
STNode colon,
STNode peerWorker) {

return new STReceiveFieldNode(
fieldName,
colon,
peerWorker);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ public T transform(STMemberTypeDescriptorNode memberTypeDescriptorNode) {
return transformSyntaxNode(memberTypeDescriptorNode);
}

public T transform(STReceiveFieldNode receiveFieldNode) {
return transformSyntaxNode(receiveFieldNode);
}

// Tokens

public T transform(STToken token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ public void visit(STMemberTypeDescriptorNode memberTypeDescriptorNode) {
visitSyntaxNode(memberTypeDescriptorNode);
}

public void visit(STReceiveFieldNode receiveFieldNode) {
visitSyntaxNode(receiveFieldNode);
}

// STNodeList
public void visit(STNodeList nodeList) {
visitChildren(nodeList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright (c) 2023, 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.compiler.internal.parser.tree;

import io.ballerina.compiler.syntax.tree.Node;
import io.ballerina.compiler.syntax.tree.NonTerminalNode;
import io.ballerina.compiler.syntax.tree.ReceiveFieldNode;
import io.ballerina.compiler.syntax.tree.SyntaxKind;

import java.util.Collection;
import java.util.Collections;

/**
* This is a generated internal syntax tree node.
*
* @since 2201.9.0
*/
public class STReceiveFieldNode extends STNode {
public final STNode fieldName;
public final STNode colon;
public final STNode peerWorker;

STReceiveFieldNode(
STNode fieldName,
STNode colon,
STNode peerWorker) {
this(
fieldName,
colon,
peerWorker,
Collections.emptyList());
}

STReceiveFieldNode(
STNode fieldName,
STNode colon,
STNode peerWorker,
Collection<STNodeDiagnostic> diagnostics) {
super(SyntaxKind.RECEIVE_FIELD, diagnostics);
this.fieldName = fieldName;
this.colon = colon;
this.peerWorker = peerWorker;

addChildren(
fieldName,
colon,
peerWorker);
}

public STNode modifyWith(Collection<STNodeDiagnostic> diagnostics) {
return new STReceiveFieldNode(
this.fieldName,
this.colon,
this.peerWorker,
diagnostics);
}

public STReceiveFieldNode modify(
STNode fieldName,
STNode colon,
STNode peerWorker) {
if (checkForReferenceEquality(
fieldName,
colon,
peerWorker)) {
return this;
}

return new STReceiveFieldNode(
fieldName,
colon,
peerWorker,
diagnostics);
}

public Node createFacade(int position, NonTerminalNode parent) {
return new ReceiveFieldNode(this, position, parent);
}

@Override
public void accept(STNodeVisitor visitor) {
visitor.visit(this);
}

@Override
public <T> T apply(STNodeTransformer<T> transformer) {
return transformer.transform(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2925,6 +2925,18 @@ public STMemberTypeDescriptorNode transform(
typeDescriptor);
}

@Override
public STReceiveFieldNode transform(
STReceiveFieldNode receiveFieldNode) {
STNode fieldName = modifyNode(receiveFieldNode.fieldName);
STNode colon = modifyNode(receiveFieldNode.colon);
STNode peerWorker = modifyNode(receiveFieldNode.peerWorker);
return receiveFieldNode.modify(
fieldName,
colon,
peerWorker);
}

// Tokens

public STToken transform(STToken token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2417,7 +2417,7 @@ public static ReceiveActionNode createReceiveActionNode(

public static ReceiveFieldsNode createReceiveFieldsNode(
Token openBrace,
SeparatedNodeList<NameReferenceNode> receiveFields,
SeparatedNodeList<Node> receiveFields,
Token closeBrace) {
Objects.requireNonNull(openBrace, "openBrace must not be null");
Objects.requireNonNull(receiveFields, "receiveFields must not be null");
Expand Down Expand Up @@ -3622,5 +3622,20 @@ public static MemberTypeDescriptorNode createMemberTypeDescriptorNode(
typeDescriptor.internalNode());
return stMemberTypeDescriptorNode.createUnlinkedFacade();
}

public static ReceiveFieldNode createReceiveFieldNode(
SimpleNameReferenceNode fieldName,
Token colon,
SimpleNameReferenceNode peerWorker) {
Objects.requireNonNull(fieldName, "fieldName must not be null");
Objects.requireNonNull(colon, "colon must not be null");
Objects.requireNonNull(peerWorker, "peerWorker must not be null");

STNode stReceiveFieldNode = STNodeFactory.createReceiveFieldNode(
fieldName.internalNode(),
colon.internalNode(),
peerWorker.internalNode());
return stReceiveFieldNode.createUnlinkedFacade();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,10 @@ public T transform(MemberTypeDescriptorNode memberTypeDescriptorNode) {
return transformSyntaxNode(memberTypeDescriptorNode);
}

public T transform(ReceiveFieldNode receiveFieldNode) {
return transformSyntaxNode(receiveFieldNode);
}

// Tokens

public T transform(Token token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,10 @@ public void visit(MemberTypeDescriptorNode memberTypeDescriptorNode) {
visitSyntaxNode(memberTypeDescriptorNode);
}

public void visit(ReceiveFieldNode receiveFieldNode) {
visitSyntaxNode(receiveFieldNode);
}

// Tokens

public void visit(Token token) {
Expand Down
Loading

0 comments on commit 27eb93f

Please sign in to comment.