Skip to content

Commit

Permalink
Write type annotations on types, not on declarations
Browse files Browse the repository at this point in the history
Fixes #3774

RELNOTES=n/a

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=290747030
  • Loading branch information
mernst authored and travis-ci committed Jan 21, 2020
1 parent d44669d commit 66c2f79
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 43 deletions.
Expand Up @@ -762,8 +762,8 @@ private void updateLastKnownIndex() {
} }


@SuppressWarnings("unchecked") // known to be a V @SuppressWarnings("unchecked") // known to be a V
@NullableDecl
@Override @Override
@NullableDecl
public V getValue() { public V getValue() {
@NullableDecl Map<K, V> delegate = delegateOrNull(); @NullableDecl Map<K, V> delegate = delegateOrNull();
if (delegate != null) { if (delegate != null) {
Expand Down
Expand Up @@ -198,6 +198,7 @@ public final <T> T[] toArray(T[] other) {
} }


/** If this collection is backed by an array of its elements in insertion order, returns it. */ /** If this collection is backed by an array of its elements in insertion order, returns it. */
@NullableDecl
Object[] internalArray() { Object[] internalArray() {
return null; return null;
} }
Expand Down
Expand Up @@ -378,8 +378,7 @@ public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException
} }


@Override @Override
@Nullable public @Nullable V getIfPresent(Object key) {
public V getIfPresent(Object key) {
return localCache.getIfPresent(key); return localCache.getIfPresent(key);
} }


Expand Down
Expand Up @@ -90,8 +90,7 @@ ImmutableList<E> createAsList() {
} }


/** If this collection is backed by an array of its elements in insertion order, returns it. */ /** If this collection is backed by an array of its elements in insertion order, returns it. */
@Nullable Object @Nullable [] internalArray() {
Object[] internalArray() {
return null; return null;
} }


Expand Down
Expand Up @@ -199,8 +199,8 @@ <E> void forEach(GeneralSpliterator<E> spliterator, Consumer<? super E> consumer
abstract <E> void forEach(GeneralSpliterator<E> spliterator, Consumer<? super E> consumer); abstract <E> void forEach(GeneralSpliterator<E> spliterator, Consumer<? super E> consumer);
} }


