[
https://issues.apache.org/jira/browse/FREEMARKER-183?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17787648#comment-17787648
]
Dániel Dékány commented on FREEMARKER-183:
------------------------------------------
So this is without looking at source code, just a quick thought, maybe too
hastily again... But I will deal with pending FreeMarker issues in December,
and hopefully look int this more as well.
What you are saying (correct me if I'm wrong) is this, kind of. We add
something like `interface MethodCallAwareTemplateHashModel { TemplateModel
getBeforeCalled(String key) }`. The `MethodCall` AST node checks if its
left-hand-operand expression is a `Dot`, and if so, then it replaces it with
`DotBeforeMethodCall` (discarding the original `Dot` object in effect).
`DotBeforeMethodCall` will check if the left-hand-operand value of it is
`MethodCallAwareTemplateHashModel`, in which case it uses `getBeforeCalled`
instead of `get`, which will wrap a non-callable value into a
`TemplateMethodModelEx`, if the `MethodCallAwareTemplateHashModel`
implementation decides that that's a proper thing to do for the given key.
So this is of course quite horrible, but what can we do... It makes maintenance
more difficult (if that matters at this level of historical complexity...), and
it also adds some minor runtime overhead for everyone, regardless if you are
using records. I wonder if at this price, it's a better compromise just to
annoy users be forcing them to not use the `()`. That's how they should do it
anyway.
> Add support for Java records
> ----------------------------
>
> Key: FREEMARKER-183
> URL: https://issues.apache.org/jira/browse/FREEMARKER-183
> Project: Apache Freemarker
> Issue Type: Task
> Reporter: Dániel Dékány
> Assignee: Dániel Dékány
> Priority: Major
>
> Currently we don't support records (JEP 395), which was finalized in Java 16.
> Users can extend {{DefaultObjectWrapper}} for that of course, but it should
> be supported out of the box.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)