Skip to content
Permalink
Browse files

Write type annotations on types, not on declarations

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 66c2f795f2cbc90e104dde9d73ceb484b184b34b
@@ -762,8 +762,8 @@ private void updateLastKnownIndex() {
}

@SuppressWarnings("unchecked") // known to be a V
@NullableDecl
@Override
@NullableDecl
public V getValue() {
@NullableDecl Map<K, V> delegate = delegateOrNull();
if (delegate != null) {
@@ -198,6 +198,7 @@
}

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

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

@@ -90,8 +90,7 @@ public final void clear() {
}

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

@@ -199,8 +199,8 @@ boolean tryAdvance(Consumer<? super E> action) {
abstract <E> void forEach(GeneralSpliterator<E> spliterator, Consumer<? super E> consumer);
}

@Nullable
private static <E> GeneralSpliterator<E> trySplitTestingSize(GeneralSpliterator<E> spliterator) {
private static <E> @Nullable GeneralSpliterator<E> trySplitTestingSize(
GeneralSpliterator<E> spliterator) {
boolean subsized = spliterator.hasCharacteristics(Spliterator.SUBSIZED);
long originalSize = spliterator.estimateSize();
GeneralSpliterator<E> trySplit = spliterator.trySplit();
@@ -336,8 +336,7 @@ private static MatchResult newMatchResult() {
}

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

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

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

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

@@ -289,8 +289,7 @@ public void testEqualsAndSerializableForReturnValues_factoryReturnsNullAndAnnota
}

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

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

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

@Nullable
public static FactoryMethodReturnsNullAndAnnotated returnsNull() {
public static @Nullable FactoryMethodReturnsNullAndAnnotated returnsNull() {
return null;
}
}
@@ -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
* result of a <i>future</i> call to {@code next()}.
*/
@Nullable
protected abstract T computeNext(T previous);
protected abstract @Nullable T computeNext(T previous);

@Override
public final boolean hasNext() {
@@ -833,9 +833,8 @@ private void updateLastKnownIndex() {
}

@SuppressWarnings("unchecked") // known to be a V
@Nullable
@Override
public V getValue() {
public @Nullable V getValue() {
@Nullable Map<K, V> delegate = delegateOrNull();
if (delegate != null) {
return delegate.get(key);
@@ -307,8 +307,7 @@ private V put(@Nullable K key, @Nullable V value, boolean force) {

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

@@ -382,8 +381,7 @@ private void rehashIfNecessary() {

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

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

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

@Override
@Nullable
public K remove(@Nullable Object value) {
public @Nullable K remove(@Nullable Object value) {
BiEntry<K, V> entry = seekByValue(value, smearedHash(value));
if (entry == null) {
return null;
@@ -210,8 +210,7 @@
}

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

@@ -63,8 +63,7 @@
private MemoryOutput memory;

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

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

0 comments on commit 66c2f79

Please sign in to comment.
You can’t perform that action at this time.