I want to create a plugin which defines a new code template (like this blog post). How can I pass a parameter into the template? like ${name:param}
?
views:
95answers:
1There aren't many things that you can pass into a code template. For example ${word_selection}
contains the current selection.
But what many people are missing is that you can define your own variables:
private static final ${type} ${name} = new ${type} (${cursor});
Neither ${type}
nor ${name}
are in the list which you get when you click the "Insert variable..." button. Eclipse notices and allows you to cycle through them with Tab and it will keep the content of these custom "template fields" in sync (so you the part after new
gets filled in if you type in the first field).
See this answer for other useful Eclipse templates.
[EDIT] According to the answers in the blog post which you mention, this is only possible at the moment with editor templates, not code templates. I suggest to file a bug against JDT Text to open the API for this.