java - How to use ASTRewrite to insert a code snippet insert a method's body? -


i´m using jdt in eclipse neon write java code generator plug-in. in moment have ast of correctly generated class , method empty body, 1 below:

// simplified question public class x {   public void x(void) {   } } 

now have code snippet in stringbuilder instance ready used code empty method body. code correctly written, so, after inserted, compile no errors.

after going through number of posts, foruns , jdt documentation, not find way insert code snippet in ast.

ps.: 1 of attemps use astparser class generate new ast snippet, in fact works. however, since snippet's ast not same target class ast, cannot used method body.

if have ast method body, can insert method after copying correct ast instance. see method org.eclipse.jdt.core.dom.astnode.copysubtree(ast, astnode)

alternatively, if control moment, when astrewrite produces textedits perhaps directly add insertedit of own, before edits applied. in scenario, finding correct offset insertion tricky part.


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -