I want to create a eclipse plugin for a new file wizard.This wizard asks about package name and class name of the file and based on two specific class type choices(can be choosen form drop down) it generates java file with pre build template having methods and variable declaration (but class name and package name based on user choice). Please suggest me how to do it.
Asked
Active
Viewed 1,301 times
0
-
Assuming you have the Eclipse RCP package, read the source code for the Eclipse New File Wizard, and emulate it for your purpose. – Gilbert Le Blanc Jan 07 '13 at 18:33
-
@GilbertLeBlanc How to change the name of class and package in that case? – WitVault Jan 07 '13 at 18:44
-
If I was answering you, I'd show you a picture. Select New Java class in Eclipse. The source folder, package name, and class name are the first 3 entry fields. – Gilbert Le Blanc Jan 07 '13 at 18:50
1 Answers
1
Using JET (Java Emitter Templates) this can be achieved easily.
Steps:
1) create a template file which have the program structure. There will be place holders for dynamic inputs like class name and package name in your case.
Links: Vogella, Tutorial 1 and Tutorial 2
2) In the runtime pass these dynamic values and execute the template will give you the Class contents in the form of String.
3) Using JDT API you can easily create package, class etc with this contents.
Links : JDT Sample and JDT API

Syam
- 1,202
- 11
- 23