refactoring java
- From: Lukasz <lkr76@xxxxx>
- Date: Tue, 26 Apr 2005 13:04:59 +0200
Hi,
I would like to replace spaghetti code built of if-else statements by
simple call to java Map; i.e.:
replace
"... else if (event == Consts.EVENT_ONE) handleOne()..."
by
"(Handler)(map.get(Consts.EVENT_ONE)).handle()"
Are there any tool which does it automatically?
Or should I write dedicated program to solve it?
While code generation is quite simple, the problem is with code analyzing.
In these case I have two problems to solve:
a) extract mapping: constant -> handle method
b) extract handle method code and put it into wrapper class (handler)
Are there any API which provides Java parse trees?
thx,
Lukasz
.