Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Inserting method declaration as last method in a type
Inserting method declaration as last method in a type [message #258830] Mon, 23 February 2009 03:12 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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
>
>
Previous Topic:How to find specific .java files
Next Topic:Joint Compillation Java / Groovy at the Groovy Eclipse Plug-in
Goto Forum:
  


Current Time: Thu Apr 17 10:24:11 EDT 2025

Powered by FUDForum. Page generated in 0.04259 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top