Skip to content

Commit 1a53d51

Browse files
cushonError Prone Team
authored andcommitted
Handle changes to EndPosTable
Follow-up to 71324be PiperOrigin-RevId: 773878493
1 parent 06c8da0 commit 1a53d51

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

check_api/src/test/java/com/google/errorprone/fixes/AppliedFixTest.java

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626
import com.sun.source.tree.TreeVisitor;
2727
import com.sun.tools.javac.tree.EndPosTable;
2828
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;
3230
import org.junit.Test;
3331
import org.junit.runner.RunWith;
3432
import org.junit.runners.JUnit4;
@@ -39,29 +37,16 @@
3937
@RunWith(JUnit4.class)
4038
public class AppliedFixTest {
4139

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.
4242
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+
});
6550

6651
// TODO(b/67738557): consolidate helpers for creating fake trees
6752
JCTree node(int startPos, int endPos) {

0 commit comments

Comments
 (0)