How to add a code snippet to method body with JDT/AST
问题 I'm trying to generate Java source code with JDT/AST. I now have MethodDeclaration and want to add a code snippet (from another source) to the method body. The code snippet can contain any Java code, even syntactically invalid code . I just can't find the way to do this. With JCodeModel you would use JBlock#directStatement(String s) method. Is there a way to do this with JDT/AST? 回答1: Since you have a well-formed tree for the rest of the application, and you want to insert non-well-formed