Skip to content

Commit

Permalink
Apply code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishad-M-I-M committed Oct 9, 2023
1 parent 98f45ae commit 1a1fbb6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
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 @@ -46,8 +46,7 @@
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 +246,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 Down

0 comments on commit 1a1fbb6

Please sign in to comment.