Skip to content

Commit

Permalink
Add getSymbols(Predicate, LookupKind) compatibility method
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fawind authored and Error Prone Team committed Oct 19, 2021
1 parent b4d427c commit 543967b
Showing 1 changed file with 8 additions and 0 deletions.
Expand Up @@ -48,6 +48,11 @@ public Iterable<Symbol> getSymbols(Predicate<Symbol> predicate) {
return (Iterable<Symbol>) invoke(getSymbols, maybeAsFilter(predicate));
}

@SuppressWarnings("unchecked") // reflection
public Iterable<Symbol> getSymbols(Predicate<Symbol> predicate, LookupKind lookupKind) {
return (Iterable<Symbol>) invoke(getSymbolsLookupKind, maybeAsFilter(predicate), lookupKind);
}

public boolean anyMatch(Predicate<Symbol> predicate) {
return (boolean) invoke(anyMatch, maybeAsFilter(predicate));
}
Expand Down Expand Up @@ -75,6 +80,9 @@ private static Class<?> getFilterClass() {

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

private static final Method getSymbolsLookupKind =
getImpl("getSymbols", Predicate.class, LookupKind.class);

private static Method getImpl(String name, Class<?>... parameters) {
return FILTER_CLASS != null
? getMethodOrDie(
Expand Down

0 comments on commit 543967b

Please sign in to comment.