From a418f1dfec042a4d66e7207bd576745388beabfb Mon Sep 17 00:00:00 2001 From: Ryan Michela Date: Fri, 9 Mar 2018 10:13:42 -0800 Subject: [PATCH] Correctly handle underscores in RPC names --- .../reactivegrpc/gen/ReactiveGrpcGenerator.java | 8 +++++++- .../proto/com/example/v1/settingsgetclassic.proto | 15 +++++++++++++++ rx-java/rxgrpc/src/main/resources/RxStub.mustache | 8 ++++---- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 rx-java/rxgrpc-test/src/test/proto/com/example/v1/settingsgetclassic.proto diff --git a/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java b/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java index 98439469..18502913 100644 --- a/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java +++ b/common/reactive-grpc-gencommon/src/main/java/com/salesforce/reactivegrpc/gen/ReactiveGrpcGenerator.java @@ -228,7 +228,13 @@ public String methodNameUpperUnderscore() { } public String methodNamePascalCase() { - return String.valueOf(Character.toUpperCase(methodName.charAt(0))) + methodName.substring(1); + String mn = methodName.replace("_", ""); + return String.valueOf(Character.toUpperCase(mn.charAt(0))) + mn.substring(1); + } + + public String methodNameCamelCase() { + String mn = methodName.replace("_", ""); + return String.valueOf(Character.toLowerCase(mn.charAt(0))) + mn.substring(1); } } } diff --git a/rx-java/rxgrpc-test/src/test/proto/com/example/v1/settingsgetclassic.proto b/rx-java/rxgrpc-test/src/test/proto/com/example/v1/settingsgetclassic.proto new file mode 100644 index 00000000..e5601d3f --- /dev/null +++ b/rx-java/rxgrpc-test/src/test/proto/com/example/v1/settingsgetclassic.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; + +package com.example.v1; + +import "google/protobuf/timestamp.proto"; +import "google/protobuf/empty.proto"; + +service Settings { + rpc SettingsGet_Classic_1 (google.protobuf.Empty) returns (Settings_Classic_1); + rpc SettingsGetClassic2 (google.protobuf.Empty) returns (Settings_Classic_1); +} + +message Settings_Classic_1 { + google.protobuf.Timestamp timestamp = 1; +} \ No newline at end of file diff --git a/rx-java/rxgrpc/src/main/resources/RxStub.mustache b/rx-java/rxgrpc/src/main/resources/RxStub.mustache index 2a33788f..47b68324 100644 --- a/rx-java/rxgrpc/src/main/resources/RxStub.mustache +++ b/rx-java/rxgrpc/src/main/resources/RxStub.mustache @@ -51,7 +51,7 @@ public final class {{className}} { @java.lang.Deprecated {{/deprecated}} public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> rxRequest) { - return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(rxRequest, delegateStub::{{methodName}}); + return com.salesforce.rxgrpc.stub.ClientCalls.{{reactiveCallsMethodName}}(rxRequest, delegateStub::{{methodNameCamelCase}}); } {{/methods}} @@ -69,7 +69,7 @@ public final class {{className}} { {{#deprecated}} @java.lang.Deprecated {{/deprecated}} - public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodName}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> request) { + public {{#isManyOutput}}io.reactivex.Flowable{{/isManyOutput}}{{^isManyOutput}}io.reactivex.Single{{/isManyOutput}}<{{outputType}}> {{methodNameCamelCase}}({{#isManyInput}}io.reactivex.Flowable{{/isManyInput}}{{^isManyInput}}io.reactivex.Single{{/isManyInput}}<{{inputType}}> request) { throw new io.grpc.StatusRuntimeException(io.grpc.Status.UNIMPLEMENTED); } @@ -115,7 +115,7 @@ public final class {{className}} { case METHODID_{{methodNameUpperUnderscore}}: com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}(({{inputType}}) request, (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - serviceImpl::{{methodName}}); + serviceImpl::{{methodNameCamelCase}}); break; {{/isManyInput}} {{/methods}} @@ -133,7 +133,7 @@ public final class {{className}} { case METHODID_{{methodNameUpperUnderscore}}: return (io.grpc.stub.StreamObserver) com.salesforce.rxgrpc.stub.ServerCalls.{{reactiveCallsMethodName}}( (io.grpc.stub.StreamObserver<{{outputType}}>) responseObserver, - serviceImpl::{{methodName}}); + serviceImpl::{{methodNameCamelCase}}); {{/isManyInput}} {{/methods}} default: