Custom Code Generation Templates Variable Documentation
Answered
Hello,
Is there any documentation to describe what methods are available in the Velocity variables described here (Generate code | IntelliJ IDEA Documentation ) ? Unfortunately the existence of the variables is the only information I could find.
Ideally I would like to pull the generic off of the $classSignature to generate a subclass-aware builder-style setter. I tried doing that via String manipulation, but the IDE prevents it with a vague Incorrect method error.
Incorrect method '
public T setAppIdentifier(java.lang.String appIdentifier) {
this.appIdentifier = appIdentifier;
return self();
}'
Please sign in to leave a comment.
Hi Adam L, thank you for your question!
Could you please provide a generation template that you are using?
It will be helpful for further investigation. Thank you!
Hi Aleksandr,
Sure.
It is designed to work with a class like this:
Here is the template. (I could not find any documentation if there was a better way to extract the generic letter T for the template to work for any valid generic. $helper sounds promising, but I don't know what it can do.)
Thanks!
Adam
Adam L,Thanks for your update!
Unfortunately, with the current code implementation, it is challenging to address your use case.
I have created a new request — https://youtrack.jetbrains.com/issue/IDEA-384858/ — to improve the code generation system.
Please check whether it matches your expectations, and if you have any comments or suggestions, feel free to leave your feedback in the comments on that ticket.
Thank you!
Aleksandr,
Thank you very much for investigating and capturing it. It might be helpful if the request contained the expected output setter from my initial post, otherwise looks spot-on.
Also, (mostly for others searching in the future), thanks to your starting point of the GitHub repo link, I was able to find where the Velocity context is built for codegen so that others can see what methods are available for the classes like $helper: intellij-community/java/java-impl/src/org/jetbrains/java/generate/GenerationUtil.java at 1d2327359692c35f5b6106113c295fd20dc36008 · JetBrains/intellij-community
Best regards,
Adam
Adam, thank you for your reply.
I have updated this ticket IDEA-384858 and created an internal ticket to update our documentation. Feel free to subscribe and vote for this ticket.
See this article https://intellij-support.jetbrains.com/hc/en-us/articles/207241135 if you are not familiar with our bug tracking system.
We appreciate your efforts and cooperation!