aspect ASTReplace { // copied from the Java1.4Backend Transformations.jrag // imperative transformation of the AST // syntax ASTNode.replace(sourcenode).with(destnode) // this syntax is used to allow for building the destnode using the sourcenode protected ASTNode ASTNode.replace(ASTNode node) { int pos = node.getParent().getIndexOfChild(node); if(pos == -1) throw new Error("invalid replacement position"); state().replacePos = pos; node.getParent().in$Circle(true); return node.getParent(); } protected ASTNode ASTNode.with(ASTNode node) { int pos = state().replacePos; if(pos == -1) throw new Error("invalid replacement position"); ((ASTNode)this).setChild(node, pos); in$Circle(false); return node; } public int ASTNode$State.replacePos = 0; }