Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Modify TypeDeclaration (class) with AST
Modify TypeDeclaration (class) with AST [message #1062921] Tue, 11 June 2013 11:58 Go to next message
michel Labarre is currently offline michel LabarreFriend
Messages: 7
Registered: July 2009
Junior Member
Hello
I want to add a SUPER_INTERFACE_TYPE on a TYPE_DECLARATION.
ie : I have a source java code with
public class Foo{...
and I want modify it with
public class Foo implements IBar {....

With a Visitor on TYPE_DECLARATION, I retrieve the good Node but I have not fount the correct method to add a SUPER_INTERFACE_TYPE to the ASTNode.

Can you help me?

Many thanks
Re: Modify TypeDeclaration (class) with AST [message #1062931 is a reply to message #1062921] Tue, 11 June 2013 13:02 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
the naive approach would be to call
typeDecl.superInterfaceTypes().add(newTypeNode);


Whether or not that is what you need depends on the context of this operation: when implementing a refactoring-like operation that should be written back into the source file you may need a snippet like this:

ASTRewrite rewrite= ASTRewrite.create(ast);
ListRewrite superInterfaces = rewrite.getListRewrite(typeDecl, TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY);
superInterfaces.insertLast(newTypeNode, editGroup);


If your unfamiliar with JDT's ast rewriting you should have a look at the javadoc of class ASTRewrite for a start.

HTH,
Stephan
Re: Modify TypeDeclaration (class) with AST [message #1063092 is a reply to message #1062931] Wed, 12 June 2013 09:15 Go to previous message
michel Labarre is currently offline michel LabarreFriend
Messages: 7
Registered: July 2009
Junior Member
Many thanks
Previous Topic:list of all available projects in eclipse workspace
Next Topic:java.lang.ClassNotFoundException at eclipse launch?
Goto Forum:
  


Current Time: Fri Apr 26 00:47:18 GMT 2024

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

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

Back to the top