Index: lib/file_generator.dart |
diff --git a/lib/file_generator.dart b/lib/file_generator.dart |
index a53c46fd24571ca9ebd7752494bba1b5ff130f63..dfbe005eab730f4828fb2b6df0fbd2a362395391 100644 |
--- a/lib/file_generator.dart |
+++ b/lib/file_generator.dart |
@@ -5,17 +5,19 @@ |
part of protoc; |
class FileGenerator extends ProtobufContainer { |
- // This should match the extension in dart_options.proto. |
- static const int implementMapByDefaultOption = 95333044; |
- // Returns true if option implement_map_by_default is on for this file. |
- static bool _shouldImplementMapByDefault(FileDescriptorProto desc) { |
- if (!desc.hasOptions()) return false; |
- |
- var val = desc.options.unknownFields.getField(implementMapByDefaultOption); |
- if (val == null || val.length != 1) return false; |
- |
- return val.values[0] == 1; |
+ /// Returns the name of the mixin to use by default in this file, |
+ /// or null for no mixin by default. |
+ static String _getDefaultMixin(FileDescriptorProto desc) { |
+ if (!desc.hasOptions()) return null; |
+ if (!desc.options.hasExtension(Dart_options.defaultMixin)) { |
+ return null; |
+ } |
+ var name = desc.options.getExtension(Dart_options.defaultMixin); |
+ if (!reservedNamesForMixins.containsKey(name)) { |
+ throw("unknown mixin class: ${name}"); |
+ } |
+ return name; |
} |
final FileDescriptorProto _fileDescriptor; |
@@ -29,7 +31,7 @@ class FileGenerator extends ProtobufContainer { |
FileGenerator(this._fileDescriptor, this._parent, this._context) { |
_context.register(this); |
- bool implementMap = _shouldImplementMapByDefault(_fileDescriptor); |
+ String defaultMixin = _getDefaultMixin(_fileDescriptor); |
// Load and register all enum and message types. |
for (EnumDescriptorProto enumType in _fileDescriptor.enumType) { |
@@ -37,7 +39,7 @@ class FileGenerator extends ProtobufContainer { |
} |
for (DescriptorProto messageType in _fileDescriptor.messageType) { |
messageGenerators.add( |
- new MessageGenerator(messageType, this, _context, implementMap)); |
+ new MessageGenerator(messageType, this, _context, defaultMixin)); |
} |
for (FieldDescriptorProto extension in _fileDescriptor.extension) { |
extensionGenerators.add( |
@@ -97,10 +99,6 @@ class FileGenerator extends ProtobufContainer { |
"import 'package:protobuf/protobuf.dart';" |
); |
- if (needsMapMixinImport) { |
- out.println("import 'dart:collection' show MapMixin;"); |
- } |
- |
for (String import in _fileDescriptor.dependency) { |
Uri importPath = new Uri.file(import); |
if (importPath.isAbsolute) { |
@@ -152,15 +150,6 @@ class FileGenerator extends ProtobufContainer { |
}); |
} |
} |
- |
- bool get needsMapMixinImport { |
- for (var m in messageGenerators) { |
- if (m.needsMapMixinImport) { |
- return true; |
- } |
- } |
- return false; |
- } |
} |
class GenerationContext { |