Skip to content

Commit 543967b

Browse files
fawindError Prone Team
authored andcommitted
Add getSymbols(Predicate, LookupKind) compatibility method
Add a compatibility helper method for `getSymbols(Predicate<Symbol>, LookupKind)`. **Context:** In [gradle-baseline](https://github.com/palantir/gradle-baseline#baseline-error-prone-checks), we maintain our own set of error-prone rules and ran into similar JDK 17 compatibility problems as mentioned in #2330. However for our custom rules, we also need a compatibility helper for `getSymbols(Predicate, LookupKind)`. For now, we work around this by copying parts of the `ErrorProneScope` class (([PR](palantir/gradle-baseline#1936))) but ideally we could reuse the existing helper and wouldn't have to maintain our own fork of this class. Fixes #2629 COPYBARA_INTEGRATE_REVIEW=#2629 from fawind:fw/get-symbols-lookup-kind e843406 PiperOrigin-RevId: 404111704
1 parent b4d427c commit 543967b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public Iterable<Symbol> getSymbols(Predicate<Symbol> predicate) {
4848
return (Iterable<Symbol>) invoke(getSymbols, maybeAsFilter(predicate));
4949
}
5050

51+
@SuppressWarnings("unchecked") // reflection
52+
public Iterable<Symbol> getSymbols(Predicate<Symbol> predicate, LookupKind lookupKind) {
53+
return (Iterable<Symbol>) invoke(getSymbolsLookupKind, maybeAsFilter(predicate), lookupKind);
54+
}
55+
5156
public boolean anyMatch(Predicate<Symbol> predicate) {
5257
return (boolean) invoke(anyMatch, maybeAsFilter(predicate));
5358
}
@@ -75,6 +80,9 @@ private static Class<?> getFilterClass() {
7580

7681
private static final Method getSymbols = getImpl("getSymbols", Predicate.class);
7782

83+
private static final Method getSymbolsLookupKind =
84+
getImpl("getSymbols", Predicate.class, LookupKind.class);
85+
7886
private static Method getImpl(String name, Class<?>... parameters) {
7987
return FILTER_CLASS != null
8088
? getMethodOrDie(

0 commit comments

Comments
 (0)