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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 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,12 @@ 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 {
_protoName ??= _unCamelCase(name);
return _protoName!;
jiahaog marked this conversation as resolved.
Show resolved Hide resolved
}

String? _protoName;

/// Field number as specified in the proto definition. Example:
/// ```proto
Expand Down Expand Up @@ -80,7 +85,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 +95,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 +109,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