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.PRAGMA &&
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);
final String oldJavaName = "_" + info.getOldName();
final String newJavaName = "_" + info.getNewName();
ASTVisitor renameTokenJavaVisitor = new ASTVisitor() {
@Override
public boolean visit(SimpleName node) {
if (node.resolveBinding() != null &&
node.resolveBinding().getKind() == IBinding.VARIABLE &&
((IVariableBinding) node.resolveBinding()).isField() &&
node.getIdentifier().equals(oldJavaName))
{
//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,
oldJavaName.length(),
newJavaName);
fileChangeRootEdit.addChild(edit);
}
}
return super.visit(node);
}
};