Skip to content

Conversation

@HT154
Copy link
Contributor

@HT154 HT154 commented Nov 25, 2025

This has been banging around in my head for a while and I finally needed to get it out.

This PR adds a new property BaseValueRenderer#annotationConverters that enables defining converters that act on both the property name and value of annotated properties of Typed values.

This enables defining declarative key and/or value transformations in cases where neither Class- nor path-based converters can be applied gracefully. It is also the only way to express transforming the resulting property names in Typed objects without applying a converter to the entire containing type, which is cumbersome at best.

This PR originally overloaded BaseValueRenderer#converters for this purpose. This implementation has been preserved in the first commit in the PR if you wish to compare that to implementation with the new property. A limitation of the previous design is that you can't have both a class and annotation converter for the same Annotation subclass (though this is probably unlikely to be an issue in practice).

SPICE: apple/pkl-evolution#26

This also fixes a silly wart in the API for getting class property mirrors.

Resolves #576

@HT154 HT154 force-pushed the annotation-converters branch from f34bd77 to 1870188 Compare November 29, 2025 20:40
@HT154 HT154 force-pushed the annotation-converters branch from 1870188 to 274ba33 Compare November 29, 2025 20:57
@HT154 HT154 changed the title Add Annotation-based converters SPICE-0024: Annotation converters Dec 12, 2025
@HT154 HT154 force-pushed the annotation-converters branch 2 times, most recently from 97ac0af to df576b6 Compare December 22, 2025 23:38
Comment on lines +23 to +29
import "pkl:json"
import "pkl:jsonnet"
import "pkl:math"
import "pkl:pklbinary"
import "pkl:protobuf"
import "pkl:xml"
import "pkl:yaml"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that these modules are unused by functional code, but are required to correctly resolve doc comment references.

@HT154 HT154 force-pushed the annotation-converters branch from df576b6 to 2d813fe Compare December 23, 2025 01:08
@HT154 HT154 force-pushed the annotation-converters branch from 2d813fe to 192ed70 Compare December 23, 2025 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output converters should allow selection for properties by Annotation

1 participant