Sunday, March 07, 2010

Eclipse Refactoring for legacy code

It has been quite sometime since I wrote anything on this blog, twitter probably spoiled me. If you are following me on twitter, you probably noticed announcement of  a small eclipse plugin for automated refactoring for Legacy Code. 

Before few months, I wrote an LTK refactoring mainly in Scala (yes, eclipse plugin in Scala language) to forward static method calls in a Java method to an instance method in same class. I am not really an expert at Scala (or functional programming for that matter) so the code is more of javaish Scala but I am improving and thats the best thing about Scala. This is also an attempt to prove how easy it is to write eclipse plugins in Scala and how seamlessly it integrates with Java source; Scala is not only a better language, it is much more suitable to deal with Eclipse APIs (you can define views etc. on extremely verbose interfaces like JDT AST).

Enough about Scala; the real purpose of the refactorings provided in this plugin would be to ease development with Legacy Java code, most of the code generators (think JavaCC) generate ugly Java code which is not only non unit testable but pain to comprehend and is often not usable with concurrent routines. Using this automated refactoring should make such code better. You can read more about the motivation behind the plugin in wiki.

For the performance heads who are worried about method chains introduced by this refactoring are encouraged to run their own "sane" micro-benchmarks to be sure JVM is really in-lining the method calls created by this refactoring.

The plugin is currently in beta and I am open for any new refactoring proposals. If you have any feedback, you are welcome to comment on this blog post or create a bug. The update site is here.


Andrew Eisenberg said...

A bit off topic, but how do you do the pde build of your scala-built plugin?

Nirav Thaker said...

PDE build is little bit painful with Scala. However if you build feature directly from Eclipse, it will use project builders (Scala builder from Scala IDE) and will jar up correctly.

However it doesn't work with RCP product export.

May be the only work around is to let PDE generate ANT script and modify it to compile scala sources separately?

Andrew Eisenberg said...

Good to know. I'm guessing that you need to select the "use class files compiled in the workspace" option.

The reason why I asked is that we have had the same problem with AspectJ-aware pde builds for a long time. We even wrote our own adaptation of the pde build plugin to fix it (but is never worked so well).

Recently, however, I worked with the pde team to get a workaround for this:

It works for AspectJ/AJDT, and it may work for you.

Nirav Thaker said...

Interesting, I will check it out. Thanks!

mensajes claro said...

Interesting, I will check it out.