I'm trying to rename a variable using AST and JDT:
At this point I can retrieve the ASTnode of the wanted variable, and the getNodeType()
method returns that the retrieved ASTnode is a "SimpleName",
Here is the code snippet that I use to set the variable name:
ASTNode an=nf.getCoveringNode();
SimpleName sn= ast.newSimpleName("rename_type");
if (an.getParent() instanceof SimpleType) {
SimpleType st= (SimpleType)an.getParent();
Name n=ast.newName("newname");
st.setName(n);
}
Now it throws:
java.lang.IllegalArgumentException: AST node cannot be modified.
Have you an idea how can I solve this?