I have a .java src file that looks like this:
class Test {
public void foo () {
}
}
I would like to change foo () programmatically, in the sense, let's add sysout and do this:
public void foo () {
System.out.println ("hello world");
}
Are there any known ways to do this by NOT directly editing the src file (RandomAccessFile)?
Several posts in StackOverflow relate to CodeModel and Eclipse JDT AST for code generation purposes. I see that they will help in generating the code from scratch and will not modify the existing code. Is there an API that allows you to modify existing code and that has an API as simple as CodeModel / Eclipse JDT AST? If not, what would be the best way to do this?
source share