diff options
Diffstat (limited to 'android/guava')
7 files changed, 66 insertions, 20 deletions
diff --git a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java index 64e3e89ac..88c7d6b5c 100644 --- a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java +++ b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java @@ -17,7 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import javax.annotation.CheckForNull; /** * Skeletal implementation of {@link ImmutableSortedSet#descendingSet()}. @@ -25,6 +25,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl; * @author Louis Wasserman */ @GwtIncompatible +@ElementTypesAreNonnullByDefault final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { private final ImmutableSortedSet<E> forward; @@ -34,7 +35,7 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean contains(@NullableDecl Object object) { + public boolean contains(@CheckForNull Object object) { return forward.contains(object); } @@ -83,27 +84,31 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull public E lower(E element) { return forward.higher(element); } @Override + @CheckForNull public E floor(E element) { return forward.ceiling(element); } @Override + @CheckForNull public E ceiling(E element) { return forward.floor(element); } @Override + @CheckForNull public E higher(E element) { return forward.lower(element); } @Override - int indexOf(@NullableDecl Object target) { + int indexOf(@CheckForNull Object target) { int index = forward.indexOf(target); if (index == -1) { return index; diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java index b0bae12be..1f5001b8b 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java @@ -33,7 +33,6 @@ import java.util.NavigableMap; import java.util.SortedMap; import java.util.TreeMap; import javax.annotation.CheckForNull; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; /** * A {@link NavigableMap} whose contents will never change, with many other important properties @@ -53,6 +52,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl; * @since 2.0 (implements {@code NavigableMap} since 12.0) */ @GwtCompatible(serializable = true, emulated = true) +@ElementTypesAreNonnullByDefault public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxverideShim<K, V> implements NavigableMap<K, V> { @@ -558,7 +558,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride private final transient RegularImmutableSortedSet<K> keySet; private final transient ImmutableList<V> valueList; - private transient ImmutableSortedMap<K, V> descendingMap; + @CheckForNull private transient ImmutableSortedMap<K, V> descendingMap; ImmutableSortedMap(RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList) { this(keySet, valueList, null); @@ -567,7 +567,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride ImmutableSortedMap( RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList, - ImmutableSortedMap<K, V> descendingMap) { + @CheckForNull ImmutableSortedMap<K, V> descendingMap) { this.keySet = keySet; this.valueList = valueList; this.descendingMap = descendingMap; @@ -580,7 +580,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Override @CheckForNull - public V get(@NullableDecl Object key) { + public V get(@CheckForNull Object key) { int index = keySet.indexOf(key); return (index == -1) ? null : valueList.get(index); } @@ -860,6 +860,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final Entry<K, V> pollFirstEntry() { throw new UnsupportedOperationException(); } @@ -874,6 +875,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride @Deprecated @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final Entry<K, V> pollLastEntry() { throw new UnsupportedOperationException(); } diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java b/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java index 1e875a3b0..6fed81740 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.DoNotCall; /** * "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableSortedMap} @@ -26,6 +27,7 @@ import com.google.common.annotations.GwtIncompatible; * @author Chris Povirk */ @GwtIncompatible +@ElementTypesAreNonnullByDefault abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> { /** * Not supported. Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety, @@ -35,6 +37,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety. */ + @DoNotCall("Use naturalOrder") @Deprecated public static <K, V> ImmutableSortedMap.Builder<K, V> builder() { throw new UnsupportedOperationException(); @@ -46,6 +49,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @throws UnsupportedOperationException always * @deprecated Not supported for ImmutableSortedMap. */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") @Deprecated public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) { throw new UnsupportedOperationException(); @@ -60,6 +64,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass a key of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object)}.</b> */ + @DoNotCall("Pass a key of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) { throw new UnsupportedOperationException(); @@ -74,6 +79,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass keys of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) { throw new UnsupportedOperationException(); @@ -88,6 +94,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * @deprecated <b>Pass keys of type {@code Comparable} to use {@link * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) { throw new UnsupportedOperationException(); @@ -103,6 +110,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, * Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { throw new UnsupportedOperationException(); @@ -118,6 +126,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> * ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object, * Comparable, Object, Comparable, Object)}.</b> */ + @DoNotCall("Pass keys of type Comparable") @Deprecated public static <K, V> ImmutableSortedMap<K, V> of( K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java index e10b4d7a7..fabf599f1 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java @@ -35,7 +35,8 @@ import java.util.Comparator; import java.util.Iterator; import java.util.NavigableSet; import java.util.SortedSet; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import javax.annotation.CheckForNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A {@link NavigableSet} whose contents will never change, with many other important properties @@ -57,6 +58,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl; // TODO(benyu): benchmark and optimize all creation paths, which are a mess now @GwtCompatible(serializable = true, emulated = true) @SuppressWarnings("serial") // we're overriding default serialization +@ElementTypesAreNonnullByDefault public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E> implements NavigableSet<E>, SortedIterable<E> { static <E> RegularImmutableSortedSet<E> emptySet(Comparator<? super E> comparator) { @@ -507,16 +509,16 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride } } - int unsafeCompare(Object a, Object b) { + int unsafeCompare(Object a, @CheckForNull Object b) { return unsafeCompare(comparator, a, b); } - static int unsafeCompare(Comparator<?> comparator, Object a, Object b) { + static int unsafeCompare(Comparator<?> comparator, Object a, @CheckForNull Object b) { // Pretend the comparator can compare anything. If it turns out it can't - // compare a and b, we should get a CCE on the subsequent line. Only methods - // that are spec'd to throw CCE should call this. - @SuppressWarnings("unchecked") - Comparator<Object> unsafeComparator = (Comparator<Object>) comparator; + // compare a and b, we should get a CCE or NPE on the subsequent line. Only methods + // that are spec'd to throw CCE and NPE should call this. + @SuppressWarnings({"unchecked", "nullness"}) + Comparator<@Nullable Object> unsafeComparator = (Comparator<@Nullable Object>) comparator; return unsafeComparator.compare(a, b); } @@ -623,18 +625,21 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride /** @since 12.0 */ @GwtIncompatible // NavigableSet @Override + @CheckForNull public E lower(E e) { return Iterators.getNext(headSet(e, false).descendingIterator(), null); } /** @since 12.0 */ @Override + @CheckForNull public E floor(E e) { return Iterators.getNext(headSet(e, true).descendingIterator(), null); } /** @since 12.0 */ @Override + @CheckForNull public E ceiling(E e) { return Iterables.getFirst(tailSet(e, true), null); } @@ -642,6 +647,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride /** @since 12.0 */ @GwtIncompatible // NavigableSet @Override + @CheckForNull public E higher(E e) { return Iterables.getFirst(tailSet(e, false), null); } @@ -668,6 +674,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride @GwtIncompatible // NavigableSet @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final E pollFirst() { throw new UnsupportedOperationException(); } @@ -684,12 +691,14 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride @GwtIncompatible // NavigableSet @Override @DoNotCall("Always throws UnsupportedOperationException") + @CheckForNull public final E pollLast() { throw new UnsupportedOperationException(); } @GwtIncompatible // NavigableSet @LazyInit + @CheckForNull transient ImmutableSortedSet<E> descendingSet; /** @since 12.0 */ @@ -717,7 +726,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride public abstract UnmodifiableIterator<E> descendingIterator(); /** Returns the position of an element within the set, or -1 if not present. */ - abstract int indexOf(@NullableDecl Object target); + abstract int indexOf(@CheckForNull Object target); /* * This class is used to serialize all ImmutableSortedSet instances, diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java b/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java index 9d2af2c18..ca19d79db 100644 --- a/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java +++ b/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtIncompatible; +import com.google.errorprone.annotations.DoNotCall; /** * "Overrides" the {@link ImmutableSet} static methods that lack {@link ImmutableSortedSet} @@ -36,6 +37,7 @@ import com.google.common.annotations.GwtIncompatible; * @author Chris Povirk */ @GwtIncompatible +@ElementTypesAreNonnullByDefault abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { /** * Not supported. Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety, @@ -45,6 +47,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @throws UnsupportedOperationException always * @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety. */ + @DoNotCall("Use naturalOrder") @Deprecated public static <E> ImmutableSortedSet.Builder<E> builder() { throw new UnsupportedOperationException(); @@ -57,6 +60,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @throws UnsupportedOperationException always * @deprecated Not supported by ImmutableSortedSet. */ + @DoNotCall("Use naturalOrder (which does not accept an expected size)") @Deprecated public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) { throw new UnsupportedOperationException(); @@ -71,6 +75,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable)}.</b> */ + @DoNotCall("Pass a parameter of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E element) { throw new UnsupportedOperationException(); @@ -85,6 +90,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable)}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2) { throw new UnsupportedOperationException(); @@ -99,6 +105,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) { throw new UnsupportedOperationException(); @@ -113,6 +120,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) { throw new UnsupportedOperationException(); @@ -127,6 +135,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) { throw new UnsupportedOperationException(); @@ -142,6 +151,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable, * Comparable, Comparable...)}. </b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) { throw new UnsupportedOperationException(); @@ -156,6 +166,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> { * @deprecated <b>Pass parameters of type {@code Comparable} to use {@link * ImmutableSortedSet#copyOf(Comparable[])}.</b> */ + @DoNotCall("Pass parameters of type Comparable") @Deprecated public static <E> ImmutableSortedSet<E> copyOf(E[] elements) { throw new UnsupportedOperationException(); diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java index d70d8fb74..dd987988b 100644 --- a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java +++ b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java @@ -27,7 +27,8 @@ import java.util.Comparator; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import javax.annotation.CheckForNull; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An immutable sorted set with one or more elements. TODO(jlevy): Consider separate class for a @@ -38,6 +39,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl; */ @GwtCompatible(serializable = true, emulated = true) @SuppressWarnings({"serial", "rawtypes"}) +@ElementTypesAreNonnullByDefault final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET = new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural()); @@ -50,6 +52,8 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull + @Nullable Object[] internalArray() { return elements.internalArray(); } @@ -81,7 +85,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean contains(@NullableDecl Object o) { + public boolean contains(@CheckForNull Object o) { try { return o != null && unsafeBinarySearch(o) >= 0; } catch (ClassCastException e) { @@ -156,7 +160,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - public boolean equals(@NullableDecl Object object) { + public boolean equals(@CheckForNull Object object) { if (object == this) { return true; } @@ -209,24 +213,28 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override + @CheckForNull public E lower(E element) { int index = headIndex(element, false) - 1; return (index == -1) ? null : elements.get(index); } @Override + @CheckForNull public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); } @Override + @CheckForNull public E ceiling(E element) { int index = tailIndex(element, true); return (index == size()) ? null : elements.get(index); } @Override + @CheckForNull public E higher(E element) { int index = tailIndex(element, false); return (index == size()) ? null : elements.get(index); @@ -286,7 +294,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> { } @Override - int indexOf(@NullableDecl Object target) { + int indexOf(@CheckForNull Object target) { if (target == null) { return -1; } diff --git a/android/guava/src/com/google/common/collect/SortedIterable.java b/android/guava/src/com/google/common/collect/SortedIterable.java index d46e8afcd..64ec08ef3 100644 --- a/android/guava/src/com/google/common/collect/SortedIterable.java +++ b/android/guava/src/com/google/common/collect/SortedIterable.java @@ -17,6 +17,7 @@ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import java.util.Comparator; import java.util.Iterator; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An {@code Iterable} whose elements are sorted relative to a {@code Comparator}, typically @@ -25,7 +26,8 @@ import java.util.Iterator; * @author Louis Wasserman */ @GwtCompatible -interface SortedIterable<T> extends Iterable<T> { +@ElementTypesAreNonnullByDefault +interface SortedIterable<T extends @Nullable Object> extends Iterable<T> { /** * Returns the {@code Comparator} by which the elements of this iterable are ordered, or {@code * Ordering.natural()} if the elements are ordered by their natural ordering. |