Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in value attributes #317

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be using the value's attributes, not the field's 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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a fallback for fields that have attributes set on them that really only apply to the value.

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());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the value's attributes.

displayComma = i < fieldList.size();
}
}
Expand Down
Loading