Skip to content

Commit

Permalink
Fix bug in value attributes (#317)
Browse files Browse the repository at this point in the history
* Fix bug in value attributes

* fmt
  • Loading branch information
wsargent authored Apr 15, 2024
1 parent a0d07a5 commit 9ec662b
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,27 @@ public String formatField(@NotNull Field field) {
assert fieldVisitor != null;
field = fieldVisitor.visit(field);
}
formatValue(builder, field.value(), attributes);

Attributes valueAttributes =
collectValueAttributes(field.attributes(), field.value().attributes());
formatValue(builder, field.value(), valueAttributes);
return builder.toString();
}

// if the field has elided, tostringvalue, abbreviateafter, or ascardinal,
// it should apply to the value instead.
Attributes collectValueAttributes(Attributes fa, Attributes valueAttributes) {
if (fa.containsKey(ABBREVIATE_AFTER)) {
return valueAttributes.plus(abbreviateAfter(fa.get(ABBREVIATE_AFTER)));
} else if (fa.containsKey(AS_CARDINAL)) {
return valueAttributes.plus(asCardinal());
} else if (fa.containsKey(TOSTRING_VALUE)) {
return valueAttributes.plus(withToStringValue(fa.get(TOSTRING_VALUE)));
} else {
return valueAttributes;
}
}

@NotNull
@Override
public String formatValue(@NotNull Value<?> value) {
Expand Down Expand Up @@ -135,7 +152,7 @@ private void formatObject(@NotNull StringBuilder b, @NotNull Value.ObjectValue v
assert fieldVisitor != null;
field = fieldVisitor.visit(field);
}
formatValue(b, field.value(), attributes);
formatValue(b, field.value(), field.value().attributes());
displayComma = i < fieldList.size();
}
}
Expand Down

0 comments on commit 9ec662b

Please sign in to comment.