I am using Eclipse JDT to modify the AST of a source code. I want to modify a MethodDeclaration
node. For that, I visited that using ASTVisitor
and made changes. Now I removed the past node and am trying to add the new one at the same place using ListRewrite.insertAt()
method. For that I want to get the index of the node before removing it. How can I get the index?
Why not call ListRewrite.replace()
instead of first removing then adding?
If that doesn't serve your purpose for some reason, try listRewrite.getOriginalList().indexOf(oldNode)
.
You can use an empty statement as a place holder and first replace this node with empty statement. Then make changes to your node. Then replace the empty statement with your node. This looks like a hack but works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.