I’m writing an Eclipse Plugin to do some simple code generation. I’m able to grab an IMethod representing the Method I need to modify, but I’m unsure how to actually write additional code in its body. I know this can be done with AST nodes, so is there a way to convert betwen IMethod and MethodDeclaration or something like that?
Share
IMethod is a class of JDT’s Java model while MethodDeclaration is a node class of the JDT AST. The Java model has no connection to the AST. But you can use the model to create an AST, typically ICompilationUnit (represents a Java source file) is used, although creating an AST from a string is also possible.
I would suggest checking out this article
Edit:
Possibly "no direct connection" would have been the better wording. In the JDT FAQ is the following: