calaedo
calaedo

Reputation: 333

Massive Eclipse AST Java Refactoring

Dear stackoverflow community!

I have to refactor a huge amount of java classes and want to do it automatized. I want to use Java JDT and write an eclipse plugin for this purpose.

Following 'problems' should be solved:

Thank you in advance and sorry for my English.

Upvotes: 0

Views: 355

Answers (1)

christoph.keimel
christoph.keimel

Reputation: 1240

If you don't know how to start, here is a good tutorial on how to use the AST and the Java Model in JDT: http://www.vogella.com/tutorials/EclipseJDT/article.html

If you do your refactoring in several steps, you could remove all throw declarations with generic exceptions first using your own plug-in leaving touched sources with compile errors. You can then start the quick fix manualy in the IDE. If you have huge amounts of changes, I would not recommend this approach.

It will be difficult to find a good entry point into the API itself, since you will probably want to do all the code changes in one "transaction". I have tried similar stuff in the past and always ended up coding the relevant parts myself, although reading the eclipse code realy helped alot! A good way to start is to use the "Plugin Spy" to find the relevant classes. (Shift+Alt+F1 or Shift+Option+F1 on Mac). It shows information for whatever is currently selected.

To create the throws block yourself you can inspect the code using the visitor pattern in AST and collect all thrown exceptions, if they are not included in a suitable catch-block.

The second requirement can be implemented straight forward with AST. You can have a look at the "Encapsulate Field" Refactoring of eclipse on how to do this (or use this feature if possible).

Upvotes: 1

Related Questions