Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Unified Diff: lib/file_generator.dart

Issue 1196293003: Initial support for generating client and server stubs for Dart. (Closed) Base URL: https://github.com/dart-lang/dart-protoc-plugin.git@master
Patch Set: adddressing nits Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/file_generator.dart
diff --git a/lib/file_generator.dart b/lib/file_generator.dart
index c7f85d2839b60186354c1cc47ae96848c1af43d4..58fa8a32e0cc5c8e03c4e33058d3189ca072f22f 100644
--- a/lib/file_generator.dart
+++ b/lib/file_generator.dart
@@ -28,6 +28,8 @@ class FileGenerator extends ProtobufContainer {
final List<EnumGenerator> enumGenerators = <EnumGenerator>[];
final List<MessageGenerator> messageGenerators = <MessageGenerator>[];
final List<ExtensionGenerator> extensionGenerators = <ExtensionGenerator>[];
+ final List<ClientApiGenerator> clientApiGenerators = <ClientApiGenerator>[];
+ final List<ServiceGenerator> serviceGenerators = <ServiceGenerator>[];
FileGenerator(this._fileDescriptor, this._parent, this._context) {
_context.register(this);
@@ -46,6 +48,10 @@ class FileGenerator extends ProtobufContainer {
extensionGenerators.add(
new ExtensionGenerator(extension, this, _context));
}
+ for (ServiceDescriptorProto service in _fileDescriptor.service) {
+ serviceGenerators.add(new ServiceGenerator(service, this, _context));
+ clientApiGenerators.add(new ClientApiGenerator(service, this, _context));
+ }
}
String get package => _fileDescriptor.package;
@@ -90,12 +96,17 @@ class FileGenerator extends ProtobufContainer {
String libraryName = _generateLibraryName(filePath);
+ // Print header and imports. We only add the dart:async import if there
+ // are services in the FileDescriptorProto.
out.println(
'///\n'
'// Generated code. Do not modify.\n'
'///\n'
- 'library $libraryName;\n'
- '\n'
+ 'library $libraryName;\n');
+ if (_fileDescriptor.service.isNotEmpty) {
+ out.println("import 'dart:async';\n");
+ }
+ out.println(
"import 'package:fixnum/fixnum.dart';\n"
"import 'package:protobuf/protobuf.dart';"
);
@@ -158,6 +169,13 @@ class FileGenerator extends ProtobufContainer {
out.println('}');
});
}
+
+ for (ClientApiGenerator c in clientApiGenerators) {
+ c.generate(out);
+ }
+ for (ServiceGenerator s in serviceGenerators) {
+ s.generate(out);
+ }
}
/// Returns a map from import names to the Dart symbols to be imported.
« no previous file with comments | « lib/client_generator.dart ('k') | lib/indenting_writer.dart » ('j') | test/service_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698