From 3064cec0a7d70ad68099a08b22ba0cc48bbd7aa9 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Fri, 15 Dec 2023 16:56:26 +0530 Subject: [PATCH] Address review suggestions --- .../compiler/internal/parser/BallerinaParser.java | 14 +++----------- .../receive-action/receive_action_assert_01.json | 6 ++---- .../receive-action/receive_action_assert_02.json | 3 +-- .../receive-action/receive_action_assert_04.json | 15 +++++---------- .../send-action/send_action_assert_02.json | 6 ++---- .../send-action/send_action_assert_04.json | 6 ++---- .../misc/completion/completion_assert_08.json | 6 ++++++ .../misc/completion/completion_source_08.bal | 2 +- .../formatter/core/FormattingTreeModifier.java | 9 +++++++-- .../send-receive/assert/send_receive_action_4.bal | 10 ++++++++++ .../send-receive/source/send_receive_action_4.bal | 9 +++++++++ 11 files changed, 48 insertions(+), 38 deletions(-) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java index d17a061f9a86..4c06f11a3c28 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/BallerinaParser.java @@ -13038,21 +13038,14 @@ private STNode parseSyncSendAction(STNode expression) { * @return peer worker name node */ private STNode parsePeerWorkerName() { - return STNodeFactory.createSimpleNameReferenceNode(parsePeerWorkerIdentifier()); - } - - private STNode parsePeerWorkerIdentifier() { STToken token = peek(); switch (token.kind) { case IDENTIFIER_TOKEN: - return consume(); case FUNCTION_KEYWORD: - STToken functionKeyword = consume(); - return STNodeFactory.createIdentifierToken(functionKeyword.text(), functionKeyword.leadingMinutiae(), - functionKeyword.trailingMinutiae(), functionKeyword.diagnostics()); + return STNodeFactory.createSimpleNameReferenceNode(consume()); default: recover(token, ParserRuleContext.PEER_WORKER_NAME); - return parsePeerWorkerIdentifier(); + return parsePeerWorkerName(); } } @@ -13232,8 +13225,7 @@ private STNode createReceiveField(STNode identifier) { identifier = STNodeFactory.createSimpleNameReferenceNode(identifier); STNode colon = parseColon(); - STNode peerWorker = parsePeerWorkerIdentifier(); - peerWorker = STNodeFactory.createSimpleNameReferenceNode(peerWorker); + STNode peerWorker = parsePeerWorkerName(); return STNodeFactory.createReceiveFieldNode(identifier, colon, peerWorker); } diff --git a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_01.json b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_01.json index 1a683f8dd921..0614217f73ce 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_01.json +++ b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_01.json @@ -83,8 +83,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } @@ -496,8 +495,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } diff --git a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_02.json b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_02.json index 041430fe3cd1..d3fa057f8f2f 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_02.json +++ b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_02.json @@ -636,8 +636,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } diff --git a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_04.json b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_04.json index 5d1b36d39904..19961f156696 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_04.json +++ b/compiler/ballerina-parser/src/test/resources/actions/receive-action/receive_action_assert_04.json @@ -334,8 +334,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", @@ -358,8 +357,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } @@ -560,8 +558,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", @@ -584,8 +581,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", @@ -685,8 +681,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", diff --git a/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_02.json b/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_02.json index 094228f66893..3bc47de77079 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_02.json +++ b/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_02.json @@ -242,8 +242,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } @@ -324,8 +323,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function" + "kind": "FUNCTION_KEYWORD" } ] } diff --git a/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_04.json b/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_04.json index e66253ec076d..8d9b27c8a067 100644 --- a/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_04.json +++ b/compiler/ballerina-parser/src/test/resources/actions/send-action/send_action_assert_04.json @@ -310,8 +310,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", @@ -407,8 +406,7 @@ "kind": "SIMPLE_NAME_REFERENCE", "children": [ { - "kind": "IDENTIFIER_TOKEN", - "value": "function", + "kind": "FUNCTION_KEYWORD", "trailingMinutiae": [ { "kind": "WHITESPACE_MINUTIAE", diff --git a/compiler/ballerina-parser/src/test/resources/misc/completion/completion_assert_08.json b/compiler/ballerina-parser/src/test/resources/misc/completion/completion_assert_08.json index a8cbb7f6af1b..d92545238d4f 100644 --- a/compiler/ballerina-parser/src/test/resources/misc/completion/completion_assert_08.json +++ b/compiler/ballerina-parser/src/test/resources/misc/completion/completion_assert_08.json @@ -1261,6 +1261,12 @@ }, { "kind": "CLOSE_BRACE_TOKEN", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], "trailingMinutiae": [ { "kind": "END_OF_LINE_MINUTIAE", diff --git a/compiler/ballerina-parser/src/test/resources/misc/completion/completion_source_08.bal b/compiler/ballerina-parser/src/test/resources/misc/completion/completion_source_08.bal index b2af46caabd3..f738f85855ef 100644 --- a/compiler/ballerina-parser/src/test/resources/misc/completion/completion_source_08.bal +++ b/compiler/ballerina-parser/src/test/resources/misc/completion/completion_source_08.bal @@ -27,7 +27,7 @@ function foo6() { function foo7() { <- { a: } -} + } function foo8() { flush diff --git a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java index 2ee8a1cb59c1..6636979456fd 100644 --- a/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java +++ b/misc/formatter/modules/formatter-core/src/main/java/org/ballerinalang/formatter/core/FormattingTreeModifier.java @@ -3008,14 +3008,19 @@ public ReceiveActionNode transform(ReceiveActionNode receiveActionNode) { @Override public ReceiveFieldsNode transform(ReceiveFieldsNode receiveFieldsNode) { - int trailingNL = shouldExpand(receiveFieldsNode) ? 1 : 0; + boolean preserveIndent = env.preserveIndentation; + preserveIndentation(false); + boolean isMultiline = shouldExpand(receiveFieldsNode); + int trailingNL = isMultiline ? 1 : 0; + int trailingWS = isMultiline ? 0 : 1; Token openBrace = formatToken(receiveFieldsNode.openBrace(), 0, trailingNL); indent(); SeparatedNodeList receiveFields = - formatSeparatedNodeList(receiveFieldsNode.receiveFields(), 0, 0, 1 - trailingNL, trailingNL, 0, + formatSeparatedNodeList(receiveFieldsNode.receiveFields(), 0, 0, trailingWS, trailingNL, 0, trailingNL); unindent(); Token closeBrace = formatToken(receiveFieldsNode.closeBrace(), env.trailingWS, env.trailingNL); + preserveIndentation(preserveIndent); return receiveFieldsNode.modify() .withOpenBrace(openBrace) .withReceiveFields(receiveFields) diff --git a/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/assert/send_receive_action_4.bal b/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/assert/send_receive_action_4.bal index 8e437cf5bc57..22a414bfd67b 100644 --- a/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/assert/send_receive_action_4.bal +++ b/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/assert/send_receive_action_4.bal @@ -55,3 +55,13 @@ function foz() { }; } } + +function foooz() { + do { + _ = <- + { + a: w1, + b: w2 + }; + } +} diff --git a/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/source/send_receive_action_4.bal b/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/source/send_receive_action_4.bal index beb15b156a63..e93955324332 100644 --- a/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/source/send_receive_action_4.bal +++ b/misc/formatter/modules/formatter-core/src/test/resources/actions/send-receive/source/send_receive_action_4.bal @@ -44,3 +44,12 @@ function foz() { tooLengthyWorkerName}; } } + +function foooz() { + do { + _ = <- +{ +a: w1,b: w2 +}; + } +}