Re: Can I use XDoclet to modify source code?
Thursday, January 31, 2008 08:58 AM
I'm actually not sure about xdoclet, but the java toolset does provide the ability for you to write an "annotation processing tool" (google for that term) which is directly designed for letting you do things programmatically in response to it reading source code. This includes writing modified versions of the source code. I've done something similar once to write a completely new Factory class based on presence of field methods once. Not *easy* necessarily, but quite doable. The other alternative is that you are asking for exactly what "aspect oriented programming" (google for that) addresses. It takes a little extra understanding of new terminology, but an AOP solution (I've played with AspectJ in the eclipse environment, and with Spring AOP otherise) does exactly that: add common pieces of code that runs on specified methods in specified classes... either before or after the code in the original method executes.