Skip to content

Commit

Permalink
Remove usage of Guava 30 API (Comparators.min).
Browse files Browse the repository at this point in the history
This CL removes the only Guava 30 usage in auto-common, Comparators.min.

Motivation for change:
Currently when writing annotation processors in Bazel, the Guava version is pinned to the version used by JavaBuilder. For the latest Bazel release, 4.2.1, this version is pinned to Guava 29, which means we can't use the latest auto-common in our annotation processors due to the usage of Comparators.min.

Fwiw, Bazel 5.0 upgrades to Guava 30, but that version is still in the pre-release phase.

RELNOTES=Remove usage of Guava 30 API (Comparators.min).
PiperOrigin-RevId: 409461735
  • Loading branch information
bcorso authored and Google Java Core Libraries committed Nov 12, 2021
1 parent d6d9657 commit 102506c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions common/src/main/java/com/google/auto/common/Visibility.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.google.auto.common;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Comparators.min;
import static javax.lang.model.element.ElementKind.PACKAGE;

import com.google.common.base.Enums;
import com.google.common.collect.Ordering;
import java.util.Set;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -77,7 +77,9 @@ public static Visibility effectiveVisibilityOfElement(Element element) {
Visibility effectiveVisibility = PUBLIC;
Element currentElement = element;
while (currentElement != null) {
effectiveVisibility = min(effectiveVisibility, ofElement(currentElement));
// NOTE: We don't use Guava's Comparators.min() because that requires Guava 30, which would
// make this library unusable in annotation processors using Bazel < 5.0.
effectiveVisibility = Ordering.natural().min(effectiveVisibility, ofElement(currentElement));
currentElement = currentElement.getEnclosingElement();
}
return effectiveVisibility;
Expand Down

0 comments on commit 102506c

Please sign in to comment.