From 48b9a26416774cfdcd296ca12135600f08ba2ff4 Mon Sep 17 00:00:00 2001 From: rdulmina Date: Fri, 26 Jul 2024 16:53:09 +0530 Subject: [PATCH 1/6] Shrink more fields of DocumentContext Shrink more fields of DocumentContext and shrink earlier --- .../main/java/io/ballerina/projects/DocumentContext.java | 2 ++ .../main/java/io/ballerina/projects/JBallerinaBackend.java | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java index b91b222fe5a5..c219679275d7 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java @@ -196,6 +196,8 @@ void shrink() { if (this.compilationUnit != null) { this.compilationUnit.topLevelNodes.clear(); } + this.syntaxTree = null; + this.moduleLoadRequests = null; this.content = null; } } diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java index ff8cd623b4dc..ccee5269ee3e 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBackend.java @@ -158,6 +158,9 @@ private void performCodeGen(boolean shrink) { // collect compilation diagnostics List moduleDiagnostics = new ArrayList<>(); for (ModuleContext moduleContext : pkgResolution.topologicallySortedModuleList()) { + if (shrink) { + ModuleContext.shrinkDocuments(moduleContext); + } if (moduleContext.moduleId().packageId().equals(packageContext.packageId())) { if (packageCompilation.diagnosticResult().hasErrors()) { for (Diagnostic diagnostic : moduleContext.diagnostics()) { @@ -180,9 +183,6 @@ private void performCodeGen(boolean shrink) { } } - if (shrink) { - ModuleContext.shrinkDocuments(moduleContext); - } if (moduleContext.project().kind() == ProjectKind.BALA_PROJECT) { moduleContext.cleanBLangPackage(); } From 35565592cc0deac95ea8a76e08625fe2a970986d Mon Sep 17 00:00:00 2001 From: mindula Date: Fri, 5 Jul 2024 15:48:34 +0530 Subject: [PATCH 2/6] Fix adding default namespaces --- .../XMLToRecordConverter.java | 21 ++++++++++++------- .../test/resources/ballerina/sample_27.bal | 6 ------ .../src/test/resources/ballerina/sample_9.bal | 12 +++++++++++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java index 91d52eb8816e..f759e2b60b93 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java @@ -314,11 +314,12 @@ private static List getRecordFieldsForXMLElement(Element xmlElement, boole } AnnotationNode xmlNSNode = getXMLNamespaceNode(prefix, xmlNode.getNodeValue()); recordToAnnotationNodes.put(xmlNodeName, xmlNSNode); - } else if (!isLeafXMLElementNode(xmlElement) && !XMLNS_PREFIX.equals(xmlNode.getPrefix())) { + } else if (!isLeafXMLElementNode(xmlElement) && !XMLNS_PREFIX.equals(xmlNode.getPrefix()) + && !XMLNS_PREFIX.equals(xmlNode.getLocalName())) { if (elementNames.contains(xmlNode.getNodeName())) { continue; } - Node recordField = getRecordField(xmlNode); + Node recordField = getRecordField(xmlNode, withNameSpace); recordFields.add(recordField); } } @@ -340,8 +341,9 @@ private static List getRecordFieldsForXMLElement(Element xmlElement, boole for (int j = 0; j < attributeLength; j++) { org.w3c.dom.Node xmlAttributeNode = xmlElement.getAttributes().item(j); if (xmlAttributeNode.getNodeType() == org.w3c.dom.Node.ATTRIBUTE_NODE - && !XMLNS_PREFIX.equals(xmlAttributeNode.getPrefix())) { - Node recordField = getRecordField(xmlAttributeNode); + && !XMLNS_PREFIX.equals(xmlAttributeNode.getPrefix()) + && !XMLNS_PREFIX.equals(xmlAttributeNode.getLocalName())) { + Node recordField = getRecordField(xmlAttributeNode, withNameSpace); recordFields.add(recordField); } } @@ -503,15 +505,20 @@ private static RecordFieldNode getRecordField(Element xmlElementNode, boolean is metadataNode, null, fieldTypeName, fieldName, optionalFieldToken, semicolonToken); } - private static Node getRecordField(org.w3c.dom.Node xmlAttributeNode) { + private static Node getRecordField(org.w3c.dom.Node xmlAttributeNode, boolean withNamespace) { Token typeName = AbstractNodeFactory.createToken(SyntaxKind.STRING_KEYWORD); TypeDescriptorNode fieldTypeName = NodeFactory.createBuiltinSimpleNameReferenceNode(typeName.kind(), typeName); IdentifierToken fieldName = AbstractNodeFactory.createIdentifierToken(escapeIdentifier(xmlAttributeNode.getLocalName())); Token equalToken = AbstractNodeFactory.createToken(SyntaxKind.EQUAL_TOKEN); Token semicolonToken = AbstractNodeFactory.createToken(SyntaxKind.SEMICOLON_TOKEN); - NodeList annotations = AbstractNodeFactory.createNodeList(getXMLAttributeNode()); - MetadataNode metadataNode = NodeFactory.createMetadataNode(null, annotations); + List annotations = new ArrayList<>(); + if (withNamespace && xmlAttributeNode.getPrefix() != null && xmlAttributeNode.getNamespaceURI() != null) { + annotations.add(getXMLNamespaceNode(xmlAttributeNode.getPrefix(), xmlAttributeNode.getNamespaceURI())); + } + annotations.add(getXMLAttributeNode()); + NodeList annotationNodes = NodeFactory.createNodeList(annotations); + MetadataNode metadataNode = NodeFactory.createMetadataNode(null, annotationNodes); if (xmlAttributeNode.getPrefix() != null && xmlAttributeNode.getPrefix().equals(XMLNS_PREFIX)) { diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal index 88eae813663e..124d9b65c959 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal @@ -7,8 +7,6 @@ type Customer record { string loyalty; @xmldata:Attribute string optedInNewsLetter; - @xmldata:Attribute - string 'xmlns; }; type Item record { @@ -30,12 +28,8 @@ type Order record { Customer customer; Items items; decimal total; - @xmldata:Attribute - string 'xmlns; }; type Orders record { Order[] 'order; - @xmldata:Attribute - string 'xmlns; }; diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_9.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_9.bal index 27f224c92693..65e5bbd3c120 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_9.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_9.bal @@ -1,11 +1,23 @@ type Ns1_Element1 record { + @xmldata:Namespace { + prefix: "ns1", + uri: "http://namespace1.com" + } @xmldata:Attribute string attribute1; + @xmldata:Namespace { + prefix: "ns2", + uri: "http://namespace2.com" + } @xmldata:Attribute string attribute2; }; type Ns2_Null record { + @xmldata:Namespace { + prefix: "xsi", + uri: "http://www.w3.org/2001/XMLSchema-instance" + } @xmldata:Attribute string nil; }; From ed28f376802e81eda2b4174277c32ca34e69bc66 Mon Sep 17 00:00:00 2001 From: mindula Date: Fri, 5 Jul 2024 13:04:46 +0530 Subject: [PATCH 3/6] Add tests --- .../XMLToRecordConverterTests.java | 42 +++++++++++ .../test/resources/ballerina/sample_35.bal | 37 ++++++++++ .../test/resources/ballerina/sample_36.bal | 62 ++++++++++++++++ .../test/resources/ballerina/sample_37.bal | 71 +++++++++++++++++++ .../src/test/resources/xml/sample_35.xml | 6 ++ .../src/test/resources/xml/sample_36.xml | 11 +++ .../src/test/resources/xml/sample_37.xml | 11 +++ 7 files changed, 240 insertions(+) create mode 100644 misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal create mode 100644 misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal create mode 100644 misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal create mode 100644 misc/xml-to-record-converter/src/test/resources/xml/sample_35.xml create mode 100644 misc/xml-to-record-converter/src/test/resources/xml/sample_36.xml create mode 100644 misc/xml-to-record-converter/src/test/resources/xml/sample_37.xml diff --git a/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java b/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java index d4a7818a9f21..70b9a80c073c 100644 --- a/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java +++ b/misc/xml-to-record-converter/src/test/java/io/ballerina/xmltorecordconverter/XMLToRecordConverterTests.java @@ -214,6 +214,21 @@ public class XMLToRecordConverterTests { private final Path sample34Bal = RES_DIR.resolve(BAL_DIR) .resolve("sample_34.bal"); + private final Path sample35XML = RES_DIR.resolve(XML_DIR) + .resolve("sample_35.xml"); + private final Path sample35Bal = RES_DIR.resolve(BAL_DIR) + .resolve("sample_35.bal"); + + private final Path sample36XML = RES_DIR.resolve(XML_DIR) + .resolve("sample_36.xml"); + private final Path sample36Bal = RES_DIR.resolve(BAL_DIR) + .resolve("sample_36.bal"); + + private final Path sample37XML = RES_DIR.resolve(XML_DIR) + .resolve("sample_37.xml"); + private final Path sample37Bal = RES_DIR.resolve(BAL_DIR) + .resolve("sample_37.bal"); + private static final String XMLToRecordServiceEP = "xmlToRecord/convert"; @@ -549,4 +564,31 @@ public void textXMLWithDefaultValueNode2() throws IOException { String expectedCodeBlock = Files.readString(sample34Bal).replaceAll("\\s+", ""); Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); } + + @Test(description = "textXMLWithDefaultNamespace") + public void textXMLWithDefaultNamespace() throws IOException { + String xmlFileContent = Files.readString(sample35XML); + String generatedCodeBlock = XMLToRecordConverter.convert(xmlFileContent, false, false, false, + "__text", true).getCodeBlock().replaceAll("\\s+", ""); + String expectedCodeBlock = Files.readString(sample35Bal).replaceAll("\\s+", ""); + Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); + } + + @Test(description = "textXMLWithDefaultNamespace2") + public void textXMLWithDefaultNamespace2() throws IOException { + String xmlFileContent = Files.readString(sample36XML); + String generatedCodeBlock = XMLToRecordConverter.convert(xmlFileContent, false, false, false, + "__text", true).getCodeBlock().replaceAll("\\s+", ""); + String expectedCodeBlock = Files.readString(sample36Bal).replaceAll("\\s+", ""); + Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); + } + + @Test(description = "textXMLWithDefaultNamespace3") + public void textXMLWithDefaultNamespace3() throws IOException { + String xmlFileContent = Files.readString(sample37XML); + String generatedCodeBlock = XMLToRecordConverter.convert(xmlFileContent, false, false, false, + "__text", true).getCodeBlock().replaceAll("\\s+", ""); + String expectedCodeBlock = Files.readString(sample37Bal).replaceAll("\\s+", ""); + Assert.assertEquals(generatedCodeBlock, expectedCodeBlock); + } } diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal new file mode 100644 index 000000000000..81739064e1ed --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal @@ -0,0 +1,37 @@ +@xmldata:Namespace { + uri: "example2.com" +} +type Ns2_Person record { + int __text; + @xmldata:Namespace { + uri: "example2.com" + } + @xmldata:Attribute + string age; + @xmldata:Namespace { + prefix: "ns2", uri: "example2.com" + } + @xmldata:Attribute + string name; +}; + +type Data record { + @xmldata:Namespace { + prefix: "ns2", uri: "example2.com" + } + Ns2_Person Person; + @xmldata:Namespace { + uri: "example.com" + } + string Message; +}; + +@xmldata:Namespace { + uri: "example.com" +} +type AQ record { + @xmldata:Namespace { + uri: "example.com" + } + Data Data; +}; diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal new file mode 100644 index 000000000000..9a459dcad1b2 --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal @@ -0,0 +1,62 @@ +@xmldata:Namespace { + uri: "example3.com" +} +type Ns2_Person record { + int __text; + @xmldata:Namespace { + prefix: "ns2", + uri: "example2.com" + } + @xmldata:Attribute + string age; + @xmldata:Namespace { + prefix: "ns2", + uri: "example2.com" + } + @xmldata:Attribute + string name; +}; + +type Ns1_Details record { + @xmldata:Namespace { + prefix: "ns1", + uri: "example1.com" + } + string Info; + @xmldata:Namespace { + prefix: "ns1", + uri: "example1.com" + } + string Status; +}; + +type Data record { + @xmldata:Namespace { + prefix: "ns2", + uri: "example2.com" + } + Ns2_Person Person; + @xmldata:Namespace { + uri: "example.com" + } + string C; + @xmldata:Namespace { + prefix: "ns1", + uri: "example1.com" + } + Ns1_Details Details; + @xmldata:Namespace { + uri: "example.com" + } + string B; +}; + +@xmldata:Namespace { + uri: "example.com" +} +type Test record { + @xmldata:Namespace { + uri: "example.com" + } + Data Data; +}; \ No newline at end of file diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal new file mode 100644 index 000000000000..09fb45290179 --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal @@ -0,0 +1,71 @@ +@xmldata:Namespace { + uri: "example3.com" +} +type Ns1_Person record { + int __text; + @xmldata:Namespace { + uri: "example3.com" + } + @xmldata:Attribute + string age; + @xmldata:Namespace { + uri: "example3.com" + } + @xmldata:Attribute + string city; + @xmldata:Namespace { + prefix: "ns1", + uri: "example1.com" + } + @xmldata:Attribute + string name; +}; + +type Ns2_Details record { + @xmldata:Namespace { + prefix: "ns2", + uri: "example.com" + } + string Info; + @xmldata:Namespace { + prefix: "ns2", + uri: "example.com" + } + string Status; + @xmldata:Namespace { + uri: "example2.com" + } + @xmldata:Attribute + string number; +}; + +type Data record { + @xmldata:Namespace { + prefix: "ns1", + uri: "example1.com" + } + Ns1_Person Person; + @xmldata:Namespace { + uri: "example2.com" + } + string Name; + @xmldata:Namespace { + prefix: "ns2", + uri: "example.com" + } + Ns2_Details Details; + @xmldata:Namespace { + uri: "example2.com" + } + string Description; +}; + +@xmldata:Namespace { + uri: "example2.com" +} +type Countries record { + @xmldata:Namespace { + uri: "example2.com" + } + Data Data; +}; diff --git a/misc/xml-to-record-converter/src/test/resources/xml/sample_35.xml b/misc/xml-to-record-converter/src/test/resources/xml/sample_35.xml new file mode 100644 index 000000000000..52c9280adadf --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/xml/sample_35.xml @@ -0,0 +1,6 @@ + + + 1 + Test + + diff --git a/misc/xml-to-record-converter/src/test/resources/xml/sample_36.xml b/misc/xml-to-record-converter/src/test/resources/xml/sample_36.xml new file mode 100644 index 000000000000..afc8c77fe40c --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/xml/sample_36.xml @@ -0,0 +1,11 @@ + + + 2 + Example + + Additional Info + Active + + Sample + + diff --git a/misc/xml-to-record-converter/src/test/resources/xml/sample_37.xml b/misc/xml-to-record-converter/src/test/resources/xml/sample_37.xml new file mode 100644 index 000000000000..b737df0e71e7 --- /dev/null +++ b/misc/xml-to-record-converter/src/test/resources/xml/sample_37.xml @@ -0,0 +1,11 @@ + + + 2 + Data Sample + + Additional Information + Active + + Sample Text + + From e306486d3491c8e64d902893c898f0ddd216dce4 Mon Sep 17 00:00:00 2001 From: mindula Date: Fri, 5 Jul 2024 17:54:50 +0530 Subject: [PATCH 4/6] Add missing new line --- .../src/test/resources/ballerina/sample_36.bal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal index 9a459dcad1b2..6ebf91718da9 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal @@ -59,4 +59,4 @@ type Test record { uri: "example.com" } Data Data; -}; \ No newline at end of file +}; From 92ba6444e85b1107cc9fd5cfc125d12408dbc2cc Mon Sep 17 00:00:00 2001 From: mindula Date: Fri, 5 Jul 2024 18:40:14 +0530 Subject: [PATCH 5/6] Fix failing tests --- .../xmltorecordconverter/XMLToRecordConverter.java | 2 +- .../src/test/resources/ballerina/sample_27.bal | 2 -- .../src/test/resources/ballerina/sample_35.bal | 10 +++++----- .../src/test/resources/ballerina/sample_36.bal | 1 + .../src/test/resources/ballerina/sample_37.bal | 10 +--------- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java index f759e2b60b93..5d89fe3fda14 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java @@ -308,7 +308,7 @@ private static List getRecordFieldsForXMLElement(Element xmlElement, boole if (((xmlNode.getPrefix() == null && XMLNS_PREFIX.equals(xmlNode.getLocalName())) || (XMLNS_PREFIX.equals(xmlNode.getPrefix()) && xmlNode.getLocalName().equals(xmlElement.getPrefix()))) && withNameSpace) { - String prefix = null; + String prefix = xmlElement.getPrefix(); if (xmlElement.getPrefix() != null && xmlElement.getPrefix().equals(xmlNode.getLocalName())) { prefix = xmlNode.getLocalName(); } diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal index 124d9b65c959..d6a3f4032e9f 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_27.bal @@ -19,8 +19,6 @@ type Item record { type Items record { Item[] item; - @xmldata:Attribute - string 'xmlns; }; type Order record { diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal index 81739064e1ed..4c6c14ffbc8b 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_35.bal @@ -1,15 +1,14 @@ @xmldata:Namespace { + prefix: "ns2", uri: "example2.com" } type Ns2_Person record { int __text; - @xmldata:Namespace { - uri: "example2.com" - } @xmldata:Attribute string age; @xmldata:Namespace { - prefix: "ns2", uri: "example2.com" + prefix: "ns2", + uri: "example2.com" } @xmldata:Attribute string name; @@ -17,7 +16,8 @@ type Ns2_Person record { type Data record { @xmldata:Namespace { - prefix: "ns2", uri: "example2.com" + prefix: "ns2", + uri: "example2.com" } Ns2_Person Person; @xmldata:Namespace { diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal index 6ebf91718da9..f8e88bd3b90a 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_36.bal @@ -1,4 +1,5 @@ @xmldata:Namespace { + prefix: "ns2", uri: "example3.com" } type Ns2_Person record { diff --git a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal index 09fb45290179..280803518d20 100644 --- a/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal +++ b/misc/xml-to-record-converter/src/test/resources/ballerina/sample_37.bal @@ -1,16 +1,11 @@ @xmldata:Namespace { + prefix: "ns1", uri: "example3.com" } type Ns1_Person record { int __text; - @xmldata:Namespace { - uri: "example3.com" - } @xmldata:Attribute string age; - @xmldata:Namespace { - uri: "example3.com" - } @xmldata:Attribute string city; @xmldata:Namespace { @@ -32,9 +27,6 @@ type Ns2_Details record { uri: "example.com" } string Status; - @xmldata:Namespace { - uri: "example2.com" - } @xmldata:Attribute string number; }; From c29b5a712d7a617a02684fe1a02cc83094a7bc5a Mon Sep 17 00:00:00 2001 From: mindula Date: Fri, 5 Jul 2024 19:28:01 +0530 Subject: [PATCH 6/6] Refactor the code --- .../ballerina/xmltorecordconverter/XMLToRecordConverter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java index 5d89fe3fda14..253e1507553e 100644 --- a/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java +++ b/misc/xml-to-record-converter/src/main/java/io/ballerina/xmltorecordconverter/XMLToRecordConverter.java @@ -332,10 +332,12 @@ private static List getRecordFieldsForXMLElement(Element xmlElement, boole return recordFields; } Token fieldType = getPrimitiveTypeName(xmlElement.getFirstChild().getNodeValue()); + TypeDescriptorNode fieldTypeName = NodeFactory.createBuiltinSimpleNameReferenceNode( + fieldType.kind(), fieldType); IdentifierToken fieldName = AbstractNodeFactory.createIdentifierToken(textFieldName == null ? escapeIdentifier("#content") : textFieldName); Token semicolon = AbstractNodeFactory.createToken(SyntaxKind.SEMICOLON_TOKEN); - RecordFieldNode recordFieldNode = NodeFactory.createRecordFieldNode(null, null, fieldType, + RecordFieldNode recordFieldNode = NodeFactory.createRecordFieldNode(null, null, fieldTypeName, fieldName, null, semicolon); recordFields.add(recordFieldNode); for (int j = 0; j < attributeLength; j++) {