Search code examples
javaabstract-syntax-treeeclipse-jdt

how to get index of a node in ListRewrite of Eclipse JDT


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?


Solution

  • 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).