Skip to content

Commit

Permalink
Merge branch 'main' into dilanSachi-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedSabthar authored Oct 31, 2023
2 parents ce6ce16 + ffbf33d commit d71a4f5
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 156 deletions.
42 changes: 21 additions & 21 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
org.gradle.caching=true
group=io.ballerina
version=0.2.0-SNAPSHOT
version=0.2.1-SNAPSHOT
#dependency versions
ballerinaLangVersion=2201.8.0-20230908-135700-74a59dff
ballerinaLangVersion=2201.8.0
checkstylePluginVersion=10.12.1
commonsLang3Version=3.8.1
slf4jVersion=1.7.30
Expand All @@ -16,29 +16,29 @@ researchgateReleaseVersion=2.8.0
testngVersion=7.6.1
jacocoVersion=0.8.10

stdlibGrpcVersion=1.10.0-20230911-215000-dc09f7e
stdlibIoVersion=1.6.0-20230911-134800-de06e28
stdlibTimeVersion=2.4.0-20230911-140200-7f96f1e
stdlibUrlVersion=2.4.0-20230911-140700-36451a2
stdlibGrpcVersion=1.10.0
stdlibIoVersion=1.6.0
stdlibTimeVersion=2.4.0
stdlibUrlVersion=2.4.0

stdlibConstraintVersion=1.4.0-20230911-142700-8202202
stdlibCryptoVersion=2.5.0-20230911-142900-8807d07
stdlibLogVersion=2.9.0-20230911-150900-2f32c1a
stdlibOsVersion=1.8.0-20230911-142700-b182bf4
stdlibProtobufVersion=1.6.0-20230911-142700-45813d1
stdlibRandomVersion=1.5.0-20230911-142500-8afcce6
stdlibTaskVersion=2.5.0-20230911-143300-237313e
stdlibConstraintVersion=1.4.0
stdlibCryptoVersion=2.5.0
stdlibLogVersion=2.9.0
stdlibOsVersion=1.8.0
stdlibProtobufVersion=1.6.0
stdlibRandomVersion=1.5.0
stdlibTaskVersion=2.5.0

stdlibCacheVersion=3.7.0-20230911-145700-142f375
stdlibFileVersion=1.9.0-20230911-153400-738b25e
stdlibMimeVersion=2.9.0-20230911-153200-3add04c
stdlibUuidVersion=1.7.0-20230911-150900-6c4771f
stdlibCacheVersion=3.7.0
stdlibFileVersion=1.9.0
stdlibMimeVersion=2.9.0
stdlibUuidVersion=1.7.0

stdlibAuthVersion=2.10.0-20230911-153500-8c3c5cb
stdlibJwtVersion=2.10.0-20230911-153400-b5de47b
stdlibOAuth2Version=2.10.0-20230911-153600-6710ec0
stdlibAuthVersion=2.10.0
stdlibJwtVersion=2.10.0
stdlibOAuth2Version=2.10.0

stdlibHttpVersion=2.10.0-20230911-204400-1c092fe
stdlibHttpVersion=2.10.0

# Ballerinax Observer
observeVersion=1.2.0-20230911-133500-b3d8db3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ public static TypeTestExpressionNode getTypeTestExpressionNode(ExpressionNode ex
);
}

public static TypeTestExpressionNode getUnaryTypeTestExpressionNode(ExpressionNode expression,
Node typeDescriptor) {
return NodeFactory.createTypeTestExpressionNode(
expression,
SyntaxTreeConstants.SYNTAX_TREE_KEYWORD_NOT_IS,
typeDescriptor
);
}

