|
26 | 26 | import com.sun.source.tree.TreeVisitor;
|
27 | 27 | import com.sun.tools.javac.tree.EndPosTable;
|
28 | 28 | import com.sun.tools.javac.tree.JCTree;
|
29 |
| -import com.sun.tools.javac.util.Position; |
30 |
| -import java.util.HashMap; |
31 |
| -import java.util.Map; |
| 29 | +import java.lang.reflect.Proxy; |
32 | 30 | import org.junit.Test;
|
33 | 31 | import org.junit.runner.RunWith;
|
34 | 32 | import org.junit.runners.JUnit4;
|
|
39 | 37 | @RunWith(JUnit4.class)
|
40 | 38 | public class AppliedFixTest {
|
41 | 39 |
|
| 40 | + // This is unused by the test, it just needs to be non-null. |
| 41 | + // The proxy is necessary since the interface contains breaking changes across JDK versions. |
42 | 42 | final EndPosTable endPositions =
|
43 |
| - new EndPosTable() { |
44 |
| - |
45 |
| - final Map<JCTree, Integer> map = new HashMap<>(); |
46 |
| - |
47 |
| - @Override |
48 |
| - public void storeEnd(JCTree tree, int endpos) { |
49 |
| - map.put(tree, endpos); |
50 |
| - } |
51 |
| - |
52 |
| - @Override |
53 |
| - public int replaceTree(JCTree oldtree, JCTree newtree) { |
54 |
| - Integer endpos = map.getOrDefault(oldtree, Position.NOPOS); |
55 |
| - map.put(newtree, endpos); |
56 |
| - return endpos; |
57 |
| - } |
58 |
| - |
59 |
| - @Override |
60 |
| - public int getEndPos(JCTree tree) { |
61 |
| - Integer result = map.getOrDefault(tree, Position.NOPOS); |
62 |
| - return result; |
63 |
| - } |
64 |
| - }; |
| 43 | + (EndPosTable) |
| 44 | + Proxy.newProxyInstance( |
| 45 | + AppliedFixTest.class.getClassLoader(), |
| 46 | + new Class<?>[] {EndPosTable.class}, |
| 47 | + (proxy, method, args) -> { |
| 48 | + throw new UnsupportedOperationException(); |
| 49 | + }); |
65 | 50 |
|
66 | 51 | // TODO(b/67738557): consolidate helpers for creating fake trees
|
67 | 52 | JCTree node(int startPos, int endPos) {
|
|
0 commit comments