Skip to content

Commit

Permalink
protoc_plugin: Reword some of the documentation (#766)
Browse files Browse the repository at this point in the history
- Convert "Returns true if ..." to "Whether ...", for consistency with
  other documentation and Effective Dart guidelines.

- Add a note in `ProtobufField.hasPresence` to mention that `isRepeated`
  is true for map fields as well.

- Remove example in `getDartType` documentation. It sounds like `List`
  is a special case.
  • Loading branch information
osa1 committed Oct 18, 2022
1 parent 243ceeb commit ba29983
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion protoc_plugin/lib/mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PbMixin {
/// Typically used for static helpers since you cannot mix in static members.
final List<String>? injectedHelpers;

/// If `True` the mixin should have static methods for converting to and from
/// Whether the mixin should have static methods for converting to and from
/// proto3 Json.
final bool hasProto3JsonHelpers;

Expand Down
2 changes: 1 addition & 1 deletion protoc_plugin/lib/src/file_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class FileGenerator extends ProtobufContainer {
final Set<String> usedExtensionNames = <String>{}
..addAll(forbiddenExtensionNames);

/// True if cross-references have been resolved.
/// Whether cross-references have been resolved.
bool _linked = false;

final ProtoSyntax syntax;
Expand Down
11 changes: 5 additions & 6 deletions protoc_plugin/lib/src/protobuf_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ProtobufField {
/// `null` for an extension.
int? get sourcePosition => memberNames?.sourcePosition;

/// True if the field is to be encoded with [deprecated = true] encoding.
/// Whether the field is to be encoded with [deprecated = true] encoding.
bool get isDeprecated => descriptor.options.deprecated;

bool get isRequired =>
Expand Down Expand Up @@ -109,20 +109,21 @@ class ProtobufField {
bool get overridesClearMethod =>
_hasBooleanOption(Dart_options.overrideClearMethod);

/// True if this field uses the Int64 from the fixnum package.
/// Whether this field uses the Int64 from the fixnum package.
bool get needsFixnumImport =>
baseType.unprefixed == '$_fixnumImportPrefix.Int64';

/// True if this field is a map field definition:
/// Whether this field is a map field definition:
/// `map<key_type, value_type> map_field = N`.
bool get isMapField {
if (!isRepeated || !baseType.isMessage) return false;
final generator = baseType.generator as MessageGenerator;
return generator._descriptor.options.mapEntry;
}

// `true` if this field should have a `hazzer` generated.
/// Whether this field should have a `hazzer` generated.
bool get hasPresence {
// NB. Map fields are represented as repeated message fields
if (isRepeated) return false;
return true;
// TODO(sigurdm): to provide the correct semantics for non-optional proto3
Expand All @@ -140,8 +141,6 @@ class ProtobufField {
}

/// Returns the expression to use for the Dart type.
///
/// This will be a List for repeated types.
String getDartType() {
if (isMapField) {
final d = baseType.generator as MessageGenerator;
Expand Down

0 comments on commit ba29983

Please sign in to comment.