From d01767f707c5f1df0db407c48aa910afcfee1174 Mon Sep 17 00:00:00 2001 From: prakanth <50439067+prakanth97@users.noreply.github.com> Date: Thu, 11 Jul 2024 15:13:50 +0530 Subject: [PATCH] Refactor code --- .../lib/data/xmldata/utils/DataUtils.java | 15 ++------------- .../ballerina/lib/data/xmldata/xml/XmlParser.java | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java index 9dd62de..c10ace8 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java @@ -237,15 +237,13 @@ public static Object convertStringToExpType(BString value, Type expType) { } public static void validateRequiredFields(XmlAnalyzerData analyzerData) { - Map remainingFields = analyzerData.fieldHierarchy.peek().getMembers(); - for (Field field : remainingFields.values()) { + for (Field field : analyzerData.fieldHierarchy.peek().getMembers().values()) { if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); } } - Map remainingAttributes = analyzerData.attributeHierarchy.peek().getMembers(); - for (Field attribute : remainingAttributes.values()) { + for (Field attribute : analyzerData.attributeHierarchy.peek().getMembers().values()) { if (!SymbolFlags.isFlagOn(attribute.getFlags(), SymbolFlags.OPTIONAL)) { throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_ATTRIBUTE_NOT_PRESENT, attribute.getFieldName()); } @@ -260,15 +258,6 @@ public static boolean isStringValueAssignable(int typeTag) { return typeTag == TypeTags.STRING_TAG || typeTag == TypeTags.ANYDATA_TAG || typeTag == TypeTags.JSON_TAG; } - public static ArrayType getValidArrayType(Type type) { - return switch (type.getTag()) { - case TypeTags.ARRAY_TAG -> (ArrayType) type; - case TypeTags.ANYDATA_TAG -> PredefinedTypes.TYPE_ANYDATA_ARRAY; - case TypeTags.JSON_TAG -> PredefinedTypes.TYPE_JSON_ARRAY; - default -> null; - }; - } - public static BArray createArrayValue(Type type) { return switch (type.getTag()) { case TypeTags.ARRAY_TAG -> ValueCreator.createArrayValue((ArrayType) type); diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java index 8d60671..22d8e54 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java @@ -347,7 +347,6 @@ private void addTextToCurrentNodeIfExpTypeIsArray(ArrayType fieldType, BString b bText, xmlParserData); case TypeTags.ANYDATA_TAG, TypeTags.JSON_TAG -> { BArray tempArr = (BArray) ((BMap) xmlParserData.nodesStack.peek()).get(bFieldName); - // TODO: Using this -2 here seems strange for me. Find a better way to handle this. HashMap indexes = xmlParserData.arrayIndexes.get(xmlParserData.arrayIndexes.size() - 2); int currentIndex = indexes.get(bFieldName.getValue());