Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
prakanth97 committed Jul 11, 2024
1 parent 5c9d2b2 commit 5d81d66
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,13 @@ public static Object convertStringToExpType(BString value, Type expType) {
}

public static void validateRequiredFields(XmlAnalyzerData analyzerData) {
Map<QualifiedName, Field> 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<QualifiedName, Field> 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());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ private void addTextToCurrentNodeIfExpTypeIsArray(ArrayType fieldType, BString b
bText, xmlParserData);
case TypeTags.ANYDATA_TAG, TypeTags.JSON_TAG -> {
BArray tempArr = (BArray) ((BMap<BString, Object>) xmlParserData.nodesStack.peek()).get(bFieldName);
// TODO: Using this -2 here seems strange for me. Find a better way to handle this.
HashMap<String, Integer> indexes
= xmlParserData.arrayIndexes.get(xmlParserData.arrayIndexes.size() - 2);
int currentIndex = indexes.get(bFieldName.getValue());
Expand Down

0 comments on commit 5d81d66

Please sign in to comment.