Skip to content

Commit ef5052b

Browse files
cushonError Prone Team
authored andcommitted
Remove some obsolete logic now that the minimum supported JDK is 21
PiperOrigin-RevId: 808758850
1 parent 7b5a8ad commit ef5052b

File tree

4 files changed

+20
-83
lines changed

4 files changed

+20
-83
lines changed

check_api/src/main/java/com/google/errorprone/fixes/SuggestedFixes.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
import java.io.IOException;
110110
import java.io.UncheckedIOException;
111111
import java.lang.annotation.Target;
112-
import java.lang.reflect.Method;
113112
import java.net.JarURLConnection;
114113
import java.net.URI;
115114
import java.util.ArrayDeque;
@@ -498,15 +497,6 @@ public static void replaceDocTree(
498497

499498
private static int endPosition(
500499
DCTree.DCEndPosTree<?> node, DCTree.DCDocComment comment, DocTreePath docPath) {
501-
try {
502-
Method method = DCTree.DCEndPosTree.class.getMethod("getEndPos", DCTree.DCDocComment.class);
503-
return (int) method.invoke(node, comment);
504-
} catch (NoSuchMethodException e) {
505-
// continue below
506-
} catch (ReflectiveOperationException e) {
507-
throw new LinkageError(e.getMessage(), e);
508-
}
509-
510500
JCDiagnostic.DiagnosticPosition pos = node.pos(comment);
511501
EndPosTable endPositions =
512502
((JCCompilationUnit) docPath.getTreePath().getCompilationUnit()).endPositions;

check_api/src/main/java/com/google/errorprone/util/ASTHelpers.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,30 +1543,8 @@ private static boolean hasSimpleName(AnnotationTree annotation, String name) {
15431543
if (compound == null) {
15441544
return null;
15451545
}
1546-
return annotationTargetType(TypeAnnotations.instance(state.context), anno, compound, target);
1547-
}
1548-
1549-
private static AnnotationType annotationTargetType(
1550-
TypeAnnotations typeAnnotations,
1551-
AnnotationTree tree,
1552-
Compound compound,
1553-
@Nullable Symbol target) {
1554-
try {
1555-
try {
1556-
// the JCTree argument was added in JDK 21
1557-
return (AnnotationType)
1558-
TypeAnnotations.class
1559-
.getMethod("annotationTargetType", JCTree.class, Compound.class, Symbol.class)
1560-
.invoke(typeAnnotations, tree, compound, target);
1561-
} catch (NoSuchMethodException e1) {
1562-
return (AnnotationType)
1563-
TypeAnnotations.class
1564-
.getMethod("annotationTargetType", Compound.class, Symbol.class)
1565-
.invoke(typeAnnotations, compound, target);
1566-
}
1567-
} catch (ReflectiveOperationException e) {
1568-
throw new LinkageError(e.getMessage(), e);
1569-
}
1546+
return TypeAnnotations.instance(state.context)
1547+
.annotationTargetType((JCTree) anno, compound, target);
15701548
}
15711549

15721550
/**

check_api/src/main/java/com/google/errorprone/util/FindIdentifiers.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,15 @@ public static Symbol findIdent(String name, VisitorState state) {
117117
}
118118
}
119119

120-
// Signature was changed in Java 13: https://bugs.openjdk.java.net/browse/JDK-8223305
121120
private static Symbol findIdent(
122121
String name, VisitorState state, KindSelector kind, Env<AttrContext> env)
123122
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
124-
if (Runtime.version().feature() >= 13) {
125-
Method method =
126-
Resolve.class.getDeclaredMethod(
127-
"findIdent", DiagnosticPosition.class, Env.class, Name.class, KindSelector.class);
128-
method.setAccessible(true);
129-
return (Symbol)
130-
method.invoke(Resolve.instance(state.context), null, env, state.getName(name), kind);
131-
}
132123
Method method =
133-
Resolve.class.getDeclaredMethod("findIdent", Env.class, Name.class, KindSelector.class);
124+
Resolve.class.getDeclaredMethod(
125+
"findIdent", DiagnosticPosition.class, Env.class, Name.class, KindSelector.class);
134126
method.setAccessible(true);
135-
return (Symbol) method.invoke(Resolve.instance(state.context), env, state.getName(name), kind);
127+
return (Symbol)
128+
method.invoke(Resolve.instance(state.context), null, env, state.getName(name), kind);
136129
}
137130

138131
private static @Nullable ClassTree getEnclosingClass(TreePath treePath) {

core/src/main/java/com/google/errorprone/refaster/PlaceholderUnificationVisitor.java

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.sun.source.tree.BinaryTree;
3030
import com.sun.source.tree.BlockTree;
3131
import com.sun.source.tree.CaseTree;
32-
import com.sun.source.tree.CaseTree.CaseKind;
3332
import com.sun.source.tree.CatchTree;
3433
import com.sun.source.tree.CompoundAssignmentTree;
3534
import com.sun.source.tree.ConditionalExpressionTree;
@@ -652,43 +651,20 @@ public Choice<State<JCSwitch>> visitSwitch(SwitchTree node, State<?> state) {
652651

653652
@Override
654653
public Choice<State<JCCase>> visitCase(CaseTree node, State<?> state) {
655-
if (Runtime.version().feature() >= 21) {
656-
return chooseSubtrees(
657-
state,
658-
s -> unify(node.getLabels(), s),
659-
s -> unifyExpression(node.getGuard(), s),
660-
s -> unifyStatements(node.getStatements(), s),
661-
s -> unify(node.getBody(), s),
662-
(labels, guard, stmts, body) ->
663-
maker()
664-
.Case(
665-
node.getCaseKind(),
666-
List.convert(JCCaseLabel.class, labels),
667-
guard,
668-
stmts,
669-
body));
670-
} else {
671-
return chooseSubtrees(
672-
state,
673-
s -> unify(node.getLabels(), s),
674-
s -> unifyStatements(node.getStatements(), s),
675-
s -> unify(node.getBody(), s),
676-
(labels, stmts, body) -> {
677-
try {
678-
return (JCCase)
679-
TreeMaker.class
680-
.getMethod("Case", CaseKind.class, List.class, List.class, JCTree.class)
681-
.invoke(
682-
maker(),
683-
node.getCaseKind(),
684-
List.convert(JCCaseLabel.class, labels),
685-
stmts,
686-
body);
687-
} catch (ReflectiveOperationException e) {
688-
throw new LinkageError(e.getMessage(), e);
689-
}
690-
});
691-
}
654+
return chooseSubtrees(
655+
state,
656+
s -> unify(node.getLabels(), s),
657+
s -> unifyExpression(node.getGuard(), s),
658+
s -> unifyStatements(node.getStatements(), s),
659+
s -> unify(node.getBody(), s),
660+
(labels, guard, stmts, body) ->
661+
maker()
662+
.Case(
663+
node.getCaseKind(),
664+
List.convert(JCCaseLabel.class, labels),
665+
guard,
666+
stmts,
667+
body));
692668
}
693669

694670
@Override

0 commit comments

Comments
 (0)