If I were you I'd look at the org.eclipse.jdt.core.dom package. Look
through the classes AST and ASTRewrite (which is actually in
org.eclipse.jdt.core.dom.rewrite). You can modify the existing AST of the
file using the ASTRewrite class, along with the ListRewrite class. There
is pretty good documentation on this on eclipse's help website, once
you've found the classes.