Skip to content
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions guava/src/com/google/common/base/CharMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.annotations.VisibleForTesting;
import java.util.Arrays;
import java.util.BitSet;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.index.qual.GTENegativeOne;
import org.checkerframework.checker.index.qual.IndexOrHigh;
import org.checkerframework.checker.index.qual.IndexOrLow;
Expand Down Expand Up @@ -321,7 +322,7 @@ public static CharMatcher isNot(final char match) {
* The CharSequence is not mutated, therefore after checking its length,
* accesses to lower indices are safe.
*/
public static CharMatcher anyOf(final CharSequence sequence) {
public static CharMatcher anyOf(final @Readonly CharSequence sequence) {
switch (sequence.length()) {
case 0:
return none();
Expand All @@ -340,7 +341,7 @@ public static CharMatcher anyOf(final CharSequence sequence) {
* Returns a {@code char} matcher that matches any BMP character not present in the given
* character sequence. Returns a bogus matcher if the sequence contains supplementary characters.
*/
public static CharMatcher noneOf(CharSequence sequence) {
public static CharMatcher noneOf(@Readonly CharSequence sequence) {
return anyOf(sequence).negate();
}

Expand Down Expand Up @@ -504,7 +505,7 @@ void setBits(BitSet table) {
* @return {@code true} if this matcher matches at least one character in the sequence
* @since 8.0
*/
public boolean matchesAnyOf(CharSequence sequence) {
public boolean matchesAnyOf(@Readonly CharSequence sequence) {
return !matchesNoneOf(sequence);
}

Expand All @@ -518,7 +519,7 @@ public boolean matchesAnyOf(CharSequence sequence) {
* @return {@code true} if this matcher matches every character in the sequence, including when
* the sequence is empty
*/
public boolean matchesAllOf(CharSequence sequence) {
public boolean matchesAllOf(@Readonly CharSequence sequence) {
for (int i = sequence.length() - 1; i >= 0; i--) {
if (!matches(sequence.charAt(i))) {
return false;
Expand All @@ -538,7 +539,7 @@ public boolean matchesAllOf(CharSequence sequence) {
* @return {@code true} if this matcher matches no characters in the sequence, including when the
* sequence is empty
*/
public boolean matchesNoneOf(CharSequence sequence) {
public boolean matchesNoneOf(@Readonly CharSequence sequence) {
return indexIn(sequence) == -1;
}

Expand All @@ -552,7 +553,7 @@ public boolean matchesNoneOf(CharSequence sequence) {
* @param sequence the character sequence to examine from the beginning
* @return an index, or {@code -1} if no character matches
*/
public @IndexOrLow("#1") int indexIn(CharSequence sequence) {
public @IndexOrLow("#1") int indexIn(@Readonly CharSequence sequence) {
return indexIn(sequence, 0);
}

Expand All @@ -571,7 +572,7 @@ public boolean matchesNoneOf(CharSequence sequence) {
* @throws IndexOutOfBoundsException if start is negative or greater than {@code
* sequence.length()}
*/
public @IndexOrLow("#1") int indexIn(CharSequence sequence, @IndexOrHigh("#1") int start) {
public @IndexOrLow("#1") int indexIn(@Readonly CharSequence sequence, @IndexOrHigh("#1") int start) {
int length = sequence.length();
checkPositionIndex(start, length);
for (int i = start; i < length; i++) {
Expand All @@ -592,7 +593,7 @@ public boolean matchesNoneOf(CharSequence sequence) {
* @param sequence the character sequence to examine from the end
* @return an index, or {@code -1} if no character matches
*/
public @IndexOrLow("#1") int lastIndexIn(CharSequence sequence) {
public @IndexOrLow("#1") int lastIndexIn(@Readonly CharSequence sequence) {
for (int i = sequence.length() - 1; i >= 0; i--) {
if (matches(sequence.charAt(i))) {
return i;
Expand All @@ -609,7 +610,7 @@ public boolean matchesNoneOf(CharSequence sequence) {
/*
* count is incremented at most sequence.length() times
*/
public @IndexOrHigh("#1") int countIn(CharSequence sequence) {
public @IndexOrHigh("#1") int countIn(@Readonly CharSequence sequence) {
@IndexOrHigh("#1") int count = 0;
for (int i = 0; i < sequence.length(); i++) {
if (matches(sequence.charAt(i))) {
Expand All @@ -629,7 +630,7 @@ public boolean matchesNoneOf(CharSequence sequence) {
*
* ... returns {@code "bzr"}.
*/
public String removeFrom(CharSequence sequence) {
public String removeFrom(@Readonly CharSequence sequence) {
String string = sequence.toString();
@GTENegativeOne @LTEqLengthOf("string") int pos = indexIn(string);
if (pos == -1) {
Expand Down Expand Up @@ -668,7 +669,7 @@ public String removeFrom(CharSequence sequence) {
*
* ... returns {@code "aaa"}.
*/
public String retainFrom(CharSequence sequence) {
public String retainFrom(@Readonly CharSequence sequence) {
return negate().removeFrom(sequence);
}

Expand All @@ -691,7 +692,7 @@ public String retainFrom(CharSequence sequence) {
* character in {@code sequence}
* @return the new string
*/
public String replaceFrom(CharSequence sequence, char replacement) {
public String replaceFrom(@Readonly CharSequence sequence, char replacement) {
String string = sequence.toString();
int pos = indexIn(string);
if (pos == -1) {
Expand Down Expand Up @@ -730,7 +731,7 @@ public String replaceFrom(CharSequence sequence, char replacement) {
* replacementLen should be @IndexOrHigh("replacement")
* indexIn should return @IndexOrLow("#1")
*/
public String replaceFrom(CharSequence sequence, CharSequence replacement) {
public String replaceFrom(@Readonly CharSequence sequence, @Readonly CharSequence replacement) {
int replacementLen = replacement.length();
if (replacementLen == 0) {
return removeFrom(sequence);
Expand Down Expand Up @@ -778,7 +779,7 @@ public String replaceFrom(CharSequence sequence, CharSequence replacement) {
*
* ... is equivalent to {@link String#trim()}.
*/
public String trimFrom(CharSequence sequence) {
public String trimFrom(@Readonly CharSequence sequence) {
int len = sequence.length();
@IndexOrHigh("sequence") int first;
int last;
Expand Down Expand Up @@ -807,7 +808,7 @@ public String trimFrom(CharSequence sequence) {
*
* ... returns {@code "catbab"}.
*/
public String trimLeadingFrom(CharSequence sequence) {
public String trimLeadingFrom(@Readonly CharSequence sequence) {
int len = sequence.length();
for (int first = 0; first < len; first++) {
if (!matches(sequence.charAt(first))) {
Expand All @@ -827,7 +828,7 @@ public String trimLeadingFrom(CharSequence sequence) {
*
* ... returns {@code "abacat"}.
*/
public String trimTrailingFrom(CharSequence sequence) {
public String trimTrailingFrom(@Readonly CharSequence sequence) {
int len = sequence.length();
for (int last = len - 1; last >= 0; last--) {
if (!matches(sequence.charAt(last))) {
Expand Down
3 changes: 2 additions & 1 deletion guava/src/com/google/common/base/Equivalence.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.signedness.qual.UnknownSignedness;

/**
Expand Down Expand Up @@ -342,7 +343,7 @@ public String toString() {
* @since 8.0 (in Equivalences with null-friendly behavior)
* @since 4.0 (in Equivalences)
*/
public static Equivalence<Object> equals() {
public static Equivalence<@Readonly Object> equals() {
return Equals.INSTANCE;
}

Expand Down
7 changes: 5 additions & 2 deletions guava/src/com/google/common/base/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.common.annotations.GwtCompatible;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;

Expand Down Expand Up @@ -45,7 +47,8 @@
@AnnotatedFor({"nullness"})
@FunctionalInterface
@ElementTypesAreNonnullByDefault
public interface Function<F extends @Nullable Object, T extends @Nullable Object>
@ReceiverDependentMutable
public interface Function<F extends @Nullable @Readonly Object, T extends @Nullable @Readonly Object>
extends java.util.function.Function<F, T> {
@Override
@ParametricNullness
Expand All @@ -64,5 +67,5 @@ public interface Function<F extends @Nullable Object, T extends @Nullable Object
*/
@Pure
@Override
boolean equals(@CheckForNull Object object);
boolean equals(@CheckForNull @Readonly Object object);
}
4 changes: 2 additions & 2 deletions guava/src/com/google/common/base/MoreObjects.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static <T> T firstNonNull(@CheckForNull T first, @CheckForNull T second)
* class name
* @since 18.0 (since 2.0 as {@code Objects.toStringHelper()}).
*/
public static ToStringHelper toStringHelper(Object self) {
public static ToStringHelper toStringHelper(@Readonly Object self) {
return new ToStringHelper(self.getClass().getSimpleName());
}

Expand Down Expand Up @@ -441,7 +441,7 @@ private ToStringHelper addUnconditionalHolder(String name, Object value) {
// Holder object for values that might be null and/or empty.
static class ValueHolder {
@CheckForNull String name;
@CheckForNull Object value;
@CheckForNull @Readonly Object value;
@CheckForNull ValueHolder next;
}

Expand Down
5 changes: 3 additions & 2 deletions guava/src/com/google/common/base/Objects.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.signedness.qual.PolySigned;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
Expand Down Expand Up @@ -54,7 +55,7 @@ private Objects() {}
* <p><b>Java 7+ users:</b> This method should be treated as deprecated; use {@link
* java.util.Objects#equals} instead.
*/
public static boolean equal(@CheckForNull @PolySigned Object a, @CheckForNull @PolySigned Object b) {
public static boolean equal(@CheckForNull @PolySigned @Readonly Object a, @CheckForNull @PolySigned @Readonly Object b) {
return a == b || (a != null && a.equals(b));
}

Expand All @@ -80,7 +81,7 @@ public static boolean equal(@CheckForNull @PolySigned Object a, @CheckForNull @P
* java.util.Objects#hash} instead.
*/
@Pure
public static int hashCode(@CheckForNull @Nullable Object... objects) {
public static int hashCode(@CheckForNull @Nullable @Readonly Object @Readonly ... objects) {
return Arrays.hashCode(objects);
}
}
13 changes: 7 additions & 6 deletions guava/src/com/google/common/base/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.annotation.CheckForNull;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.dataflow.qual.AssertMethod;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;
Expand Down Expand Up @@ -149,7 +150,7 @@ public static void checkArgument(boolean expression) {
*/
@AssertMethod(IllegalArgumentException.class)
@Pure
public static void checkArgument(boolean expression, @CheckForNull Object errorMessage) {
public static void checkArgument(boolean expression, @CheckForNull @Readonly Object errorMessage) {
if (!expression) {
throw new IllegalArgumentException(String.valueOf(errorMessage));
}
Expand All @@ -173,7 +174,7 @@ public static void checkArgument(boolean expression, @CheckForNull Object errorM
public static void checkArgument(
boolean expression,
String errorMessageTemplate,
@CheckForNull @Nullable Object... errorMessageArgs) {
@CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (!expression) {
throw new IllegalArgumentException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
Expand Down Expand Up @@ -569,7 +570,7 @@ public static void checkState(boolean expression) {
*/
@AssertMethod(IllegalStateException.class)
@Pure
public static void checkState(boolean expression, @CheckForNull Object errorMessage) {
public static void checkState(boolean expression, @CheckForNull @Readonly Object errorMessage) {
if (!expression) {
throw new IllegalStateException(String.valueOf(errorMessage));
}
Expand Down Expand Up @@ -603,7 +604,7 @@ public static void checkState(
* that user first.
*/
@CheckForNull String errorMessageTemplate,
@CheckForNull @Nullable Object... errorMessageArgs) {
@CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (!expression) {
throw new IllegalStateException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
Expand Down Expand Up @@ -1026,7 +1027,7 @@ public static <T> T checkNotNull(@CheckForNull T reference) {
*/
@CanIgnoreReturnValue
@Pure
public static <T> T checkNotNull(@CheckForNull T reference, @CheckForNull Object errorMessage) {
public static <T> T checkNotNull(@CheckForNull T reference, @CheckForNull @Readonly Object errorMessage) {
if (reference == null) {
throw new NullPointerException(String.valueOf(errorMessage));
}
Expand All @@ -1053,7 +1054,7 @@ public static <T> T checkNotNull(@CheckForNull T reference, @CheckForNull Object
public static <T> T checkNotNull(
@CheckForNull T reference,
String errorMessageTemplate,
@CheckForNull @Nullable Object... errorMessageArgs) {
@CheckForNull @Nullable @Readonly Object... errorMessageArgs) {
if (reference == null) {
throw new NullPointerException(lenientFormat(errorMessageTemplate, errorMessageArgs));
}
Expand Down
8 changes: 6 additions & 2 deletions guava/src/com/google/common/base/Predicate.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.google.common.annotations.GwtCompatible;
import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.pico.qual.Readonly;
import org.checkerframework.checker.pico.qual.ReceiverDependentMutable;
import org.checkerframework.dataflow.qual.Pure;
import org.checkerframework.framework.qual.AnnotatedFor;

Expand All @@ -42,11 +44,13 @@
* @author Kevin Bourrillion
* @since 2.0
*/
@SuppressWarnings("pico")
@FunctionalInterface
@GwtCompatible
@AnnotatedFor({"nullness"})
@ElementTypesAreNonnullByDefault
public interface Predicate<T extends @Nullable Object> extends java.util.function.Predicate<T> {
@ReceiverDependentMutable
public interface Predicate<T extends @Nullable @Readonly Object> extends java.util.function.Predicate<T> {
/**
* Returns the result of applying this predicate to {@code input} (Java 8+ users, see notes in the
* class documentation above). This method is <i>generally expected</i>, but not absolutely
Expand Down Expand Up @@ -76,7 +80,7 @@ public interface Predicate<T extends @Nullable Object> extends java.util.functio
*/
@Pure
@Override
boolean equals(@CheckForNull Object object);
boolean equals(@CheckForNull @Readonly Object object);

@Override
default boolean test(@ParametricNullness T input) {
Expand Down
Loading
Loading