public static CheckExpressionNode getCheckExpressionNode(ExpressionNode expression) {
return NodeFactory.createCheckExpressionNode(
SyntaxKind.CHECK_ACTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ private SyntaxTreeConstants() {
public static final Token SYNTAX_TREE_UNDERSCORE = AbstractNodeFactory.createIdentifierToken("_");
public static final Token SYNTAX_TREE_OPTIONAL_CHAINING = AbstractNodeFactory.createIdentifierToken("?.");
public static final Token SYNTAX_TREE_AT = AbstractNodeFactory.createIdentifierToken("@");

public static final Token SYNTAX_TREE_KEYWORD_NEW = AbstractNodeFactory.createIdentifierToken("new ");
public static final Token SYNTAX_TREE_KEYWORD_IMPORT = AbstractNodeFactory.createIdentifierToken("import ");
public static final Token SYNTAX_TREE_KEYWORD_CHECK = AbstractNodeFactory.createIdentifierToken("check ");
Expand All @@ -74,6 +73,7 @@ private SyntaxTreeConstants() {
public static final Token SYNTAX_TREE_KEYWORD_IF = AbstractNodeFactory.createIdentifierToken("if ");
public static final Token SYNTAX_TREE_KEYWORD_ELSE = AbstractNodeFactory.createIdentifierToken("else ");
public static final Token SYNTAX_TREE_KEYWORD_IS = AbstractNodeFactory.createIdentifierToken("is ");
public static final Token SYNTAX_TREE_KEYWORD_NOT_IS = AbstractNodeFactory.createIdentifierToken("!is ");
public static final Token SYNTAX_TREE_KEYWORD_LISTENER = AbstractNodeFactory.createIdentifierToken("listener ");
public static final Token SYNTAX_TREE_KEYWORD_SERVICE = AbstractNodeFactory.createIdentifierToken("service ");
public static final Token SYNTAX_TREE_KEYWORD_ON = AbstractNodeFactory.createIdentifierToken("on ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -90,6 +91,24 @@ public class ClientSampleSyntaxTreeUtils {

private static boolean firstLine;

private static final Map<String, ExpressionNode> INPUT_TYPE_EXPR_NODES = new HashMap<>();

static {
INPUT_TYPE_EXPR_NODES.put("int", getNumericLiteralNode(1));
INPUT_TYPE_EXPR_NODES.put("float", getNumericLiteralNode(1));
INPUT_TYPE_EXPR_NODES.put("decimal", getNumericLiteralNode(1));
INPUT_TYPE_EXPR_NODES.put("boolean", getBooleanLiteralNode(true));
INPUT_TYPE_EXPR_NODES.put("string", getStringLiteralNode("ballerina"));
INPUT_TYPE_EXPR_NODES.put("byte[]", getByteArrayLiteralNode("[72,101,108,108,111]"));
INPUT_TYPE_EXPR_NODES.put("time:Utc", getTupleLiteralNode("[1659688553,0.310073000d]"));
INPUT_TYPE_EXPR_NODES.put("time:Seconds", getDecimalLiteralNode("0.310073000d"));
INPUT_TYPE_EXPR_NODES.put("map<anydata>", createBasicLiteralNode(SyntaxKind.MAP_TYPE_DESC,
"{message: \"Hello Ballerina\"}"));
INPUT_TYPE_EXPR_NODES.put("'any:Any", getCheckExpressionNode(
getFunctionCallExpressionNode("'any", "pack", "\"ballerina\""))
);
}

public static SyntaxTree generateSyntaxTreeForClientSample(ServiceStub serviceStub, String filename,
Map<String, Message> msgMap) {
NodeList<ModuleMemberDeclarationNode> moduleMembers = AbstractNodeFactory.createEmptyNodeList();
Expand Down Expand Up @@ -285,41 +304,14 @@ private static VariableDeclarationNode getInputDeclarationStatement(Method metho
method.getInputType() + " ")),
getCaptureBindingPatternNode(getRequestName(method.getMethodName())));
ExpressionNode node = null;
switch (method.getInputType()) {
case "int":
case "float":
case "decimal":
node = getNumericLiteralNode(1);
break;
case "boolean":
node = getBooleanLiteralNode(true);
break;
case "string":
node = getStringLiteralNode("ballerina");
break;
case "byte[]":
node = getByteArrayLiteralNode("[72,101,108,108,111]");
break;
case "time:Utc":
node = getTupleLiteralNode("[1659688553,0.310073000d]");
break;
case "time:Seconds":
node = getDecimalLiteralNode("0.310073000d");
break;
case "map<anydata>":
node = createBasicLiteralNode(SyntaxKind.MAP_TYPE_DESC, "{message: \"Hello Ballerina\"}");
break;
case "'any:Any":
node = getCheckExpressionNode(getFunctionCallExpressionNode("'any", "pack", "\"ballerina\""));
break;
default:
if (msgMap.containsKey(method.getInputType())) {
Message msg = msgMap.get(method.getInputType());
node = NodeFactory.createMappingConstructorExpressionNode(
SyntaxTreeConstants.SYNTAX_TREE_OPEN_BRACE,
NodeFactory.createSeparatedNodeList(getFieldNodes(msg, msgMap)),
SyntaxTreeConstants.SYNTAX_TREE_CLOSE_BRACE);
}
if (INPUT_TYPE_EXPR_NODES.containsKey(method.getInputType())) {
node = INPUT_TYPE_EXPR_NODES.get(method.getInputType());
} else if (msgMap.containsKey(method.getInputType())) {
Message msg = msgMap.get(method.getInputType());
node = NodeFactory.createMappingConstructorExpressionNode(
SyntaxTreeConstants.SYNTAX_TREE_OPEN_BRACE,
NodeFactory.createSeparatedNodeList(getFieldNodes(msg, msgMap)),
SyntaxTreeConstants.SYNTAX_TREE_CLOSE_BRACE);
}
VariableDeclaration valueVariable = new VariableDeclaration(bindingPatternNode, node);
return valueVariable.getVariableDeclarationNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@

import static io.ballerina.protoc.GrpcConstants.ANN_DESCRIPTOR;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getBinaryExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getBracedExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getFieldAccessExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getMethodCallExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getOptionalFieldAccessExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getTypeTestExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getUnaryExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getUnaryTypeTestExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Literal.getBooleanLiteralNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Literal.getNumericLiteralNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Statement.getCompoundAssignmentStatementNode;
Expand Down Expand Up @@ -247,14 +245,10 @@ private static Function getValidationFunction(Message message) {
function.addVariableStatement(count.getVariableDeclarationNode());
for (Field field : oneOfFieldMap.getValue()) {
IfElse oneOfFieldCheck = new IfElse(
getUnaryExpressionNode(
getBracedExpressionNode(
getTypeTestExpressionNode(
getOptionalFieldAccessExpressionNode("r", field.getFieldName()),
getNilTypeDescriptorNode()
)
)
)
getUnaryTypeTestExpressionNode(
getOptionalFieldAccessExpressionNode("r", field.getFieldName()),
getNilTypeDescriptorNode()
)
);
oneOfFieldCheck.addIfStatement(
getCompoundAssignmentStatementNode(
Expand All @@ -268,9 +262,7 @@ private static Function getValidationFunction(Message message) {
}
if (counts.size() > 0) {
IfElse countCheck = new IfElse(
getBracedExpressionNode(
getCountCheckBinaryExpression(counts)
)
getCountCheckBinaryExpression(counts)
);
countCheck.addIfStatement(
getReturnStatementNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static io.ballerina.protoc.builder.BallerinaFileBuilder.protofileModuleMap;
import static io.ballerina.protoc.builder.balgen.BalGenConstants.COLON;
import static io.ballerina.protoc.builder.balgen.BalGenConstants.PACKAGE_SEPARATOR;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getBracedExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getExplicitNewExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getFieldAccessExpressionNode;
import static io.ballerina.protoc.builder.syntaxtree.components.Expression.getMethodCallExpressionNode;
Expand Down Expand Up @@ -228,11 +227,9 @@ private static Function getNextFunction(Method method, String filename) {
function.addVariableStatement(streamValue.getVariableDeclarationNode());

IfElse streamValueNilCheck = new IfElse(
getBracedExpressionNode(
getTypeTestExpressionNode(
getSimpleNameReferenceNode("streamValue"),
getNilTypeDescriptorNode()
)
getTypeTestExpressionNode(
getSimpleNameReferenceNode("streamValue"),
getNilTypeDescriptorNode()
)
);
streamValueNilCheck.addIfStatement(
Expand All @@ -241,11 +238,9 @@ private static Function getNextFunction(Method method, String filename) {
)
);
IfElse streamValueErrorCheck = new IfElse(
getBracedExpressionNode(
getTypeTestExpressionNode(
getSimpleNameReferenceNode("streamValue"),
SyntaxTreeConstants.SYNTAX_TREE_GRPC_ERROR
)
getTypeTestExpressionNode(
getSimpleNameReferenceNode("streamValue"),
SyntaxTreeConstants.SYNTAX_TREE_GRPC_ERROR
)
);
streamValueErrorCheck.addIfStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public class ResMessageStream {

public isolated function next() returns record {|ResMessage value;|}|grpc:Error? {
var streamValue = self.anydataStream.next();
if (streamValue is ()) {
if streamValue is () {
return streamValue;
} else if (streamValue is grpc:Error) {
} else if streamValue is grpc:Error {
return streamValue;
} else {
record {|ResMessage value;|} nextRecord = {value: <ResMessage>streamValue.value};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public class ResMessageStream {

public isolated function next() returns record {|ResMessage value;|}|grpc:Error? {
var streamValue = self.anydataStream.next();
if (streamValue is ()) {
if streamValue is () {
return streamValue;
} else if (streamValue is grpc:Error) {
} else if streamValue is grpc:Error {
return streamValue;
} else {
record {|ResMessage value;|} nextRecord = {value: <ResMessage>streamValue.value};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,26 @@ public type Request1 record {|

isolated function isValidRequest1(Request1 r) returns boolean {
int otherCount = 0;
if !(r?.age is ()) {
if r?.age !is () {
otherCount += 1;
}
if !(r?.address is ()) {
if r?.address !is () {
otherCount += 1;
}
if !(r?.married is ()) {
if r?.married !is () {
otherCount += 1;
}
int nameCount = 0;
if !(r?.first_name is ()) {
if r?.first_name !is () {
nameCount += 1;
}
if !(r?.last_name is ()) {
if r?.last_name !is () {
nameCount += 1;
}
if !(r?.'version is ()) {
if r?.'version !is () {
nameCount += 1;
}
if (otherCount > 1 || nameCount > 1) {
if otherCount > 1 || nameCount > 1 {
return false;
}
return true;
Expand Down Expand Up @@ -235,13 +235,13 @@ public type Address1 record {|

isolated function isValidAddress1(Address1 r) returns boolean {
int codeCount = 0;
if !(r?.house_number is ()) {
if r?.house_number !is () {
codeCount += 1;
}
if !(r?.street_number is ()) {
if r?.street_number !is () {
codeCount += 1;
}
if (codeCount > 1) {
if codeCount > 1 {
return false;
}
return true;
Expand Down Expand Up @@ -285,40 +285,40 @@ public type ZZZ record {|

isolated function isValidZzz(ZZZ r) returns boolean {
int valueCount = 0;
if !(r?.one_a is ()) {
if r?.one_a !is () {
valueCount += 1;
}
if !(r?.one_b is ()) {
if r?.one_b !is () {
valueCount += 1;
}
if !(r?.one_c is ()) {
if r?.one_c !is () {
valueCount += 1;
}
if !(r?.one_d is ()) {
if r?.one_d !is () {
valueCount += 1;
}
if !(r?.one_e is ()) {
if r?.one_e !is () {
valueCount += 1;
}
if !(r?.one_f is ()) {
if r?.one_f !is () {
valueCount += 1;
}
if !(r?.one_g is ()) {
if r?.one_g !is () {
valueCount += 1;
}
if !(r?.one_h is ()) {
if r?.one_h !is () {
valueCount += 1;
}
if !(r?.one_i is ()) {
if r?.one_i !is () {
valueCount += 1;
}
if !(r?.one_j is ()) {
if r?.one_j !is () {
valueCount += 1;
}
if !(r?.one_k is ()) {
if r?.one_k !is () {
valueCount += 1;
}
if (valueCount > 1) {
if valueCount > 1 {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public class ParentMessageStream {

public isolated function next() returns record {|ParentMessage value;|}|grpc:Error? {
var streamValue = self.anydataStream.next();
if (streamValue is ()) {
if streamValue is () {
return streamValue;
} else if (streamValue is grpc:Error) {
} else if streamValue is grpc:Error {
return streamValue;
} else {
record {|ParentMessage value;|} nextRecord = {value: <ParentMessage>streamValue.value};
Expand Down
Loading

0 comments on commit d71a4f5

Please sign in to comment.