How to have several templates for Java files in Eclipse?
I'd like to have several different templates for new java files in Eclipse. Is this possible?
Basically when I am creating a new Java class file in Package Explorer I'd like to use a template X as a base for new file, when I am creating a new unit test class I'd like to use template Y, when I am creating a Wicket component class I'd like to use template Z, etc.
Also is it possible to configure Eclipse so that when I create a new Java class, Eclipse开发者_Go百科 will generate corresponding new unit test class automatically?
I am not sure if this is what you want, but you can add new wizards to Eclipse using the org.eclipse.ui.newWizards
extension point.
Here is the corresponding documentation in Eclipse help.
Another (less elegant) way of doing this is to add your own templates (e.g. DAO) under the Java editor (Window->Preferences->Java->Editor->Templates)
so when you type DAO and Ctrl + Enter it, it expands to the full template you want. This way creating a new empty file, typing DAO and autocompleting would transform into a full file snippet.
Hope it helps!
精彩评论