Skip to content

Commit

Permalink
Add sign annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
markro49 authored Jun 8, 2023
1 parent b533232 commit 1b6f8cf
Show file tree
Hide file tree
Showing 146 changed files with 326 additions and 236 deletions.
2 changes: 1 addition & 1 deletion guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>3.34.0</version>
<version>3.35.0</version>
</dependency>
</dependencies>
<build>
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Absent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.framework.qual.AnnotatedFor;

/** Implementation of an {@link Optional} not containing a reference. */
Expand Down Expand Up @@ -89,7 +90,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness Absent<T> this) {
return 0x79a31aac;
}

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/CaseFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.checkerframework.checker.index.qual.IndexOrHigh;
import org.checkerframework.checker.index.qual.LTEqLengthOf;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.common.value.qual.ArrayLen;

/**
Expand Down Expand Up @@ -200,7 +201,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness StringConverter this) {
return sourceFormat.hashCode() ^ targetFormat.hashCode();
}

Expand Down
7 changes: 4 additions & 3 deletions guava/src/com/google/common/base/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
* A function from {@code A} to {@code B} with an associated <i>reverse</i> function from {@code B}
Expand Down Expand Up @@ -369,7 +370,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness ReverseConverter<A, B> this) {
return ~original.hashCode();
}

Expand Down Expand Up @@ -446,7 +447,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness ConverterComposition<A, B, C> this) {
return 31 * first.hashCode() + second.hashCode();
}

Expand Down Expand Up @@ -572,7 +573,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness FunctionBasedConverter<A, B> this) {
return forwardFunction.hashCode() * 31 + backwardFunction.hashCode();
}

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Enums.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.WeakHashMap;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.framework.qual.AnnotatedFor;

/**
Expand Down Expand Up @@ -141,7 +142,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness StringConverter<T> this) {
return enumClass.hashCode();
}

Expand Down
5 changes: 3 additions & 2 deletions guava/src/com/google/common/base/Equivalence.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.function.BiPredicate;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
* A strategy for determining whether two instances are considered equivalent, and for computing
Expand Down Expand Up @@ -267,7 +268,7 @@ public boolean equals(@CheckForNull Object obj) {

/** Returns the result of {@link Equivalence#hash(Object)} applied to the wrapped reference. */
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness Wrapper<T> this) {
return equivalence.hash(reference);
}

Expand Down Expand Up @@ -340,7 +341,7 @@ public boolean equals(@CheckForNull Object obj) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness EquivalentToPredicate<T> this) {
return Objects.hashCode(equivalence, target);
}

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/FunctionalEquivalence.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
* Equivalence applied on functional result.
Expand Down Expand Up @@ -67,7 +68,7 @@ public boolean equals(@CheckForNull Object obj) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness FunctionalEquivalence<F, T> this) {
return Objects.hashCode(function, resultEquivalence);
}

Expand Down
13 changes: 7 additions & 6 deletions guava/src/com/google/common/base/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;

Expand Down Expand Up @@ -173,7 +174,7 @@ public boolean equals(@CheckForNull Object o) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness FunctionForMapNoDefault<K, V> this) {
return map.hashCode();
}

Expand Down Expand Up @@ -218,7 +219,7 @@ public boolean equals(@CheckForNull Object o) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness ForMapWithDefault<K,V> this) {
return Objects.hashCode(map, defaultValue);
}

Expand Down Expand Up @@ -278,7 +279,7 @@ public boolean equals(@CheckForNull Object obj) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness FunctionComposition<A, B, C> this) {
return f.hashCode() ^ g.hashCode();
}

Expand Down Expand Up @@ -331,7 +332,7 @@ public boolean equals(@CheckForNull Object obj) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness PredicateFunction<T> this) {
return predicate.hashCode();
}

Expand Down Expand Up @@ -383,7 +384,7 @@ public boolean equals(@CheckForNull Object obj) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness ConstantFunction<E> this) {
return (value == null) ? 0 : value.hashCode();
}

Expand Down Expand Up @@ -434,7 +435,7 @@ public boolean equals(@CheckForNull Object obj) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness SupplierFunction<F, T> this) {
return supplier.hashCode();
}

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Optional.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.framework.qual.AnnotatedFor;
import org.checkerframework.framework.qual.Covariant;

