Skip to content

Commit 8dc3cbd

Browse files
author
Johyn Papin
committed
Replaces isNullable with isOptional.
Signed-off-by: Johyn Papin <[email protected]>
1 parent 54bbcb2 commit 8dc3cbd

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

protoc_plugin/lib/src/message_generator.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class MessageGenerator extends ProtobufContainer {
490490
var defaultExpr = field.getDefaultExpr();
491491
var names = field.memberNames;
492492

493-
if (useNullable && field.isNullable) {
493+
if (useNullable && field.isOptional) {
494494
fieldTypeString += '?';
495495
}
496496

@@ -503,7 +503,7 @@ class MessageGenerator extends ProtobufContainer {
503503
defaultExpr,
504504
field.isRepeated,
505505
field.isMapField,
506-
useNullable && field.isNullable);
506+
useNullable && field.isOptional);
507507
out.printlnAnnotated(
508508
'$fieldTypeString get ${names!.fieldName} => $getterExpr;', [
509509
NamedLocation(
@@ -531,7 +531,7 @@ class MessageGenerator extends ProtobufContainer {
531531
_emitOverrideIf(field.overridesSetter, out);
532532
_emitIndexAnnotation(field.number, out);
533533
if (fastSetter != null) {
534-
if (useNullable && field.isNullable) {
534+
if (useNullable && field.isOptional) {
535535
fastSetter += 'Nullable';
536536
}
537537
out.printlnAnnotated(
@@ -547,7 +547,7 @@ class MessageGenerator extends ProtobufContainer {
547547
]);
548548
} else {
549549
final setterName =
550-
useNullable && field.isNullable ? 'setFieldNullable' : 'setField';
550+
useNullable && field.isOptional ? 'setFieldNullable' : 'setField';
551551

552552
out.printlnAnnotated(
553553
'set ${names.fieldName}'

protoc_plugin/lib/src/protobuf_field.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class ProtobufField {
6565
bool get isRepeated =>
6666
descriptor.label == FieldDescriptorProto_Label.LABEL_REPEATED;
6767

68+
bool get isOptional {
69+
if (isRepeated) return false;
70+
if (isRequired || !descriptor.proto3Optional) return false;
71+
return true;
72+
}
73+
6874
/// Whether a numeric field is repeated and must be encoded with packed
6975
/// encoding.
7076
///
@@ -140,12 +146,6 @@ class ProtobufField {
140146
// for example in package:protobuf/src/protobuf/mixins/well_known.dart.
141147
}
142148

143-
bool get isNullable {
144-
if (isRepeated) return false;
145-
if (isRequired) return false;
146-
return descriptor.proto3Optional || baseType.isMessage;
147-
}
148-
149149
/// Returns the expression to use for the Dart type.
150150
String getDartType() {
151151
if (isMapField) {

0 commit comments

Comments
 (0)