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 07:58 Go to next message
michel Labarre is currently offline michel Labarre
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 09:02 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 1001
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 05:15 Go to previous message
michel Labarre is currently offline michel Labarre
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: Tue Sep 02 00:22:44 EDT 2014

Powered by FUDForum. Page generated in 0.11638 seconds