Skip to content

Commit 072f99d

Browse files
authored
use super params in generated grpc service classes (#988)
- update the GRPC service generator to emit constructors that use super parameters
1 parent 7d2e615 commit 072f99d

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

protoc_plugin/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
([#952])
66
* Add fromDart() and toDart() methods to convert between core Duration and proto
77
Duration ([#986])
8+
* Update the GRPC service generator to emit constructors that use super
9+
parameters.
810

911
[#975]: https://github.com/google/protobuf.dart/issues/975
1012
[#952]: https://github.com/google/protobuf.dart/issues/952

protoc_plugin/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ TEST_PROTO_LIST = \
2626
dart_name \
2727
deprecations \
2828
doc_comments \
29-
default_value_escape \
29+
default_value_escape \
3030
entity \
3131
enum_extension \
3232
enum_name \

protoc_plugin/lib/src/grpc_generator.dart

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,34 +108,28 @@ class GrpcServiceGenerator {
108108
void _generateClient(IndentingWriter out) {
109109
if (_descriptor.options.deprecated) {
110110
out.println(
111-
'@$coreImportPrefix.Deprecated(\'This service is deprecated\')');
111+
"@$coreImportPrefix.Deprecated('This service is deprecated')");
112112
}
113-
out.println(
114-
'@$protobufImportPrefix.GrpcServiceName(\'$_fullServiceName\')');
113+
out.println("@$protobufImportPrefix.GrpcServiceName('$_fullServiceName')");
115114
out.addBlock('class $_clientClassname extends $_client {', '}', () {
116115
for (final method in _methods) {
117116
method.generateClientMethodDescriptor(out);
118117
}
119118
out.println();
120-
out.println('$_clientClassname($_clientChannel channel,');
121-
out.println(' {$_callOptions? options,');
122119
out.println(
123-
' $coreImportPrefix.Iterable<$_interceptor>? interceptors})');
124-
out.println(' : super(channel, options: options,');
125-
out.println(' interceptors: interceptors);');
120+
'$_clientClassname(super.channel, {super.options, super.interceptors});');
126121
for (final method in _methods) {
127122
method.generateClientStub(out);
128123
}
129124
});
130125
}
131126

132127
void _generateService(IndentingWriter out) {
133-
out.println(
134-
'@$protobufImportPrefix.GrpcServiceName(\'$_fullServiceName\')');
128+
out.println("@$protobufImportPrefix.GrpcServiceName('$_fullServiceName')");
135129
out.addBlock('abstract class $_serviceClassname extends $_service {', '}',
136130
() {
137131
out.println(
138-
'$coreImportPrefix.String get \$name => \'$_fullServiceName\';');
132+
"$coreImportPrefix.String get \$name => '$_fullServiceName';");
139133
out.println();
140134
out.addBlock('$_serviceClassname() {', '}', () {
141135
for (final method in _methods) {
@@ -153,9 +147,7 @@ class GrpcServiceGenerator {
153147
}
154148

155149
static final String _callOptions = '$grpcImportPrefix.CallOptions';
156-
static final String _interceptor = '$grpcImportPrefix.ClientInterceptor';
157150
static final String _client = '$grpcImportPrefix.Client';
158-
static final String _clientChannel = '$grpcImportPrefix.ClientChannel';
159151
static final String _service = '$grpcImportPrefix.Service';
160152
}
161153

protoc_plugin/test/golden_file.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void expectMatchesGoldenFile(String actual, String goldenFilePath) {
1616
expect(actual, equals(goldenFile.readAsStringSync()),
1717
reason: 'goldenFilePath: "$goldenFilePath"');
1818
} else {
19-
// This enables writing the updated file when the run in otherwise hermetic
19+
// This enables writing the updated file when run in otherwise hermetic
2020
// settings.
2121
final workspaceDirectory =
2222
Platform.environment['BUILD_WORKSPACE_DIRECTORY'];

protoc_plugin/test/goldens/grpc_service.pbgrpc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ class TestClient extends $grpc.Client {
4646
($0.Input value) => value.writeToBuffer(),
4747
($core.List<$core.int> value) => $0.Output.fromBuffer(value));
4848

49-
TestClient($grpc.ClientChannel channel,
50-
{$grpc.CallOptions? options,
51-
$core.Iterable<$grpc.ClientInterceptor>? interceptors})
52-
: super(channel, options: options,
53-
interceptors: interceptors);
49+
TestClient(super.channel, {super.options, super.interceptors});
5450

5551
$grpc.ResponseFuture<$0.Output> unary($0.Input request, {$grpc.CallOptions? options}) {
5652
return $createUnaryCall(_$unary, request, options: options);

0 commit comments

Comments
 (0)