Skip to content

Commit cfd83ad

Browse files
author
Alex Davies-Moore
committed
Remove the suffix of 'Service' on generated types
This commit removes the 'Service' suffix on RPC service interface, favouring the name defined in the proto file. This prevents awkward class naming such as 'StatusServiceService'.
1 parent b105cb4 commit cfd83ad

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

plugin/src/main/java/com/flit/protoc/gen/server/ServiceGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ public class ServiceGenerator extends BaseGenerator {
1212

1313
public ServiceGenerator(DescriptorProtos.FileDescriptorProto proto, DescriptorProtos.ServiceDescriptorProto s, TypeMapper mapper) {
1414
super(proto, s, mapper);
15-
this.filename = javaPackage.replace(".", "/") + "/Rpc" + service.getName() + "Service.java";
15+
this.filename = javaPackage.replace(".", "/") + "/Rpc" + service.getName() + ".java";
1616
}
1717

1818
public void open() {
19-
b.wn("public interface Rpc", service.getName(), "Service {");
19+
b.wn("public interface Rpc", service.getName(), " {");
2020
b.n();
2121
b.inc();
2222
}

plugin/src/main/java/com/flit/protoc/gen/server/spring/RpcGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void open() {
5555
// add the service handler
5656
b.inc();
5757
b.iwn("@Autowired");
58-
b.iwn("private Rpc", service.getName(), "Service service;");
58+
b.iwn("private Rpc", service.getName(), " service;");
5959
b.n();
6060
}
6161

plugin/src/main/java/com/flit/protoc/gen/server/undertow/RpcGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ void open(DescriptorProtos.ServiceDescriptorProto s) {
6767
b.n();
6868

6969
// add the service handler
70-
b.iwn("private final Rpc", service.getName(), "Service service;");
70+
b.iwn("private final Rpc", service.getName(), " service;");
7171
b.iwn("private final ErrorWriter errorWriter;");
7272
b.n();
7373

7474
// add the constructor for the service
75-
b.iwn("public Rpc", service.getName(), "Handler(Rpc", service.getName() + "Service service) {");
75+
b.iwn("public Rpc", service.getName(), "Handler(Rpc", service.getName() + " service) {");
7676
b.inc();
7777
b.iwn("this.service = service;");
7878
b.iwn("this.errorWriter = new ErrorWriter();");

plugin/src/test/java/com/flit/protoc/gen/server/undertow/ContextGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private void test_Route(String file, String route) throws Exception {
5656
Function.identity()
5757
));
5858

59-
assertTrue(files.containsKey("com/example/context/rpc/RpcNullServiceService.java"));
59+
assertTrue(files.containsKey("com/example/context/rpc/RpcNullService.java"));
6060
assertTrue(files.containsKey("com/example/context/rpc/RpcNullServiceHandler.java"));
6161

6262
assertTrue(files.get("com/example/context/rpc/RpcNullServiceHandler.java").getContent().contains(

plugin/src/test/java/com/flit/protoc/gen/server/undertow/HelloworldGeneratorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public void test_Generate() throws Exception {
3333
Function.identity()
3434
));
3535

36-
assertTrue(files.containsKey("com/example/helloworld/RpcHelloWorldService.java"));
36+
assertTrue(files.containsKey("com/example/helloworld/RpcHelloWorld.java"));
3737
assertTrue(files.containsKey("com/example/helloworld/RpcHelloWorldHandler.java"));
3838

3939
// ensure it's parseable java
40-
test_Service(files.get("com/example/helloworld/RpcHelloWorldService.java"));
40+
test_Service(files.get("com/example/helloworld/RpcHelloWorld.java"));
4141
test_Handler(files.get("com/example/helloworld/RpcHelloWorldHandler.java"));
4242
}
4343

@@ -92,7 +92,7 @@ private void test_Service(PluginProtos.CodeGeneratorResponse.File file) throws E
9292
assertEquals(1, cu.getTypes().size());
9393

9494
assertTrue(cu.getType(0).isPublic());
95-
assertEquals("RpcHelloWorldService", cu.getType(0).getNameAsString());
95+
assertEquals("RpcHelloWorld", cu.getType(0).getNameAsString());
9696

9797
Map<String, MethodDeclaration> methods = cu
9898
.findAll(MethodDeclaration.class)

plugin/src/test/java/com/flit/protoc/gen/server/undertow/StatusGeneratorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public void test_Generate() throws Exception {
3636
Function.identity()
3737
));
3838

39-
assertTrue(files.containsKey("com/example/helloworld/RpcStatusService.java"));
39+
assertTrue(files.containsKey("com/example/helloworld/RpcStatus.java"));
4040
assertTrue(files.containsKey("com/example/helloworld/RpcStatusHandler.java"));
4141

42-
test_Service(files.get("com/example/helloworld/RpcStatusService.java"));
42+
test_Service(files.get("com/example/helloworld/RpcStatus.java"));
4343
test_Handler(files.get("com/example/helloworld/RpcStatusHandler.java"));
4444
}
4545

@@ -85,7 +85,7 @@ private void test_Service(PluginProtos.CodeGeneratorResponse.File file) throws E
8585
assertEquals(1, cu.getTypes().size());
8686

8787
assertTrue(cu.getType(0).isPublic());
88-
assertEquals("RpcStatusService", cu.getType(0).getNameAsString());
88+
assertEquals("RpcStatus", cu.getType(0).getNameAsString());
8989

9090
Map<String, MethodDeclaration> methods = cu
9191
.findAll(MethodDeclaration.class)

0 commit comments

Comments
 (0)