blob: 1c0b9311f577f6c1cf0b08a8ff96a828f138e65e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
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<Void> {
private final IdentityHashMap<JCTree, JCTree> originalToCopy = new IdentityHashMap<JCTree, JCTree>();
public TreeMirrorMaker(JavacNode node) {
super(node.getTreeMaker());
}
@Override public <T extends JCTree> T copy(T original) {
T copy = super.copy(original);
originalToCopy.put(original, copy);
return copy;
}
@Override public <T extends JCTree> T copy(T original, Void p) {
T copy = super.copy(original, p);
originalToCopy.put(original, copy);
return copy;
}
@Override public <T extends JCTree> List<T> copy(List<T> originals) {
List<T> copies = super.copy(originals);
Iterator<T> it1 = originals.iterator();
Iterator<T> it2 = copies.iterator();
while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next());
return copies;
}
@Override public <T extends JCTree> List<T> copy(List<T> originals, Void p) {
List<T> copies = super.copy(originals, p);
Iterator<T> it1 = originals.iterator();
Iterator<T> it2 = copies.iterator();
while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next());
return copies;
}
public Map<JCTree, JCTree> getOriginalToCopyMap() {
return Collections.unmodifiableMap(originalToCopy);
}
}
|