Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple JDT example of code generation

I'm trying to write an Eclipse plugin. It will have dependencies on the RCP for basic stuff and JDT for Java code generation. It consists of a Wizard / WizardPage which asks for a package and a few class names. When the user hits "Finish", I want the wizard to create classes corresponding to the entered values into the current Java project.

I have the basic UI working. What I cannot figure out is how to generate the corresponding class code. Eclipse documentation is a bit hard to follow. From what I can glean I need to first obtain an IJavaProject from the workspace, from that an IPackageFragment and from that I can call createCompilationUnit() to make a class.

What I can't do is find any working examples. I assume that somehow I can walk from the workspace root to where I need to be and create the unit.

Can anyone offer some pointers to simple working code?

like image 369
locka Avatar asked Nov 28 '25 03:11

locka


1 Answers

You need to extend NewElementWizardPage and provide the functionality. See this documentation for more details

like image 198
Prakash G. R. Avatar answered Nov 30 '25 16:11

Prakash G. R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!