use super params in generated grpc service classes (#988)
- update the GRPC service generator to emit constructors that use super parameters
diff --git a/protoc_plugin/CHANGELOG.md b/protoc_plugin/CHANGELOG.md
index b47f38c..2f1f593 100644
--- a/protoc_plugin/CHANGELOG.md
+++ b/protoc_plugin/CHANGELOG.md
@@ -5,6 +5,8 @@
([#952])
* Add fromDart() and toDart() methods to convert between core Duration and proto
Duration ([#986])
+* Update the GRPC service generator to emit constructors that use super
+ parameters.
[#975]: https://github.com/google/protobuf.dart/issues/975
[#952]: https://github.com/google/protobuf.dart/issues/952
diff --git a/protoc_plugin/Makefile b/protoc_plugin/Makefile
index 0aa7a13..bab82e3 100644
--- a/protoc_plugin/Makefile
+++ b/protoc_plugin/Makefile
@@ -26,7 +26,7 @@
dart_name \
deprecations \
doc_comments \
- default_value_escape \
+ default_value_escape \
entity \
enum_extension \
enum_name \
diff --git a/protoc_plugin/lib/src/grpc_generator.dart b/protoc_plugin/lib/src/grpc_generator.dart
index a6e3736..1d9257c 100644
--- a/protoc_plugin/lib/src/grpc_generator.dart
+++ b/protoc_plugin/lib/src/grpc_generator.dart
@@ -108,21 +108,16 @@
void _generateClient(IndentingWriter out) {
if (_descriptor.options.deprecated) {
out.println(
- '@$coreImportPrefix.Deprecated(\'This service is deprecated\')');
+ "@$coreImportPrefix.Deprecated('This service is deprecated')");
}
- out.println(
- '@$protobufImportPrefix.GrpcServiceName(\'$_fullServiceName\')');
+ out.println("@$protobufImportPrefix.GrpcServiceName('$_fullServiceName')");
out.addBlock('class $_clientClassname extends $_client {', '}', () {
for (final method in _methods) {
method.generateClientMethodDescriptor(out);
}
out.println();
- out.println('$_clientClassname($_clientChannel channel,');
- out.println(' {$_callOptions? options,');
out.println(
- ' $coreImportPrefix.Iterable<$_interceptor>? interceptors})');
- out.println(' : super(channel, options: options,');
- out.println(' interceptors: interceptors);');
+ '$_clientClassname(super.channel, {super.options, super.interceptors});');
for (final method in _methods) {
method.generateClientStub(out);
}
@@ -130,12 +125,11 @@
}
void _generateService(IndentingWriter out) {
- out.println(
- '@$protobufImportPrefix.GrpcServiceName(\'$_fullServiceName\')');
+ out.println("@$protobufImportPrefix.GrpcServiceName('$_fullServiceName')");
out.addBlock('abstract class $_serviceClassname extends $_service {', '}',
() {
out.println(
- '$coreImportPrefix.String get \$name => \'$_fullServiceName\';');
+ "$coreImportPrefix.String get \$name => '$_fullServiceName';");
out.println();
out.addBlock('$_serviceClassname() {', '}', () {
for (final method in _methods) {
@@ -153,9 +147,7 @@
}
static final String _callOptions = '$grpcImportPrefix.CallOptions';
- static final String _interceptor = '$grpcImportPrefix.ClientInterceptor';
static final String _client = '$grpcImportPrefix.Client';
- static final String _clientChannel = '$grpcImportPrefix.ClientChannel';
static final String _service = '$grpcImportPrefix.Service';
}
diff --git a/protoc_plugin/test/golden_file.dart b/protoc_plugin/test/golden_file.dart
index 64b95aa..42af0f8 100644
--- a/protoc_plugin/test/golden_file.dart
+++ b/protoc_plugin/test/golden_file.dart
@@ -16,7 +16,7 @@
expect(actual, equals(goldenFile.readAsStringSync()),
reason: 'goldenFilePath: "$goldenFilePath"');
} else {
- // This enables writing the updated file when the run in otherwise hermetic
+ // This enables writing the updated file when run in otherwise hermetic
// settings.
final workspaceDirectory =
Platform.environment['BUILD_WORKSPACE_DIRECTORY'];
diff --git a/protoc_plugin/test/goldens/grpc_service.pbgrpc b/protoc_plugin/test/goldens/grpc_service.pbgrpc
index c8f2cb8..2d6d5a2 100644
--- a/protoc_plugin/test/goldens/grpc_service.pbgrpc
+++ b/protoc_plugin/test/goldens/grpc_service.pbgrpc
@@ -46,11 +46,7 @@
($0.Input value) => value.writeToBuffer(),
($core.List<$core.int> value) => $0.Output.fromBuffer(value));
- TestClient($grpc.ClientChannel channel,
- {$grpc.CallOptions? options,
- $core.Iterable<$grpc.ClientInterceptor>? interceptors})
- : super(channel, options: options,
- interceptors: interceptors);
+ TestClient(super.channel, {super.options, super.interceptors});
$grpc.ResponseFuture<$0.Output> unary($0.Input request, {$grpc.CallOptions? options}) {
return $createUnaryCall(_$unary, request, options: options);