Skip to content

Commit 2024979

Browse files
author
Johyn Papin
committed
Replaces isNullable with isOptional.
Signed-off-by: Johyn Papin <[email protected]>
1 parent 4bd55db commit 2024979

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
@@ -498,7 +498,7 @@ class MessageGenerator extends ProtobufContainer {
498498
final defaultExpr = field.getDefaultExpr();
499499
final names = field.memberNames;
500500

501-
if (useNullable && field.isNullable) {
501+
if (useNullable && field.isOptional) {
502502
fieldTypeString += '?';
503503
}
504504

@@ -511,7 +511,7 @@ class MessageGenerator extends ProtobufContainer {
511511
defaultExpr,
512512
field.isRepeated,
513513
field.isMapField,
514-
useNullable && field.isNullable);
514+
useNullable && field.isOptional);
515515
out.printlnAnnotated(
516516
'$fieldTypeString get ${names!.fieldName} => $getterExpr;', [
517517
NamedLocation(
@@ -539,7 +539,7 @@ class MessageGenerator extends ProtobufContainer {
539539
_emitOverrideIf(field.overridesSetter, out);
540540
_emitIndexAnnotation(field.number, out);
541541
if (fastSetter != null) {
542-
if (useNullable && field.isNullable) {
542+
if (useNullable && field.isOptional) {
543543
fastSetter += 'Nullable';
544544
}
545545
out.printlnAnnotated(
@@ -555,7 +555,7 @@ class MessageGenerator extends ProtobufContainer {
555555
]);
556556
} else {
557557
final setterName =
558-
useNullable && field.isNullable ? 'setFieldNullable' : 'setField';
558+
useNullable && field.isOptional ? 'setFieldNullable' : 'setField';
559559

560560
out.printlnAnnotated(
561561
'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)