Various cleanup and formatting fixes. (#249)
* Various cleanup and formatting fixes.
diff --git a/protobuf/lib/meta.dart b/protobuf/lib/meta.dart
index 0507114..f50bc77 100644
--- a/protobuf/lib/meta.dart
+++ b/protobuf/lib/meta.dart
@@ -8,51 +8,53 @@
// List of names which cannot be used in a subclass of GeneratedMessage.
const GeneratedMessage_reservedNames = <String>[
- 'hashCode',
- 'noSuchMethod',
+ '==',
+ 'GeneratedMessage',
+ 'Object',
+ 'addExtension',
+ 'check',
+ 'clear',
+ 'clearExtension',
+ 'clearField',
+ 'clone',
'copyWith',
'createEmptyInstance',
- 'runtimeType',
- 'toString',
+ 'createMapField',
+ 'createRepeatedField',
+ 'eventPlugin',
+ 'extensionsAreInitialized',
'freeze',
'fromBuffer',
'fromJson',
- 'hasRequiredFields',
- 'isInitialized',
- 'clear',
- 'getTagNumber',
- 'check',
- 'writeToBuffer',
- 'writeToCodedBufferWriter',
- 'mergeFromCodedBufferReader',
- 'mergeFromBuffer',
- 'writeToJson',
- 'mergeFromJson',
- 'writeToJsonMap',
- 'mergeFromJsonMap',
- 'addExtension',
+ 'getDefaultForField',
'getExtension',
- 'setExtension',
- 'hasExtension',
- 'clearExtension',
'getField',
'getFieldOrNull',
- 'getDefaultForField',
- 'setField',
+ 'getTagNumber',
+ 'hasExtension',
'hasField',
- 'clearField',
- 'extensionsAreInitialized',
+ 'hasRequiredFields',
+ 'hashCode',
+ 'info_',
+ 'isInitialized',
+ 'mergeFromBuffer',
+ 'mergeFromCodedBufferReader',
+ 'mergeFromJson',
+ 'mergeFromJsonMap',
'mergeFromMessage',
'mergeUnknownFields',
- '==',
- 'info_',
- 'GeneratedMessage',
- 'Object',
- 'eventPlugin',
- 'createMapField',
- 'createRepeatedField',
+ 'noSuchMethod',
+ 'runtimeType',
+ 'setExtension',
+ 'setField',
+ 'toBuilder',
+ 'toDebugString',
+ 'toString',
'unknownFields',
- 'clone',
+ 'writeToBuffer',
+ 'writeToCodedBufferWriter',
+ 'writeToJson',
+ 'writeToJsonMap',
r'$_get',
r'$_getI64',
r'$_getList',
@@ -62,15 +64,13 @@
r'$_has',
r'$_setBool',
r'$_setBytes',
- r'$_setString',
- r'$_setFloat',
r'$_setDouble',
- r'$_setSignedInt32',
- r'$_setUnsignedInt32',
+ r'$_setFloat',
r'$_setInt64',
+ r'$_setSignedInt32',
+ r'$_setString',
+ r'$_setUnsignedInt32',
r'$_whichOneof',
- 'toBuilder',
- 'toDebugString',
];
// List of names which cannot be used in a subclass of ProtobufEnum.
diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart
index 5c4d99b..1b76048 100644
--- a/protobuf/lib/src/protobuf/field_set.dart
+++ b/protobuf/lib/src/protobuf/field_set.dart
@@ -594,11 +594,11 @@
// TODO(skybrian): possibly unused. Delete?
final value = fieldValue.getUint64(0, Endian.little);
renderValue(name, value);
- } else if (fieldValue is List) {
+ } else if (fieldValue is PbListBase) {
for (var value in fieldValue) {
renderValue(name, value);
}
- } else if (fieldValue is Map) {
+ } else if (fieldValue is PbMap) {
for (var entry in fieldValue.entries) {
renderValue(name, entry);
}
diff --git a/protoc_plugin/lib/message_generator.dart b/protoc_plugin/lib/message_generator.dart
index fd1a7e7..643ec84 100644
--- a/protoc_plugin/lib/message_generator.dart
+++ b/protoc_plugin/lib/message_generator.dart
@@ -64,7 +64,7 @@
/// The nested message will have a `fullName` of 'foo.Container.Nested', and a
/// `messageName` of 'Container.Nested'.
String get messageName =>
- fullName.substring(package.length == 0 ? 0 : package.length + 1);
+ fullName.substring(package.isEmpty ? 0 : package.length + 1);
final PbMixin mixin;
@@ -333,19 +333,19 @@
'static final $_protobufImportPrefix.BuilderInfo _i = '
'$_protobufImportPrefix.BuilderInfo(\'${messageName}\'$packageClause)',
';', () {
- for (ProtobufField field in _fieldList) {
- var dartFieldName = field.memberNames.fieldName;
- out.println(
- field.generateBuilderInfoCall(fileGen, dartFieldName, package));
- }
-
for (int oneof = 0; oneof < _oneofFields.length; oneof++) {
List<int> tags =
_oneofFields[oneof].map((ProtobufField f) => f.number).toList();
out.println("..oo($oneof, ${tags})");
}
- if (_descriptor.extensionRange.length > 0) {
+ for (ProtobufField field in _fieldList) {
+ var dartFieldName = field.memberNames.fieldName;
+ out.println(
+ field.generateBuilderInfoCall(fileGen, dartFieldName, package));
+ }
+
+ if (_descriptor.extensionRange.isNotEmpty) {
out.println('..hasExtensions = true');
}
if (!_hasRequiredFields(this, Set())) {
@@ -417,7 +417,7 @@
// If the type has extensions, an extension with message type could contain
// required fields, so we have to be conservative and assume such an
// extension exists.
- if (type._descriptor.extensionRange.length > 0) {
+ if (type._descriptor.extensionRange.isNotEmpty) {
return true;
}
@@ -437,7 +437,7 @@
void generateFieldsAccessorsMutators(IndentingWriter out) {
_oneofNames
- .forEach((OneofNames oneof) => generateoneOfAccessors(out, oneof));
+ .forEach((OneofNames oneof) => generateOneofAccessors(out, oneof));
for (var field in _fieldList) {
out.println();
@@ -447,7 +447,7 @@
}
}
- void generateoneOfAccessors(IndentingWriter out, OneofNames oneof) {
+ void generateOneofAccessors(IndentingWriter out, OneofNames oneof) {
out.println();
out.println("${oneof.oneofEnumName} ${oneof.whichOneofMethodName}() "
"=> ${oneof.byTagMapName}[\$_whichOneof(${oneof.index})];");
diff --git a/protoc_plugin/lib/names.dart b/protoc_plugin/lib/names.dart
index bac5055..d85d757 100644
--- a/protoc_plugin/lib/names.dart
+++ b/protoc_plugin/lib/names.dart
@@ -42,23 +42,23 @@
{this.hasMethodName, this.clearMethodName});
}
-// The Dart names associated with a oneof declaration.
+/// The Dart names associated with a oneof declaration.
class OneofNames {
final OneofDescriptorProto descriptor;
- // Index in the containing type's oneof_decl list.
+ /// Index in the containing type's oneof_decl list.
final int index;
- // Identifier for the generated whichX() method, without braces.
+ /// Identifier for the generated whichX() method, without braces.
final String whichOneofMethodName;
- // Identifier for the generated clearX() method, without braces.
+ /// Identifier for the generated clearX() method, without braces.
final String clearMethodName;
- // Identifier for the generated enum definition.
+ /// Identifier for the generated enum definition.
final String oneofEnumName;
- // Identifier for the _XByTag map.
+ /// Identifier for the _XByTag map.
final String byTagMapName;
OneofNames(this.descriptor, this.index, this.clearMethodName,
@@ -528,4 +528,4 @@
];
// List of names used in Dart enums, which can't be used as enum member names.
-const _oneofEnumMemberNames = const <String>['index', 'values'];
+const _oneofEnumMemberNames = <String>['default', 'index', 'values'];
diff --git a/protoc_plugin/lib/options.dart b/protoc_plugin/lib/options.dart
index 4ab10cd..232944c 100644
--- a/protoc_plugin/lib/options.dart
+++ b/protoc_plugin/lib/options.dart
@@ -38,7 +38,7 @@
parser.parse(name, value, reportError);
}
- if (errors.length == 0) return true;
+ if (errors.isEmpty) return true;
response.error = errors.join('\n');
return false;
diff --git a/protoc_plugin/lib/protobuf_field.dart b/protoc_plugin/lib/protobuf_field.dart
index ed04415..8effeae 100644
--- a/protoc_plugin/lib/protobuf_field.dart
+++ b/protoc_plugin/lib/protobuf_field.dart
@@ -78,7 +78,8 @@
/// True if this field uses the Int64 from the fixnum package.
bool get needsFixnumImport => baseType.unprefixed == "Int64";
- /// True if this field is a map field definition: `map<key_type, value_type> map_field = N`.
+ /// True if this field is a map field definition:
+ /// `map<key_type, value_type> map_field = N`.
bool get isMapField {
if (!isRepeated || !baseType.isMessage) return false;
MessageGenerator generator = baseType.generator;
diff --git a/protoc_plugin/test/all_tests.dart b/protoc_plugin/test/all_tests.dart
index affcb87..347da54 100755
--- a/protoc_plugin/test/all_tests.dart
+++ b/protoc_plugin/test/all_tests.dart
@@ -14,20 +14,23 @@
import 'file_generator_test.dart' as file_generator;
import 'generated_message_test.dart' as generated_message;
import 'hash_code_test.dart' as hash_code;
-import 'indenting_writer_test.dart' as indenting_writer;
import 'import_test.dart' as import_prefix;
+import 'indenting_writer_test.dart' as indenting_writer;
import 'json_test.dart' as json;
import 'leading_underscores_test.dart' as leading_underscores;
+import 'map_field_test.dart' as map_field;
import 'map_test.dart' as map;
import 'merge_test.dart' as merge;
import 'message_generator_test.dart' as message_generator;
import 'message_test.dart' as message;
import 'mixin_test.dart' as mixin_test;
import 'names_test.dart' as names;
+import 'oneof_test.dart' as oneof;
import 'protoc_options_test.dart' as protoc_options;
import 'repeated_field_test.dart' as repeated_field;
import 'service_test.dart' as service;
import 'service_generator_test.dart' as service_generator;
+import 'to_builder_test.dart' as to_builder;
import 'unknown_field_set_test.dart' as unknown_field_set;
import 'validate_fail_test.dart' as validate_fail;
import 'wire_format_test.dart' as wire_format;
@@ -42,20 +45,23 @@
file_generator.main();
generated_message.main();
hash_code.main();
- indenting_writer.main();
import_prefix.main();
+ indenting_writer.main();
json.main();
leading_underscores.main();
map.main();
+ map_field.main();
merge.main();
message_generator.main();
message.main();
mixin_test.main();
names.main();
+ oneof.main();
protoc_options.main();
repeated_field.main();
service.main();
service_generator.main();
+ to_builder.main();
unknown_field_set.main();
validate_fail.main();
wire_format.main();
diff --git a/protoc_plugin/test/leading_underscores_test.dart b/protoc_plugin/test/leading_underscores_test.dart
index 29a52c6..61c4aee 100644
--- a/protoc_plugin/test/leading_underscores_test.dart
+++ b/protoc_plugin/test/leading_underscores_test.dart
@@ -49,7 +49,7 @@
messageA.e = Enum_.constant;
expect(messageA.e, Enum_.constant);
messageA.clearE();
- expect(messageA.e, Enum_.constant_);
+ expect(messageA.e, Enum_.default_);
messageA.r.add(message);
expect(messageA.r, [message]);
messageA.setExtension(Leading_underscores_.q, Int64(100));
diff --git a/protoc_plugin/test/map_field_test.dart b/protoc_plugin/test/map_field_test.dart
index 7c5c35d..5daf488 100644
--- a/protoc_plugin/test/map_field_test.dart
+++ b/protoc_plugin/test/map_field_test.dart
@@ -24,7 +24,7 @@
..int32ToBytesField[1] = utf8.encode('11')
..int32ToBytesField[2] = utf8.encode('22')
..int32ToBytesField[3] = utf8.encode('33')
- ..int32ToEnumField[1] = TestMap_EnumValue.FOO
+ ..int32ToEnumField[1] = TestMap_EnumValue.DEFAULT
..int32ToEnumField[2] = TestMap_EnumValue.BAR
..int32ToEnumField[3] = TestMap_EnumValue.BAZ
..int32ToMessageField[1] = (TestMap_MessageValue()..value = 11)
@@ -79,7 +79,7 @@
expect(testMap.int32ToBytesField[2], utf8.encode('22'));
expect(testMap.int32ToBytesField[3], utf8.encode('33'));
- expect(testMap.int32ToEnumField[1], TestMap_EnumValue.FOO);
+ expect(testMap.int32ToEnumField[1], TestMap_EnumValue.DEFAULT);
expect(testMap.int32ToEnumField[2], TestMap_EnumValue.BAR);
expect(testMap.int32ToEnumField[3], TestMap_EnumValue.BAZ);
diff --git a/protoc_plugin/test/protos/_leading_underscores.proto b/protoc_plugin/test/protos/_leading_underscores.proto
index 600d03b..49067ba 100644
--- a/protoc_plugin/test/protos/_leading_underscores.proto
+++ b/protoc_plugin/test/protos/_leading_underscores.proto
@@ -46,7 +46,7 @@
}
enum _Enum {
- _constant = 0;
+ _default = 0;
constant = 1;
}
diff --git a/protoc_plugin/test/protos/foo.proto b/protoc_plugin/test/protos/foo.proto
index 9c52af8..f573ac9 100644
--- a/protoc_plugin/test/protos/foo.proto
+++ b/protoc_plugin/test/protos/foo.proto
@@ -19,7 +19,7 @@
}
message OuterWithMap {
- map<int32, Inner> innerMap = 3;
+ map<int32, Inner> inner_map = 3;
}
message Inner {
diff --git a/protoc_plugin/test/protos/google/protobuf/unittest_optimize_for.proto b/protoc_plugin/test/protos/google/protobuf/unittest_optimize_for.proto
index 2b36c60..0ac952b 100644
--- a/protoc_plugin/test/protos/google/protobuf/unittest_optimize_for.proto
+++ b/protoc_plugin/test/protos/google/protobuf/unittest_optimize_for.proto
@@ -57,7 +57,7 @@
message TestRequiredOptimizedForSize {
required int32 x = 1;
}
-
+
message TestOptionalOptimizedForSize {
optional TestRequiredOptimizedForSize o = 1;
}
diff --git a/protoc_plugin/test/protos/map_field.proto b/protoc_plugin/test/protos/map_field.proto
index d5af64f..db2a606 100644
--- a/protoc_plugin/test/protos/map_field.proto
+++ b/protoc_plugin/test/protos/map_field.proto
@@ -9,11 +9,11 @@
message TestMap {
message MessageValue {
optional int32 value = 1;
- optional int32 secondValue = 2 [default = 42];
+ optional int32 second_value = 2 [default = 42];
}
enum EnumValue {
- FOO = 0;
+ DEFAULT = 0;
BAR = 1;
BAZ = 2;
ZOP = 3;