Skip to content

Commit

Permalink
@CanIgnoreReturnValue for blocking stub methods returning Empty
Browse files Browse the repository at this point in the history
  • Loading branch information
panchenko committed Jun 15, 2024
1 parent 889893d commit 56505b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/src/java_plugin/cpp/java_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ static void PrintStub(
for (int i = 0; i < service->method_count(); ++i) {
const MethodDescriptor* method = service->method(i);
(*vars)["input_type"] = MessageFullJavaName(method->input_type());
(*vars)["output_type"] = MessageFullJavaName(method->output_type());
std::string output_type = MessageFullJavaName(method->output_type());
(*vars)["output_type"] = output_type;
(*vars)["lower_method_name"] = LowerMethodName(method);
(*vars)["method_method_name"] = MethodPropertiesGetterName(method);
bool client_streaming = method->client_streaming();
Expand All @@ -682,6 +683,11 @@ static void PrintStub(
// TODO(nmittler): Replace with WriteMethodDocComment once included by the protobuf distro.
GrpcWriteMethodDocComment(p, method);

if (call_type == BLOCKING_CALL &&
!server_streaming &&
output_type == "com.google.protobuf.Empty") {
p->Print(*vars, "@$CanIgnoreReturnValue$\n");
}
if (method->options().deprecated()) {
p->Print(*vars, "@$Deprecated$\n");
}
Expand Down Expand Up @@ -1261,6 +1267,7 @@ void GenerateService(const ServiceDescriptor* service,
vars["GrpcGenerated"] = "io.grpc.stub.annotations.GrpcGenerated";
vars["ListenableFuture"] =
"com.google.common.util.concurrent.ListenableFuture";
vars["CanIgnoreReturnValue"] = "com.google.errorprone.annotations.CanIgnoreReturnValue";

Printer printer(out, '$');
std::string package_name = ServiceJavaPackage(service->file());
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/test/proto/grpc/testing/compiler/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package grpc.testing.compiler;

option java_package = "io.grpc.testing.compiler";

import "google/protobuf/empty.proto";

message SimpleRequest {
}

Expand Down Expand Up @@ -80,6 +82,8 @@ service TestService {
rpc IdempotentCall(SimpleRequest) returns (SimpleResponse) {
option idempotency_level = IDEMPOTENT;
}

rpc UnaryCallWithoutResult(SimpleRequest) returns (google.protobuf.Empty);
}

// Test service that has been deprecated and should generate with Java's @Deprecated annotation
Expand Down

0 comments on commit 56505b0

Please sign in to comment.