Skip to content

Commit

Permalink
NonNull annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
suztomo committed Sep 16, 2024
1 parent 2491335 commit efd84ea
Show file tree
Hide file tree
Showing 33 changed files with 161 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

@AutoValue
Expand Down Expand Up @@ -60,7 +60,7 @@ public abstract static class Builder {

public abstract Builder setIsSampleCode(boolean isSampleCode);

public Builder addCatch(@Nonnull VariableExpr variableExpr, List<Statement> body) {
public Builder addCatch(@NonNull VariableExpr variableExpr, List<Statement> body) {
List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs());
catchVarExprs.add(variableExpr);
setCatchVariableExprs(catchVarExprs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

public class ImportWriterVisitor implements AstNodeVisitor {
Expand All @@ -91,12 +91,12 @@ public void clear() {
importShortNames.clear();
}

public void initialize(@Nonnull String currentPackage) {
public void initialize(@NonNull String currentPackage) {
this.currentPackage = currentPackage;
currentClassName = null;
}

public void initialize(@Nonnull String currentPackage, @Nonnull String currentClassName) {
public void initialize(@NonNull String currentPackage, @NonNull String currentClassName) {
this.currentPackage = currentPackage;
this.currentClassName = currentClassName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
package com.google.api.generator.gapic.model;

import com.google.protobuf.DescriptorProtos.SourceCodeInfo.Location;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/**
* A light wrapper around SourceCodeInfo.Location to provide cleaner protobuf comments. Please see
* additional documentation on descriptor.proto.
*/
public class SourceCodeInfoLocation {
@Nonnull private final Location location;
@NonNull private final Location location;

private SourceCodeInfoLocation(Location location) {
this.location = location;
}

public static SourceCodeInfoLocation create(@Nonnull Location location) {
public static SourceCodeInfoLocation create(@NonNull Location location) {
return new SourceCodeInfoLocation(location);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

public class TypeParser {
private static Reference REFERENCE_BYTE_STRING = ConcreteReference.withClazz(ByteString.class);
Expand Down Expand Up @@ -62,7 +62,7 @@ public class TypeParser {
.put(JavaType.BYTE_STRING, REFERENCE_BYTE_STRING)
.build();

public static TypeNode parseType(@Nonnull FieldDescriptor field) {
public static TypeNode parseType(@NonNull FieldDescriptor field) {
if (field.isMapField()) {
return createMapType(field);
}
Expand All @@ -83,11 +83,11 @@ public static TypeNode parseType(@Nonnull FieldDescriptor field) {
return TypeNode.withReference(parseFieldReference(field));
}

public static TypeNode parseType(@Nonnull Descriptor messageDescriptor) {
public static TypeNode parseType(@NonNull Descriptor messageDescriptor) {
return TypeNode.withReference(parseMessageReference(messageDescriptor));
}

public static TypeNode parseType(@Nonnull EnumDescriptor enumDescriptor) {
public static TypeNode parseType(@NonNull EnumDescriptor enumDescriptor) {
return TypeNode.withReference(parseEnumReference(enumDescriptor));
}

Expand Down Expand Up @@ -119,7 +119,7 @@ static Reference parseFieldReference(FieldDescriptor field) {
}

@VisibleForTesting
static Reference parseMessageReference(@Nonnull Descriptor messageDescriptor) {
static Reference parseMessageReference(@NonNull Descriptor messageDescriptor) {
List<String> outerNestedTypeNames = new ArrayList<>();
FileOptions fileOptions = messageDescriptor.getFile().getOptions();
String javaOuterClassname =
Expand Down Expand Up @@ -179,7 +179,7 @@ static Reference parseMessageReference(@Nonnull Descriptor messageDescriptor) {
}

@VisibleForTesting
static Reference parseEnumReference(@Nonnull EnumDescriptor enumDescriptor) {
static Reference parseEnumReference(@NonNull EnumDescriptor enumDescriptor) {
// This is similar to parseMessageReference, but we make it a separate method because
// EnumDescriptor and Descriptor are sibling types.
FileOptions fileOptions = enumDescriptor.getFile().getOptions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -626,7 +626,7 @@ public GrpcCallContext withRequestParamsDynamicHeaderOption(String requestParams

/** {@inheritDoc} */
@Override
@Nonnull
@NonNull
public ApiTracer getTracer() {
ApiTracer tracer = callOptions.getOption(TRACER_KEY);
if (tracer == null) {
Expand All @@ -637,7 +637,7 @@ public ApiTracer getTracer() {

/** {@inheritDoc} */
@Override
public GrpcCallContext withTracer(@Nonnull ApiTracer tracer) {
public GrpcCallContext withTracer(@NonNull ApiTracer tracer) {
Preconditions.checkNotNull(tracer);
return withCallOptions(callOptions.withOption(TRACER_KEY, tracer));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import io.grpc.MethodDescriptor;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/** Class with utility methods to create grpc-based direct callables. */
public class GrpcCallableFactory {
Expand Down Expand Up @@ -329,7 +329,7 @@ ClientStreamingCallable<RequestT, ResponseT> createClientStreamingCallable(
}

@InternalApi("Visible for testing")
static SpanName getSpanName(@Nonnull MethodDescriptor<?, ?> methodDescriptor) {
static SpanName getSpanName(@NonNull MethodDescriptor<?, ?> methodDescriptor) {
Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName());

Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -68,13 +68,13 @@ void testRetryNoRaceCondition() throws Exception {
ManagedChannelBuilder.forAddress("localhost", 1234).usePlaintext().build();
StreamResumptionStrategy<Color, Money> resumptionStrategy =
new StreamResumptionStrategy<Color, Money>() {
@Nonnull
@NonNull
@Override
public StreamResumptionStrategy<Color, Money> createNew() {
return this;
}

@Nonnull
@NonNull
@Override
public Money processResponse(Money response) {
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -587,7 +587,7 @@ public HttpJsonCallContext withDeadline(org.threeten.bp.Instant newDeadline) {
return withCallOptions(builder.setDeadline(newDeadline).build());
}

@Nonnull
@NonNull
@Override
public ApiTracer getTracer() {
if (tracer == null) {
Expand All @@ -598,7 +598,7 @@ public ApiTracer getTracer() {

/** {@inheritDoc} */
@Override
public HttpJsonCallContext withTracer(@Nonnull ApiTracer newTracer) {
public HttpJsonCallContext withTracer(@NonNull ApiTracer newTracer) {
Preconditions.checkNotNull(newTracer);

return new HttpJsonCallContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import com.google.common.base.Preconditions;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/** Class with utility methods to create http/json-based direct callables. */
public class HttpJsonCallableFactory {
Expand Down Expand Up @@ -228,7 +228,7 @@ ServerStreamingCallable<RequestT, ResponseT> createServerStreamingCallable(
}

@InternalApi("Visible for testing")
static SpanName getSpanName(@Nonnull ApiMethodDescriptor<?, ?> methodDescriptor) {
static SpanName getSpanName(@NonNull ApiMethodDescriptor<?, ?> methodDescriptor) {
Matcher matcher = FULL_METHOD_NAME_REGEX.matcher(methodDescriptor.getFullMethodName());

Preconditions.checkArgument(matcher.matches(), "Invalid fullMethodName");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -500,7 +500,7 @@ void add(
totalThrottledTimeMs += throttledTimeMs;
}

void setResponseFuture(@Nonnull ApiFuture<ResponseT> responseFuture) {
void setResponseFuture(@NonNull ApiFuture<ResponseT> responseFuture) {
Preconditions.checkNotNull(responseFuture);
this.responseFuture = responseFuture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.google.api.gax.tracing.ApiTracer;
import com.google.api.gax.tracing.BaseApiTracer;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/**
* Backwards compatibility class to aid in transition to adding operation state to {@link
Expand All @@ -48,7 +48,7 @@ public static RetryingContext create() {
}

/** {@inheritDoc} */
@Nonnull
@NonNull
@Override
public ApiTracer getTracer() {
return BaseApiTracer.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.google.api.gax.rpc.StatusCode;
import com.google.api.gax.tracing.ApiTracer;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand All @@ -44,7 +44,7 @@
@BetaApi("The surface for passing per operation state is not yet stable")
public interface RetryingContext {
/** Returns the {@link ApiTracer} associated with the current operation. */
@Nonnull
@NonNull
ApiTracer getTracer();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.google.api.core.BetaApi;
import com.google.api.core.InternalExtensionOnly;
import java.util.concurrent.Callable;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;

/**
* A {@link RetryingExecutor} that accepts a per-operation context.
Expand All @@ -45,5 +45,5 @@
@InternalExtensionOnly
public interface RetryingExecutorWithContext<ResponseT> extends RetryingExecutor<ResponseT> {
RetryingFuture<ResponseT> createFuture(
@Nonnull Callable<ResponseT> callable, @Nonnull RetryingContext context);
@NonNull Callable<ResponseT> callable, @NonNull RetryingContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
package com.google.api.gax.retrying;

import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand All @@ -41,7 +41,7 @@
public interface StreamResumptionStrategy<RequestT, ResponseT> {

/** Creates a new instance of this StreamResumptionStrategy without accumulated state */
@Nonnull
@NonNull
StreamResumptionStrategy<RequestT, ResponseT> createNew();

/**
Expand All @@ -58,7 +58,7 @@ public interface StreamResumptionStrategy<RequestT, ResponseT> {
* through this method.
* </ol>
*/
@Nonnull
@NonNull
ResponseT processResponse(ResponseT response);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -173,7 +173,7 @@ public interface ApiCallContext extends RetryingContext {
* events like retries.
*/
@BetaApi("The surface for tracing is not stable yet and may change in the future")
@Nonnull
@NonNull
ApiTracer getTracer();

/**
Expand All @@ -185,7 +185,7 @@ public interface ApiCallContext extends RetryingContext {
* @param tracer the {@link ApiTracer} to set.
*/
@BetaApi("The surface for tracing is not stable yet and may change in the future")
ApiCallContext withTracer(@Nonnull ApiTracer tracer);
ApiCallContext withTracer(@NonNull ApiTracer tracer);

/**
* Returns a new ApiCallContext with the given {@link RetrySettings} set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;

/**
Expand Down Expand Up @@ -101,14 +101,12 @@ public abstract class ClientContext {
public abstract Watchdog getStreamWatchdog();

/** This method is obsolete. Use {@link #getStreamWatchdogCheckIntervalDuration()} instead. */
@Nonnull
@ObsoleteApi("Use getStreamWatchdogCheckIntervalDuration() instead")
public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() {
public final org.threeten.bp.@NonNull Duration getStreamWatchdogCheckInterval() {
return toThreetenDuration(getStreamWatchdogCheckIntervalDuration());
}

@Nonnull
public abstract java.time.Duration getStreamWatchdogCheckIntervalDuration();
public abstract java.time.@NonNull Duration getStreamWatchdogCheckIntervalDuration();

@Nullable
public abstract String getUniverseDomain();
Expand All @@ -124,7 +122,7 @@ public final org.threeten.bp.Duration getStreamWatchdogCheckInterval() {

/** Gets the {@link ApiTracerFactory} that will be used to generate traces for operations. */
@BetaApi("The surface for tracing is not stable yet and may change in the future.")
@Nonnull
@NonNull
public abstract ApiTracerFactory getTracerFactory();

/**
Expand Down
Loading

0 comments on commit efd84ea

Please sign in to comment.