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. |