nullability annotation

pull/16190/head
Muxi Yan 6 years ago
parent 92db5fc724
commit df21aab3a6
  1. 2
      src/objective-c/GRPCClient/GRPCCall.m
  2. 18
      src/objective-c/ProtoRPC/ProtoRPC.h
  3. 3
      src/objective-c/ProtoRPC/ProtoRPC.m
  4. 34
      src/objective-c/ProtoRPC/ProtoService.h
  5. 7
      src/objective-c/ProtoRPC/ProtoService.m
  6. 3
      src/objective-c/tests/GRPCClientTests.m

@ -485,7 +485,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
requestsWriter:(GRXWriter *)requestWriter
callOptions:(GRPCCallOptions *)callOptions {
// Purposely using pointer rather than length ([host length] == 0) for backwards compatibility.
NSAssert(host != nil && path != nil, @"Neither host nor path can be nil.");
NSAssert(host.length != 0 && path.length != 0, @"Neither host nor path can be nil.");
NSAssert(safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value.");
NSAssert(requestWriter.state == GRXWriterStateNotStarted,
@"The requests writer can't be already started.");

@ -70,11 +70,11 @@ NS_ASSUME_NONNULL_BEGIN
* Users should not use this initializer directly. Call objects will be created, initialized, and
* returned to users by methods of the generated service.
*/
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
message:(GPBMessage *)message
responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/**
* Start the call. This function must only be called once for each instance.
@ -101,10 +101,10 @@ NS_ASSUME_NONNULL_BEGIN
* Users should not use this initializer directly. Call objects will be created, initialized, and
* returned to users by methods of the generated service.
*/
- (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions
responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass NS_DESIGNATED_INITIALIZER;
/**
* Start the call. This function must only be called once for each instance.

@ -57,6 +57,9 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
responseClass:(Class)responseClass {
NSAssert(message != nil, @"message cannot be empty.");
NSAssert(responseClass != nil, @"responseClass cannot be empty.");
if (message == nil || responseClass == nil) {
return nil;
}
if ((self = [super init])) {
_call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions
responseHandler:handler

@ -27,33 +27,35 @@
@class GRPCStreamingProtoCall;
@protocol GRPCProtoResponseCallbacks;
NS_ASSUME_NONNULL_BEGIN
__attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoService
: NSObject
-
(instancetype)initWithHost : (NSString *)host packageName
(nullable instancetype)initWithHost : (NSString *)host packageName
: (NSString *)packageName serviceName : (NSString *)serviceName callOptions
: (GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER;
: (nullable GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithHost:(NSString *)host
packageName:(NSString *)packageName
serviceName:(NSString *)serviceName;
- (GRPCProtoCall *)RPCToMethod:(NSString *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable;
- (nullable GRPCProtoCall *)RPCToMethod:(NSString *)method
requestsWriter:(GRXWriter *)requestsWriter
responseClass:(Class)responseClass
responsesWriteable:(id<GRXWriteable>)responsesWriteable;
- (GRPCUnaryProtoCall *)RPCToMethod:(NSString *)method
message:(id)message
responseHandler:(id<GRPCProtoResponseCallbacks>)handler
callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass;
- (nullable GRPCUnaryProtoCall *)RPCToMethod:(NSString *)method
message:(id)message
responseHandler:(id<GRPCProtoResponseCallbacks>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass;
- (GRPCStreamingProtoCall *)RPCToMethod:(NSString *)method
responseHandler:(id<GRPCProtoResponseCallbacks>)handler
callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass;
- (nullable GRPCStreamingProtoCall *)RPCToMethod:(NSString *)method
responseHandler:(id<GRPCProtoResponseCallbacks>)handler
callOptions:(nullable GRPCCallOptions *)callOptions
responseClass:(Class)responseClass;
@end
@ -67,3 +69,5 @@ __attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoServ
#pragma clang diagnostic pop
@end
NS_ASSUME_NONNULL_END

@ -44,9 +44,10 @@
packageName:(NSString *)packageName
serviceName:(NSString *)serviceName
callOptions:(GRPCCallOptions *)callOptions {
if (!host || !serviceName) {
[NSException raise:NSInvalidArgumentException
format:@"Neither host nor serviceName can be nil."];
NSAssert(host.length != 0 && packageName.length != 0 && serviceName.length != 0,
@"Invalid parameter.");
if (host.length == 0 || packageName.length == 0 || serviceName.length == 0) {
return nil;
}
if ((self = [super init])) {
_host = [host copy];

@ -362,9 +362,10 @@ static GRPCProtoMethod *kFullDuplexCallMethod;
// TODO(makarandd): Move to a different file that contains only unit tests
- (void)testExceptions {
GRXWriter *writer = [GRXWriter writerWithValue:[NSData data]];
// Try to set parameters to nil for GRPCCall. This should cause an exception
@try {
(void)[[GRPCCall alloc] initWithHost:nil path:nil requestsWriter:nil];
(void)[[GRPCCall alloc] initWithHost:@"" path:@"" requestsWriter:writer];
XCTFail(@"Did not receive an exception when parameters are nil");
} @catch (NSException *theException) {
NSLog(@"Received exception as expected: %@", theException.name);

Loading…
Cancel
Save