diff --git a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/components/Expression.java b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/components/Expression.java index 23aab80..6e7f775 100644 --- a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/components/Expression.java +++ b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/components/Expression.java @@ -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, diff --git a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/constants/SyntaxTreeConstants.java b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/constants/SyntaxTreeConstants.java index 80a88a0..d477725 100644 --- a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/constants/SyntaxTreeConstants.java +++ b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/constants/SyntaxTreeConstants.java @@ -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 "); @@ -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 "); diff --git a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/utils/MessageUtils.java b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/utils/MessageUtils.java index 873d0e2..f2753fc 100644 --- a/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/utils/MessageUtils.java +++ b/protoc-cli/src/main/java/io/ballerina/protoc/builder/syntaxtree/utils/MessageUtils.java @@ -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; @@ -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(