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

Allow optional target type to be specified for JavaTemplate #4599

Open
knutwannheden opened this issue Oct 22, 2024 · 0 comments
Open

Allow optional target type to be specified for JavaTemplate #4599

knutwannheden opened this issue Oct 22, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@knutwannheden
Copy link
Contributor

knutwannheden commented Oct 22, 2024

When creating a JavaTemplate it should be possible to optionally specify a target type (as defined in the JLS). This is for example necessary when the template expression is only a method reference or a lambda and would unlock further Refaster use cases as well as declaring some more templates as context-free (like this example).

This idea would be for the JavaTemplate.Builder to declare a new targetType() method. Whether the parameter's type should be a plain String, JavaType, or even have both overloads would have to be explored.

Note that the target type would have to be included in the cache key for the context-free template cache.

An example would be a template like () -> 3 which would not be usable as a context-free template unless a matching target type like Supplier<Integer> is provided. This target type would then allow the code generator to generate a variable declaration for the template, like Supplier<Integer> o = () -> 3;.

@knutwannheden knutwannheden added the enhancement New feature or request label Oct 22, 2024
@knutwannheden knutwannheden changed the title Allow optional _target type_ to be specified for JavaTemplate Allow optional target type to be specified for JavaTemplate Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

1 participant