Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you define your own template variables in Eclipse

Tags:

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.

like image 917
Jordi Avatar asked Jan 10 '09 18:01

Jordi


1 Answers

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.

like image 197
Urs Reupke Avatar answered Sep 21 '22 18:09

Urs Reupke