Inserting method declaration as last method in a type [message #258830] |
Mon, 23 February 2009 03:12  |
Eclipse User |
|
|
|
Originally posted by: marius.eich.gmx.de
Hi all,
I'm trying to insert a method into a java type using the ASTRewrite. I'm
building up the whole code and inserting it by using the following
statements:
ASTRewrite rewrite = ASTRewrite.create(ast);
ListRewrite listRewrite =
rewrite.getListRewrite(declaration,TypeDeclaration.BODY_DECL ARATIONS_PROPERTY);
listRewrite.insertLast(wrapperMethod, null);
declaration is of type TypeDeclaration and represents the type, in which the
method (wrapperMethod of type MethodDeclaration) is to be inserted.
My problem is that from time to time the method is inserted inside another
method already existing in the type declaration and that way the whole code
is messed up. I used listRewrite.insertLast() to achieve that the method is
always inserted as the last method in the type's body declarations behind
all existing methods. Why is this happening and what am I doing wrong?
Thanks in advance and best regards
Marius Eich
|
|
|
Re: Inserting method declaration as last method in a type [message #258838 is a reply to message #258830] |
Mon, 23 February 2009 10:22  |
Eclipse User |
|
|
|
Originally posted by: marius.eich.gmx.de
Hi again,
After a few more tests I found out that the insertion always goes wrong the
first time. If I delete the inserted code and trigger the insertion again,
the code will be inserted at the correct position. I still couldn't figure
out why this happens. Any ideas?
Thanks in advance and best regards
Marius Eich
"Marius Eich" <marius.eich@gmx.de> schrieb im Newsbeitrag
news:gntlps$jvm$1@build.eclipse.org...
> Hi all,
>
> I'm trying to insert a method into a java type using the ASTRewrite. I'm
> building up the whole code and inserting it by using the following
> statements:
> ASTRewrite rewrite = ASTRewrite.create(ast);
> ListRewrite listRewrite =
> rewrite.getListRewrite(declaration,TypeDeclaration.BODY_DECL ARATIONS_PROPERTY);
> listRewrite.insertLast(wrapperMethod, null);
>
> declaration is of type TypeDeclaration and represents the type, in which
> the method (wrapperMethod of type MethodDeclaration) is to be inserted.
>
> My problem is that from time to time the method is inserted inside another
> method already existing in the type declaration and that way the whole
> code is messed up. I used listRewrite.insertLast() to achieve that the
> method is always inserted as the last method in the type's body
> declarations behind all existing methods. Why is this happening and what
> am I doing wrong?
>
> Thanks in advance and best regards
> Marius Eich
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04561 seconds