I am trying to copy a method declaration from the first AST (where the method declaration originally resides) to another AST. What I tried to do was to copy the method declaration using the ASTRewrite of the original compilation unit, which then I add to the ListRewrite of the second compilation unit in the code below.
MethodDeclaration newMethodDeclaration = (MethodDeclaration) oldCURewrite.createCopyTarget(oldMethodDeclaration);
astRewrite.getListRewrite(typeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY).insertAfter(newMethodDeclaration, constructor, null);
However, this gives me a MISSING method declaration and not the correct one. No exceptions are being thrown during the procedure. Is there any standard way to do the copy or do I have to create all child nodes of the method declarations from start? (which will be too difficult, if possible)
thanks
I managed to copy the method using the copySubtree(AST target, ASTNode node) static method of the ASTNode class. The first parameter is for the target ast.