Bug 269811 - [templates] New template variable userMail
Summary: [templates] New template variable userMail
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-24 07:42 EDT by Philipp Kursawe CLA
Modified: 2009-03-24 10:20 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Kursawe CLA 2009-03-24 07:42:21 EDT
We often change the default template for types to include the E-Mail of the author in the @author tag. It would be helpful if Eclipse would provide a way to have a new template variable like "userMail" that could be something like this: <a href="mailto:user.name">user.name</a>.

Is there any way to extend the available template Variables?

The userMail would have to be configured in the preferences or taken from the command line Eclipse was started with.

I think that would introduce a new TemplateVariableResolver?
Comment 1 Dani Megert CLA 2009-03-24 07:51:12 EDT
Are you talking about code templates or editor templates?
Comment 2 Philipp Kursawe CLA 2009-03-24 08:05:50 EDT
Editor templates. The one you set for Types and files.
Comment 3 Philipp Kursawe CLA 2009-03-24 08:12:43 EDT
Actually the "user" variable is currently used in both Editor and Code templates. I would just like to introduce a new TemplateVariableResolver that provides a value that you can edit on the preference pages. Maybe there is already a "Template Variables" preference page? There you could enter new Variables that could be used in templates. Or provide a way to have more dynamic variable resolvers that would allow you to have a variable like "system.xxx" where xxx would be any system property. That way you would not have to code new Variable Resolvers again and again for each system property. For instance if we in the company have a environment variable like "COMPANY_NAME" I could have easily this name in all our file headers by having a code template:
/**
  Copyright {year} {system.companyname}
*/

Or is that not a good idea anyway?
Comment 4 Dani Megert CLA 2009-03-24 08:15:30 EDT
>Editor templates. The one you set for Types and files.
Well see, that's just the opposite ;-)

Editor templates are those entered during editing, defined on Java > Editor > Templates.

Code templates are those used for code generation, defined on Java > Code Style > Code Templates.

The definition of the resolver would go into org.eclipse.jface.text.templates.GlobalTemplateVariables and would then have to be used/referenced by the two mechanisms.
Comment 5 Philipp Kursawe CLA 2009-03-24 08:22:16 EDT
Yeah I found out about the GlobaleTemplateVariables already. I think its easy for me to provide a patch for such a new variable. However do you think the mechanism described in my comment #3 is a better solution? Or even provide an extension point for template variables?
Comment 6 Dani Megert CLA 2009-03-24 09:02:20 EDT
> Or even provide an extension point for template variables?
See: org.eclipse.ui.editors.templates. The problem is that those are currently only visible for editor templates and not for code templates.

Adding additional preference for that seems overkill given how easy it is to write a plug-in if someone needs additional variables.
Comment 7 Philipp Kursawe CLA 2009-03-24 09:09:03 EDT
so this new variable could be created as an org.eclipse.ui.editors.templates resolver extension? But that would not work in the Code templates as the code templates do not yet use this extension point?
Comment 8 Markus Keller CLA 2009-03-24 09:10:56 EDT
See bug 45251 for using system properties (but use a syntax for passing
arguments to code template variables that matches the mechanism for advanced
editor template variables).
Comment 9 Philipp Kursawe CLA 2009-03-24 09:30:14 EDT
Thanks Markus, whats the mechanism for advanced editor template variables? Where can I read about it?
Comment 10 Markus Keller CLA 2009-03-24 10:20:43 EDT
> Thanks Markus, whats the mechanism for advanced editor template variables?

See the help for 'Template Variables' when you're in the edit dialog for Java > Editor > Templates. The syntax is described in org.eclipse.jface.text.templates.TemplateTranslator.