Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » replacing astNodes with type resolving
replacing astNodes with type resolving [message #670276] Fri, 13 May 2011 10:48 Go to next message
Andreas Kaluza is currently offline Andreas KaluzaFriend
Messages: 10
Registered: December 2010
Junior Member
Hi at all!

I'm trying to replace astNodes from different compilationUnits. By doing that, I cannot resolve the types from a replaced astNode.

An Example:
Button b1; //NodeToBeReplaced --> org.eclipse.swt.widgets.Button

should be replaced by:
Button b = new Button(null, 1); //replaceNode --> org.eclipse.swt.widgets.Button


For that, I use the astParser construct to get the astNodes I seek for. For these nodes I'm able to resolve the types (to get org.eclipse.swt.widgets.Button)

Now if I'm trying to replace the node (within a block), the types will not be resolved.

My replacing works like that:
Block parent = (Block) NodeToBeReplaced.getParent();
ASTNode astNodeCopied = ASTNode.copySubtree(NodeToBeReplaced.getAst(), replaceNode);
parent.statements().set(0, astNodeCopied);


The astNode astNodeCopied is not able to resolve the type.
((VariableDeclarationStatement) astNodeCopied).getType().resolveType();

leads to null.

Do you have a hint, how to realize this issue?

Best regards,

Andreas

[Updated on: Fri, 13 May 2011 10:49]

Report message to a moderator

Re: replacing astNodes with type resolving [message #670348 is a reply to message #670276] Fri, 13 May 2011 15:30 Go to previous message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
AST nodes cannot be modified directly. They have to be modified through ASTRewrite. Then, resolveType() cannot be used for new nodes.
Previous Topic:add a configuration to favorites
Next Topic:No Contents section in New Java Project wizard
Goto Forum:
  


Current Time: Tue Apr 23 10:12:21 GMT 2024

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

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

Back to the top