From 102506c383e4e8165a1d8e23247549915d3ebcfb Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Fri, 12 Nov 2021 11:36:01 -0800 Subject: Remove usage of Guava 30 API (Comparators.min). 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 --- common/src/main/java/com/google/auto/common/Visibility.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/src/main/java/com/google/auto/common/Visibility.java b/common/src/main/java/com/google/auto/common/Visibility.java index 36f4ad6d..db15f8bd 100644 --- a/common/src/main/java/com/google/auto/common/Visibility.java +++ b/common/src/main/java/com/google/auto/common/Visibility.java @@ -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; @@ -77,7 +77,9 @@ public enum Visibility { 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; -- cgit v1.2.3