Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make protoName unCamelCase lazy #606

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions protobuf/lib/src/protobuf/field_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ class FieldInfo<T> {
/// ```
/// `protoName` for the `result_per_page` field above is `"result_per_page"`.
/// This will typically consist of words separated with underscores.
final String protoName;
String get protoName {
return _protoName ??= _unCamelCase(name);
}

String? _protoName;

/// Field number as specified in the proto definition. Example:
/// ```proto
Expand Down Expand Up @@ -80,7 +84,7 @@ class FieldInfo<T> {
String? protoName})
: makeDefault = findMakeDefault(type, defaultOrMaker),
check = null,
protoName = protoName ?? _unCamelCase(name),
_protoName = protoName,
assert(type != 0),
assert(!_isGroupOrMessage(type) ||
subBuilder != null ||
Expand All @@ -90,7 +94,7 @@ class FieldInfo<T> {
// Represents a field that has been removed by a program transformation.
FieldInfo.dummy(this.index)
: name = '<removed field>',
protoName = '<removed field>',
_protoName = '<removed field>',
tagNumber = 0,
type = 0,
makeDefault = null,
Expand All @@ -104,7 +108,7 @@ class FieldInfo<T> {
this.check, this.subBuilder,
{this.valueOf, this.enumValues, this.defaultEnumValue, String? protoName})
: makeDefault = (() => PbList<T>(check: check!)),
protoName = protoName ?? _unCamelCase(name) {
_protoName = protoName {
ArgumentError.checkNotNull(name, 'name');
ArgumentError.checkNotNull(tagNumber, 'tagNumber');
assert(_isRepeated(type));
Expand Down