@Nullable private static <E> @Nullable GeneralSpliterator<E> trySplitTestingSize(
private static <E> GeneralSpliterator<E> trySplitTestingSize(GeneralSpliterator<E> spliterator) { GeneralSpliterator<E> spliterator) {
boolean subsized = spliterator.hasCharacteristics(Spliterator.SUBSIZED); boolean subsized = spliterator.hasCharacteristics(Spliterator.SUBSIZED);
long originalSize = spliterator.estimateSize(); long originalSize = spliterator.estimateSize();
GeneralSpliterator<E> trySplit = spliterator.trySplit(); GeneralSpliterator<E> trySplit = spliterator.trySplit();
Expand Down
Expand Up @@ -336,8 +336,7 @@ private static <T> void setImplementation(Class<T> type, Class<? extends T> impl
} }


@SuppressWarnings("unchecked") // it's a subtype map @SuppressWarnings("unchecked") // it's a subtype map
@Nullable private static <T> @Nullable Class<? extends T> getImplementation(Class<T> type) {
private static <T> Class<? extends T> getImplementation(Class<T> type) {
return (Class<? extends T>) implementations.get(type); return (Class<? extends T>) implementations.get(type);
} }


Expand All @@ -347,8 +346,7 @@ private static <T> Class<? extends T> getImplementation(Class<T> type) {
* Returns an arbitrary instance for {@code type}, or {@code null} if no arbitrary instance can be * Returns an arbitrary instance for {@code type}, or {@code null} if no arbitrary instance can be
* determined. * determined.
*/ */
@Nullable public static <T> @Nullable T get(Class<T> type) {
public static <T> T get(Class<T> type) {
T defaultValue = DEFAULTS.getInstance(type); T defaultValue = DEFAULTS.getInstance(type);
if (defaultValue != null) { if (defaultValue != null) {
return defaultValue; return defaultValue;
Expand Down Expand Up @@ -398,8 +396,7 @@ public static <T> T get(Class<T> type) {
} }
} }


@Nullable private static <T> @Nullable T arbitraryConstantInstanceOrNull(Class<T> type) {
private static <T> T arbitraryConstantInstanceOrNull(Class<T> type) {
Field[] fields = type.getDeclaredFields(); Field[] fields = type.getDeclaredFields();
Arrays.sort(fields, BY_FIELD_NAME); Arrays.sort(fields, BY_FIELD_NAME);
for (Field field : fields) { for (Field field : fields) {
Expand Down
Expand Up @@ -179,17 +179,15 @@ final <T> void addSampleInstances(Class<T> type, Iterable<? extends T> instances
* <li>null if no value can be generated. * <li>null if no value can be generated.
* </ul> * </ul>
*/ */
@Nullable final @Nullable Object generateFresh(TypeToken<?> type) {
final Object generateFresh(TypeToken<?> type) {
Object generated = generate(type); Object generated = generate(type);
if (generated != null) { if (generated != null) {
freshness.incrementAndGet(); freshness.incrementAndGet();
} }
return generated; return generated;
} }


@Nullable final <T> @Nullable T generateFresh(Class<T> type) {
final <T> T generateFresh(Class<T> type) {
return Primitives.wrap(type).cast(generateFresh(TypeToken.of(type))); return Primitives.wrap(type).cast(generateFresh(TypeToken.of(type)));
} }


Expand Down
Expand Up @@ -289,8 +289,7 @@ public void testEqualsAndSerializableForReturnValues_factoryReturnsNullAndAnnota
} }


public static class FactoryThatReturnsNullAndAnnotated { public static class FactoryThatReturnsNullAndAnnotated {
@Nullable public static @Nullable Object bad() {
public static Object bad() {
return null; return null;
} }
} }
Expand Down Expand Up @@ -759,8 +758,7 @@ static GoodEquals create(String a, int b) {


// keep trying // keep trying
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Nullable public static @Nullable GoodEquals createMayReturnNull(int a, int b) {
public static GoodEquals createMayReturnNull(int a, int b) {
return null; return null;
} }


Expand Down Expand Up @@ -1191,8 +1189,7 @@ static FactoryMethodReturnsNullButNotAnnotated returnsNull() {
static class FactoryMethodReturnsNullAndAnnotated { static class FactoryMethodReturnsNullAndAnnotated {
private FactoryMethodReturnsNullAndAnnotated() {} private FactoryMethodReturnsNullAndAnnotated() {}


@Nullable public static @Nullable FactoryMethodReturnsNullAndAnnotated returnsNull() {
public static FactoryMethodReturnsNullAndAnnotated returnsNull() {
return null; return null;
} }
} }
Expand Down
Expand Up @@ -56,8 +56,7 @@ protected AbstractSequentialIterator(@Nullable T firstOrNull) {
* remain. This method is invoked during each call to {@link #next()} in order to compute the * remain. This method is invoked during each call to {@link #next()} in order to compute the
* result of a <i>future</i> call to {@code next()}. * result of a <i>future</i> call to {@code next()}.
*/ */
@Nullable protected abstract @Nullable T computeNext(T previous);
protected abstract T computeNext(T previous);


@Override @Override
public final boolean hasNext() { public final boolean hasNext() {
Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/collect/CompactHashMap.java
Expand Up @@ -833,9 +833,8 @@ private void updateLastKnownIndex() {
} }


@SuppressWarnings("unchecked") // known to be a V @SuppressWarnings("unchecked") // known to be a V
@Nullable
@Override @Override
public V getValue() { public @Nullable V getValue() {
@Nullable Map<K, V> delegate = delegateOrNull(); @Nullable Map<K, V> delegate = delegateOrNull();
if (delegate != null) { if (delegate != null) {
return delegate.get(key); return delegate.get(key);
Expand Down
15 changes: 5 additions & 10 deletions guava/src/com/google/common/collect/HashBiMap.java
Expand Up @@ -307,8 +307,7 @@ private V put(@Nullable K key, @Nullable V value, boolean force) {


@CanIgnoreReturnValue @CanIgnoreReturnValue
@Override @Override
@Nullable public @Nullable V forcePut(@Nullable K key, @Nullable V value) {
public V forcePut(@Nullable K key, @Nullable V value) {
return put(key, value, true); return put(key, value, true);
} }


Expand Down Expand Up @@ -382,8 +381,7 @@ private BiEntry<K, V>[] createTable(int length) {


@CanIgnoreReturnValue @CanIgnoreReturnValue
@Override @Override
@Nullable public @Nullable V remove(@Nullable Object key) {
public V remove(@Nullable Object key) {
BiEntry<K, V> entry = seekByKey(key, smearedHash(key)); BiEntry<K, V> entry = seekByKey(key, smearedHash(key));
if (entry == null) { if (entry == null) {
return null; return null;
Expand Down Expand Up @@ -596,20 +594,17 @@ public K get(@Nullable Object value) {


@CanIgnoreReturnValue @CanIgnoreReturnValue
@Override @Override
@Nullable public @Nullable K put(@Nullable V value, @Nullable K key) {
public K put(@Nullable V value, @Nullable K key) {
return putInverse(value, key, false); return putInverse(value, key, false);
} }


@Override @Override
@Nullable public @Nullable K forcePut(@Nullable V value, @Nullable K key) {
public K forcePut(@Nullable V value, @Nullable K key) {
return putInverse(value, key, true); return putInverse(value, key, true);
} }


@Override @Override
@Nullable public @Nullable K remove(@Nullable Object value) {
public K remove(@Nullable Object value) {
BiEntry<K, V> entry = seekByValue(value, smearedHash(value)); BiEntry<K, V> entry = seekByValue(value, smearedHash(value));
if (entry == null) { if (entry == null) {
return null; return null;
Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/collect/ImmutableCollection.java
Expand Up @@ -210,8 +210,7 @@ public final <T> T[] toArray(T[] other) {
} }


/** If this collection is backed by an array of its elements in insertion order, returns it. */ /** If this collection is backed by an array of its elements in insertion order, returns it. */
@Nullable Object @Nullable [] internalArray() {
Object[] internalArray() {
return null; return null;
} }


Expand Down
3 changes: 1 addition & 2 deletions guava/src/com/google/common/io/FileBackedOutputStream.java
Expand Up @@ -63,8 +63,7 @@ public final class FileBackedOutputStream extends OutputStream {
private MemoryOutput memory; private MemoryOutput memory;


@GuardedBy("this") @GuardedBy("this")
@Nullable private @Nullable File file;
private File file;


/** ByteArrayOutputStream that exposes its internals. */ /** ByteArrayOutputStream that exposes its internals. */
private static class MemoryOutput extends ByteArrayOutputStream { private static class MemoryOutput extends ByteArrayOutputStream {
Expand Down
Expand Up @@ -999,8 +999,7 @@ protected void afterDone() {}
* @since 27.0 * @since 27.0
*/ */
@Override @Override
@Nullable protected final @Nullable Throwable tryInternalFastPathGetFailure() {
protected final Throwable tryInternalFastPathGetFailure() {
if (this instanceof Trusted) { if (this instanceof Trusted) {
Object obj = value; Object obj = value;
if (obj instanceof Failure) { if (obj instanceof Failure) {
Expand Down

0 comments on commit 66c2f79

Please sign in to comment.