Skip to content

Commit

Permalink
Move type annotations immediately before the type they apply
Browse files Browse the repository at this point in the history
to

Fixes #3145

RELNOTES=N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=196531789
  • Loading branch information
mernst authored and ronshapiro committed May 14, 2018
1 parent 4038405 commit 9b4a9db
Show file tree
Hide file tree
Showing 102 changed files with 274 additions and 412 deletions.
Expand Up @@ -43,8 +43,8 @@ private enum State {

protected abstract T computeNext();

@NullableDecl
@CanIgnoreReturnValue
@NullableDecl
protected final T endOfData() {
state = State.DONE;
return null;
Expand Down
4 changes: 2 additions & 2 deletions android/guava/src/com/google/common/base/Converter.java
Expand Up @@ -164,8 +164,8 @@ protected Converter() {
*
* @return the converted value; is null <i>if and only if</i> {@code a} is null
*/
@NullableDecl
@CanIgnoreReturnValue
@NullableDecl
public final B convert(@NullableDecl A a) {
return correctedDoForward(a);
}
Expand Down Expand Up @@ -386,8 +386,8 @@ public String toString() {
*/
@Deprecated
@Override
@NullableDecl
@CanIgnoreReturnValue
@NullableDecl
public final B apply(@NullableDecl A a) {
return convert(a);
}
Expand Down
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/base/Defaults.java
Expand Up @@ -37,8 +37,8 @@ private Defaults() {}
* false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types and
* {@code void}, {@code null} is returned.
*/
@NullableDecl
@SuppressWarnings("unchecked")
@NullableDecl
public static <T> T defaultValue(Class<T> type) {
checkNotNull(type);
if (type == boolean.class) {
Expand Down
Expand Up @@ -241,8 +241,8 @@ static class SystemLoader implements FinalizerLoader {
// finding Finalizer on the system class path even if it is there.
@VisibleForTesting static boolean disabled;

@NullableDecl
@Override
@NullableDecl
public Class<?> loadFinalizer() {
if (disabled) {
return null;
Expand Down Expand Up @@ -279,8 +279,8 @@ static class DecoupledLoader implements FinalizerLoader {
+ "loader. To support reclaiming this class loader, either resolve the underlying "
+ "issue, or move Guava to your system class path.";

@NullableDecl
@Override
@NullableDecl
public Class<?> loadFinalizer() {
try {
/*
Expand Down
Expand Up @@ -31,14 +31,14 @@ class ImmutableEntry<K, V> extends AbstractMapEntry<K, V> implements Serializabl
this.value = value;
}

@NullableDecl
@Override
@NullableDecl
public final K getKey() {
return key;
}

@NullableDecl
@Override
@NullableDecl
public final V getValue() {
return value;
}
Expand Down
Expand Up @@ -338,7 +338,7 @@ public int hashCode() {
@Override
public abstract UnmodifiableIterator<E> iterator();

@LazyInit @NullableDecl @RetainedWith private transient ImmutableList<E> asList;
@LazyInit @RetainedWith @NullableDecl private transient ImmutableList<E> asList;

@Override
public ImmutableList<E> asList() {
Expand Down
Expand Up @@ -675,8 +675,8 @@ private static Pattern fpPattern() {
* @since 14.0
*/
@Beta
@NullableDecl
@GwtIncompatible // regular expressions
@NullableDecl
public static Double tryParse(String string) {
if (FLOATING_POINT_PATTERN.matcher(string).matches()) {
// TODO(lowasser): could be potentially optimized, but only with
Expand Down
2 changes: 1 addition & 1 deletion android/guava/src/com/google/common/primitives/Floats.java
Expand Up @@ -649,8 +649,8 @@ float[] toFloatArray() {
* @since 14.0
*/
@Beta
@NullableDecl
@GwtIncompatible // regular expressions
@NullableDecl
public static Float tryParse(String string) {
if (Doubles.FLOATING_POINT_PATTERN.matcher(string).matches()) {
// TODO(lowasser): could be potentially optimized, but only with
Expand Down
Expand Up @@ -41,28 +41,28 @@ public final class MutableTypeToInstanceMap<B> extends ForwardingMap<TypeToken<?

private final Map<TypeToken<? extends B>, B> backingMap = Maps.newHashMap();

@NullableDecl
@Override
@NullableDecl
public <T extends B> T getInstance(Class<T> type) {
return trustedGet(TypeToken.of(type));
}

@NullableDecl
@Override
@NullableDecl
public <T extends B> T getInstance(TypeToken<T> type) {
return trustedGet(type.rejectTypeVariables());
}

@NullableDecl
@Override
@CanIgnoreReturnValue
@NullableDecl
public <T extends B> T putInstance(Class<T> type, @NullableDecl T value) {
return trustedPut(TypeToken.of(type), value);
}

@NullableDecl
@Override
@CanIgnoreReturnValue
@NullableDecl
public <T extends B> T putInstance(TypeToken<T> type, @NullableDecl T value) {
return trustedPut(type.rejectTypeVariables(), value);
}
Expand Down
Expand Up @@ -70,8 +70,8 @@ public interface TypeToInstanceMap<B> extends Map<TypeToken<? extends B>, B> {
* @return the value previously associated with this class (possibly {@code null}), or {@code
* null} if there was no previous entry.
*/
@NullableDecl
@CanIgnoreReturnValue
@NullableDecl
<T extends B> T putInstance(Class<T> type, @NullableDecl T value);

/**
Expand All @@ -81,7 +81,7 @@ public interface TypeToInstanceMap<B> extends Map<TypeToken<? extends B>, B> {
* @return the value previously associated with this type (possibly {@code null}), or {@code null}
* if there was no previous entry.
*/
@NullableDecl
@CanIgnoreReturnValue
@NullableDecl
<T extends B> T putInstance(TypeToken<T> type, @NullableDecl T value);
}
4 changes: 2 additions & 2 deletions android/guava/src/com/google/common/reflect/TypeToken.java
Expand Up @@ -1310,8 +1310,8 @@ Iterable<? extends TypeToken<?>> getInterfaces(TypeToken<?> type) {
return type.getGenericInterfaces();
}

@NullableDecl
@Override
@NullableDecl
TypeToken<?> getSuperclass(TypeToken<?> type) {
return type.getGenericSuperclass();
}
Expand All @@ -1329,8 +1329,8 @@ Iterable<? extends Class<?>> getInterfaces(Class<?> type) {
return Arrays.asList(type.getInterfaces());
}

@NullableDecl
@Override
@NullableDecl
Class<?> getSuperclass(Class<?> type) {
return type.getSuperclass();
}
Expand Down
4 changes: 2 additions & 2 deletions android/guava/src/com/google/common/reflect/Types.java
Expand Up @@ -105,15 +105,15 @@ static ParameterizedType newParameterizedType(Class<?> rawType, Type... argument
/** Decides what owner type to use for constructing {@link ParameterizedType} from a raw class. */
private enum ClassOwnership {
OWNED_BY_ENCLOSING_CLASS {
@NullableDecl
@Override
@NullableDecl
Class<?> getOwnerType(Class<?> rawType) {
return rawType.getEnclosingClass();
}
},
LOCAL_CLASS_HAS_NO_OWNER {
@NullableDecl
@Override
@NullableDecl
Class<?> getOwnerType(Class<?> rawType) {
if (rawType.isLocalClass()) {
return null;
Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/base/Absent.java
Expand Up @@ -61,8 +61,7 @@ public T or(Supplier<? extends T> supplier) {
}

@Override
@Nullable
public T orNull() {
public @Nullable T orNull() {
return null;
}

Expand Down
5 changes: 2 additions & 3 deletions guava/src/com/google/common/base/AbstractIterator.java
Expand Up @@ -39,13 +39,12 @@ private enum State {
FAILED,
}

@Nullable private T next;
private @Nullable T next;

protected abstract T computeNext();

@Nullable
@CanIgnoreReturnValue
protected final T endOfData() {
protected final @Nullable T endOfData() {
state = State.DONE;
return null;
}
Expand Down
6 changes: 2 additions & 4 deletions guava/src/com/google/common/base/Converter.java
Expand Up @@ -164,9 +164,8 @@ protected Converter() {
*
* @return the converted value; is null <i>if and only if</i> {@code a} is null
*/
@Nullable
@CanIgnoreReturnValue
public final B convert(@Nullable A a) {
public final @Nullable B convert(@Nullable A a) {
return correctedDoForward(a);
}

Expand Down Expand Up @@ -386,9 +385,8 @@ public String toString() {
*/
@Deprecated
@Override
@Nullable
@CanIgnoreReturnValue
public final B apply(@Nullable A a) {
public final @Nullable B apply(@Nullable A a) {
return convert(a);
}

Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/base/Defaults.java
Expand Up @@ -37,9 +37,8 @@ private Defaults() {}
* false} for {@code boolean} and {@code '\0'} for {@code char}. For non-primitive types and
* {@code void}, {@code null} is returned.
*/
@Nullable
@SuppressWarnings("unchecked")
public static <T> T defaultValue(Class<T> type) {
public static <T> @Nullable T defaultValue(Class<T> type) {
checkNotNull(type);
if (type == boolean.class) {
return (T) Boolean.FALSE;
Expand Down
7 changes: 3 additions & 4 deletions guava/src/com/google/common/base/Equivalence.java
Expand Up @@ -184,16 +184,15 @@ public final <S extends T> Wrapper<S> wrap(@Nullable S reference) {
*/
public static final class Wrapper<T> implements Serializable {
private final Equivalence<? super T> equivalence;
@Nullable private final T reference;
private final @Nullable T reference;

private Wrapper(Equivalence<? super T> equivalence, @Nullable T reference) {
this.equivalence = checkNotNull(equivalence);
this.reference = reference;
}

/** Returns the (possibly null) reference wrapped by this instance. */
@Nullable
public T get() {
public @Nullable T get() {
return reference;
}

Expand Down Expand Up @@ -272,7 +271,7 @@ public final Predicate<T> equivalentTo(@Nullable T target) {
private static final class EquivalentToPredicate<T> implements Predicate<T>, Serializable {

private final Equivalence<T> equivalence;
@Nullable private final T target;
private final @Nullable T target;

EquivalentToPredicate(Equivalence<T> equivalence, @Nullable T target) {
this.equivalence = checkNotNull(equivalence);
Expand Down
Expand Up @@ -241,9 +241,8 @@ static class SystemLoader implements FinalizerLoader {
// finding Finalizer on the system class path even if it is there.
@VisibleForTesting static boolean disabled;

@Nullable
@Override
public Class<?> loadFinalizer() {
public @Nullable Class<?> loadFinalizer() {
if (disabled) {
return null;
}
Expand Down Expand Up @@ -279,9 +278,8 @@ static class DecoupledLoader implements FinalizerLoader {
+ "loader. To support reclaiming this class loader, either resolve the underlying "
+ "issue, or move Guava to your system class path.";

@Nullable
@Override
public Class<?> loadFinalizer() {
public @Nullable Class<?> loadFinalizer() {
try {
/*
* We use URLClassLoader because it's the only concrete class loader implementation in the
Expand Down
7 changes: 3 additions & 4 deletions guava/src/com/google/common/base/Functions.java
Expand Up @@ -88,8 +88,7 @@ private enum IdentityFunction implements Function<Object, Object> {
INSTANCE;

@Override
@Nullable
public Object apply(@Nullable Object o) {
public @Nullable Object apply(@Nullable Object o) {
return o;
}

Expand Down Expand Up @@ -171,7 +170,7 @@ public String toString() {

private static class ForMapWithDefault<K, V> implements Function<K, V>, Serializable {
final Map<K, ? extends V> map;
@Nullable final V defaultValue;
final @Nullable V defaultValue;

ForMapWithDefault(Map<K, ? extends V> map, @Nullable V defaultValue) {
this.map = checkNotNull(map);
Expand Down Expand Up @@ -320,7 +319,7 @@ public static <E> Function<Object, E> constant(@Nullable E value) {
}

private static class ConstantFunction<E> implements Function<Object, E>, Serializable {
@Nullable private final E value;
private final @Nullable E value;

public ConstantFunction(@Nullable E value) {
this.value = value;
Expand Down
7 changes: 3 additions & 4 deletions guava/src/com/google/common/base/Optional.java
Expand Up @@ -120,8 +120,8 @@ public static <T> Optional<T> fromNullable(@Nullable T nullableReference) {
*
* @since 21.0
*/
@Nullable
public static <T> Optional<T> fromJavaUtil(java.util.@Nullable Optional<T> javaUtilOptional) {
public static <T> @Nullable Optional<T> fromJavaUtil(
java.util.@Nullable Optional<T> javaUtilOptional) {
return (javaUtilOptional == null) ? null : fromNullable(javaUtilOptional.orElse(null));
}

Expand Down Expand Up @@ -246,8 +246,7 @@ public java.util.Optional<T> toJavaUtil() {
* <p><b>Comparison to {@code java.util.Optional}:</b> this method is equivalent to Java 8's
* {@code Optional.orElse(null)}.
*/
@Nullable
public abstract T orNull();
public abstract @Nullable T orNull();

/**
* Returns an immutable singleton {@link Set} whose only element is the contained instance if it
Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/base/StandardSystemProperty.java
Expand Up @@ -125,8 +125,7 @@ public String key() {
* Returns the current value for this system property by delegating to {@link
* System#getProperty(String)}.
*/
@Nullable
public String value() {
public @Nullable String value() {
return System.getProperty(key);
}

Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/base/Strings.java
Expand Up @@ -47,8 +47,7 @@ public static String nullToEmpty(@Nullable String string) {
* @param string the string to test and possibly return
* @return {@code string} itself if it is nonempty; {@code null} if it is empty or null
*/
@Nullable
public static String emptyToNull(@Nullable String string) {
public static @Nullable String emptyToNull(@Nullable String string) {
return Platform.emptyToNull(string);
}

Expand Down

0 comments on commit 9b4a9db

Please sign in to comment.