Search code examples
javaeclipseeclipse-plugineclipse-templates

New File Wizard eclipse plugin with pre decided code template


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.


Solution

  • 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