IFile file = getFile(info.getAtgEditor());
TextFileChange textFileChange = new TextFileChange( file.getName(), file );
rootChange.add(textFileChange);
//a file change contains a tree of edits, first add the root of them
final MultiTextEdit fileChangeRootEdit = new MultiTextEdit();
textFileChange.setEdit(fileChangeRootEdit);
AtgAstVisitor renameTokenAtgVisitor = new AtgAstVisitor() {
@Override
public boolean visit(AbstractAtgAstNode node) {
if (node instanceof IdentNode) {
IdentNode identNode = (IdentNode) node;
if ((identNode.getKind() == IdentNode.Kind.PRODUCTION ||
identNode.getKind() == IdentNode.Kind.COMPILER) &&
identNode.getIdent().equals(info.getOldName())) {
//found ident to change
ReplaceEdit edit = new ReplaceEdit(
identNode.getRegion().getOffset(),
identNode.getRegion().getLength(),
info.getNewName());
fileChangeRootEdit.addChild(edit);
return false;
}
}
return true;
}
};
//visit atgAst
info.getAtgEditor()
.getAtgAstManager()
.getAtgAst()
.getRoot()
.accept(renameTokenAtgVisitor);
ASTVisitor renameTokenJavaVisitor = new ASTVisitor() {
@Override
public boolean visit(SimpleName node) {
if (node.resolveBinding() != null &&
node.resolveBinding().getKind() == IBinding.METHOD &&
node.getIdentifier().equals(info.getOldName()))
{
//map to ATG Position
int offset = info.getAtgEditor()
.getSyncer()
.mapToATG(node.getStartPosition(), node);
if (offset >= 0) {
//found token-ident to change
ReplaceEdit edit = new ReplaceEdit(
offset,
info.getOldName().length(),
info.getNewName());
fileChangeRootEdit.addChild(edit);
}
}
return super.visit(node);
}
};