Expand Down Expand Up @@ -314,7 +315,7 @@ public java.util.Optional<T> toJavaUtil() {
* hash code unspecified, unlike the Java 8 equivalent.
*/
@Override
public abstract int hashCode();
public abstract int hashCode(@UnknownSignedness Optional<T> this);

/**
* Returns a string representation for this instance.
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/PairwiseEquivalence.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Iterator;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

@GwtCompatible(serializable = true)
@ElementTypesAreNonnullByDefault
Expand Down Expand Up @@ -64,7 +65,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness PairwiseEquivalence<E, T> this) {
return elementEquivalence.hashCode() ^ 0x46a3eb07;
}

Expand Down
19 changes: 10 additions & 9 deletions guava/src/com/google/common/base/Predicates.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;

Expand Down Expand Up @@ -330,7 +331,7 @@ public boolean apply(@ParametricNullness T t) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness NotPredicate<T> this) {
return ~predicate.hashCode();
}

Expand Down Expand Up @@ -375,7 +376,7 @@ public boolean apply(@ParametricNullness T t) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness AndPredicate<T> this) {
// add a random number to avoid collisions with OrPredicate
return components.hashCode() + 0x12472c2c;
}
Expand Down Expand Up @@ -421,7 +422,7 @@ public boolean apply(@ParametricNullness T t) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness OrPredicate<T> this) {
// add a random number to avoid collisions with AndPredicate
return components.hashCode() + 0x053c91cf;
}
Expand Down Expand Up @@ -473,7 +474,7 @@ public boolean apply(@CheckForNull Object o) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness IsEqualToPredicate this) {
return target.hashCode();
}

Expand Down Expand Up @@ -518,7 +519,7 @@ public boolean apply(@ParametricNullness T o) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness InstanceOfPredicate<T> this) {
return clazz.hashCode();
}

Expand Down Expand Up @@ -556,7 +557,7 @@ public boolean apply(Class<?> input) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness SubtypeOfPredicate this) {
return clazz.hashCode();
}

Expand Down Expand Up @@ -607,7 +608,7 @@ public boolean equals(@CheckForNull Object obj) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness InPredicate<T> this) {
return target.hashCode();
}

Expand Down Expand Up @@ -648,7 +649,7 @@ public boolean equals(@CheckForNull Object obj) {

@Pure
@Override
public int hashCode() {
public int hashCode(@UnknownSignedness CompositionPredicate<A, B> this) {
return f.hashCode() ^ p.hashCode();
}

Expand Down Expand Up @@ -677,7 +678,7 @@ public boolean apply(CharSequence t) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness ContainsPatternPredicate this) {
// Pattern uses Object.hashCode, so we have to reach
// inside to build a hashCode consistent with equals.

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Present.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.annotation.CheckForNull;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/** Implementation of an {@link Optional} containing a reference. */
@GwtCompatible
Expand Down Expand Up @@ -89,7 +90,7 @@ public boolean equals(@CheckForNull Object object) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness Present<T> this) {
return 0x598df91c + reference.hashCode();
}

Expand Down
5 changes: 3 additions & 2 deletions guava/src/com/google/common/base/Suppliers.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
import org.checkerframework.framework.qual.AnnotatedFor;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public boolean equals(@CheckForNull Object obj) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness SupplierComposition<F, T> this) {
return Objects.hashCode(function, supplier);
}

Expand Down Expand Up @@ -315,7 +316,7 @@ public boolean equals(@CheckForNull Object obj) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness SupplierOfInstance<T> this) {
return Objects.hashCode(instance);
}

Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/cache/CacheBuilderSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.annotation.CheckForNull;
import org.checkerframework.checker.formatter.qual.FormatMethod;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
* A specification of a {@link CacheBuilder} configuration.
Expand Down Expand Up @@ -237,7 +238,7 @@ public String toString() {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness CacheBuilderSpec this) {
return Objects.hashCode(
initialCapacity,
maximumSize,
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/cache/CacheStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.Objects;
import java.util.concurrent.Callable;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
* Statistics about the performance of a {@link Cache}. Instances of this class are immutable.
Expand Down Expand Up @@ -271,7 +272,7 @@ public CacheStats plus(CacheStats other) {
}

@Override
public int hashCode() {
public int hashCode(@UnknownSignedness CacheStats this) {
return Objects.hashCode(
hitCount, missCount, loadSuccessCount, loadExceptionCount, totalLoadTime, evictionCount);
}
Expand Down
Loading

0 comments on commit 1b6f8cf

Please sign in to comment.