package lombok.javac; import java.util.Collections; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.TreeCopier; import com.sun.tools.javac.util.List; public class TreeMirrorMaker extends TreeCopier { private final IdentityHashMap originalToCopy = new IdentityHashMap(); public TreeMirrorMaker(JavacNode node) { super(node.getTreeMaker()); } @Override public T copy(T original) { T copy = super.copy(original); originalToCopy.put(original, copy); return copy; } @Override public T copy(T original, Void p) { T copy = super.copy(original, p); originalToCopy.put(original, copy); return copy; } @Override public List copy(List originals) { List copies = super.copy(originals); if (originals != null) { Iterator it1 = originals.iterator(); Iterator it2 = copies.iterator(); while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next()); } return copies; } @Override public List copy(List originals, Void p) { List copies = super.copy(originals, p); if (originals != null) { Iterator it1 = originals.iterator(); Iterator it2 = copies.iterator(); while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next()); } return copies; } public Map getOriginalToCopyMap() { return Collections.unmodifiableMap(originalToCopy); } }