From 208795c0fe7a2783c370adfa9b4ff3f73101961a Mon Sep 17 00:00:00 2001 From: Benjamin Herzog Date: Mon, 18 Apr 2016 18:10:14 +0200 Subject: [PATCH 1/3] Added nullability to service declaration in objc --- src/compiler/objective_c_generator.cc | 6 +++--- src/compiler/objective_c_plugin.cc | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index ff092053ad0..465491e385f 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -75,11 +75,11 @@ void PrintMethodSignature(Printer *printer, const MethodDescriptor *method, if (method->server_streaming()) { printer->Print(vars, " eventHandler:(void(^)(BOOL done, " - "$response_class$ *response, NSError *error))eventHandler"); + "$response_class$ *_Nullable response, NSError *_Nullable error))eventHandler"); } else { printer->Print(vars, - " handler:(void(^)($response_class$ *response, " - "NSError *error))handler"); + " handler:(void(^)($response_class$ *_Nullable response, " + "NSError *_Nullable error))handler"); } } diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index 17440358bb8..f62faa52610 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -64,7 +64,8 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ".pbobjc.h\"\n\n" "#import \n" "#import \n" - "#import \n"; + "#import \n\n" + "NS_ASSUME_NONNULL_BEGIN\n\n"; // TODO(jcanizales): Instead forward-declare the input and output types // and import the files in the .pbrpc.m @@ -81,8 +82,10 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { declarations += grpc_objective_c_generator::GetHeader(service); } + ::grpc::string nonNullEnd = "\nNS_ASSUME_NONNULL_END\n"; + Write(context, file_name + ".pbrpc.h", - imports + '\n' + proto_imports + '\n' + declarations); + imports + '\n' + proto_imports + '\n' + declarations + nonNullEnd); } { From ee6de9365b9d2a79cd7874b4976372c681fb257d Mon Sep 17 00:00:00 2001 From: Benjamin Herzog Date: Fri, 22 Apr 2016 11:17:43 +0200 Subject: [PATCH 2/3] Move nonnull begin to correct position --- src/compiler/objective_c_plugin.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index f62faa52610..9522956fdeb 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -64,8 +64,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ".pbobjc.h\"\n\n" "#import \n" "#import \n" - "#import \n\n" - "NS_ASSUME_NONNULL_BEGIN\n\n"; + "#import \n"; // TODO(jcanizales): Instead forward-declare the input and output types // and import the files in the .pbrpc.m @@ -82,10 +81,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { declarations += grpc_objective_c_generator::GetHeader(service); } + ::grpc::string nonNullBegin = "\nNS_ASSUME_NONNULL_BEGIN\n\n"; ::grpc::string nonNullEnd = "\nNS_ASSUME_NONNULL_END\n"; Write(context, file_name + ".pbrpc.h", - imports + '\n' + proto_imports + '\n' + declarations + nonNullEnd); + imports + '\n' + proto_imports + '\n' + nonNullBegin + + declarations + nonNullEnd); } { From 1843ccb226c477798ed7dd25287cb9ef3a87c754 Mon Sep 17 00:00:00 2001 From: Benjamin Herzog Date: Wed, 27 Apr 2016 17:39:26 +0200 Subject: [PATCH 3/3] Use static const strings --- src/compiler/objective_c_plugin.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index 9522956fdeb..3ccfd5b037c 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -81,12 +81,12 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { declarations += grpc_objective_c_generator::GetHeader(service); } - ::grpc::string nonNullBegin = "\nNS_ASSUME_NONNULL_BEGIN\n\n"; - ::grpc::string nonNullEnd = "\nNS_ASSUME_NONNULL_END\n"; + static const ::grpc::string kNonNullBegin = "\nNS_ASSUME_NONNULL_BEGIN\n\n"; + static const ::grpc::string kNonNullEnd = "\nNS_ASSUME_NONNULL_END\n"; Write(context, file_name + ".pbrpc.h", - imports + '\n' + proto_imports + '\n' + nonNullBegin + - declarations + nonNullEnd); + imports + '\n' + proto_imports + '\n' + kNonNullBegin + + declarations + kNonNullEnd); } {