Can you define your own template variables in Eclipse
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.
Related videos on Youtube
Jordi
I have bachelor's and master's degrees in Artificial Intelligence and am currently pursuing a PhD on the topic. I'm also interested in machine learning and programming.
Updated on February 28, 2020Comments
-
Jordi over 4 years
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.
-
PEZ over 15 yearsThis is such a good question. I've often wanted to do this but never figured out if it's even possible. For the first time I just started to wish there was a way to subscribe to a question and get an e-mail message when answers arrive.
-
-
Jon over 12 yearsHey there, just found this post via Google, and unfortunately the blog post link you gave is broken. I don't suppose you know where to find a similar blog post? PlanetEclipse.org does not appear to have a search function (or any other way to navigate by date o search term), and my Google-Fu has failed me..
-
Urs Reupke over 12 yearsNo, sorry. Can't find it any longer.
-
chepseskaf over 12 yearsThe corresponding extension point is well documented org.eclipse.ui.editors.templates