In Eclipse there are templates that help you by automatically inserting some code or comments. You can edit these templates yourself via Preferences > Java > Editor > Templates. There are so-called "template variables" that you can use to make these templates a little smarter.
For instance, there is the ${see_to_overridden} variable that inserts "@see my.package.name.SpuerclassName#methodName(int, my.other.package.SomeType, ...)" into a javadoc comment. It would be really great if I could define my own variables, so that I could obtain Superclassname, SomeType etc. without having the "@see" thing prepended to it so that I could for instance link to the appropriate method. There appear to exist no template variables for this, so I was wondering if there was any way to create your own template variables.
According to this Blog post (alternative link) by the eclipse team, you can.
Extend org.eclipse.ui.editors.templates, add a org.eclipse.jface.text.templates.TemplateVariableResolver and fill in the values required by the system. They should be self explanatory if you ever defined your own template.
Then implement the resolver, replacing your variable with a appropriate string.
The Blog post holds more details and screenshots.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With