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}
?
This solution is aimed at Eclipse 4.2 Juno, I have not tested this in any other environment.
All you have to do is pass your parameters, and then you'll have them available.
Say we wanted to create a TemplateVariableResolver that would uppercase the first letter of a passed parameter.
You'll first populate your plugin.xml as follows:
You'd also create your custom resolver:
public void resolve(TemplateVariable variable, TemplateContext context) {
if (variable.getVariableType().getParams().size() > 0) {
StringBuffer result = new StringBuffer();
for(String value : (List) variable.getVariableType().getParams()) {
value = value.substring(0,1).toUpperCase() + value.substring(1);
result.append(value);
}
variable.setValue(result.toString());
}
}
Finally in your code Template:
String name = ${Uppercase(jim,laughlin)};