Skip to content

Commit 5f99de4

Browse files
author
Ivan Dlugos
committed
generated code - improve names of generated temporary/internal variables (offset and value)
1 parent 27bbb12 commit 5f99de4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

generator/lib/src/code_chunks.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CodeChunks {
118118
// prepare properties that must be defined before the FB table is started
119119
final offsets = <int, String>{};
120120
final offsetsCode = entity.properties.map((ModelProperty p) {
121-
final offsetVar = 'offset${propertyFieldName(p)}';
121+
final offsetVar = '${propertyFieldName(p)}Offset';
122122
var fieldName = 'object.${propertyFieldName(p)}';
123123
offsets[p.id.id] = offsetVar; // see default case in the switch
124124

@@ -199,6 +199,7 @@ class CodeChunks {
199199
'const $fbReader.vTableGet(buffer, rootOffset, ${propertyFlatBuffersvTableOffset(p)}, ${defaultValue ?? fieldDefaultValue(p)})';
200200
var readField =
201201
() => p.fieldIsNullable ? readFieldOrNull() : readFieldNonNull();
202+
final valueVar = '${propertyFieldName(p)}Value';
202203

203204
switch (p.type) {
204205
case OBXPropertyType.ByteVector:
@@ -208,8 +209,8 @@ class CodeChunks {
208209
fbReader = 'fb.ListReader<int>(fb.Int8Reader())';
209210
if (p.fieldIsNullable) {
210211
preLines.add(
211-
'final val${propertyFieldName(p)} = ${readFieldOrNull()};');
212-
return 'val${propertyFieldName(p)} == null ? null : ${p.fieldType}.fromList(val${propertyFieldName(p)})';
212+
'final $valueVar = ${readFieldOrNull()};');
213+
return '$valueVar == null ? null : ${p.fieldType}.fromList($valueVar)';
213214
} else {
214215
return '${p.fieldType}.fromList(${readFieldNonNull('[]')})';
215216
}
@@ -229,11 +230,11 @@ class CodeChunks {
229230
if (p.fieldType == 'DateTime') {
230231
if (p.fieldIsNullable) {
231232
preLines
232-
.add('final val${propertyFieldName(p)} = ${readFieldOrNull()};');
233+
.add('final $valueVar = ${readFieldOrNull()};');
233234
if (p.type == OBXPropertyType.Date) {
234-
return 'val${propertyFieldName(p)} == null ? null : DateTime.fromMillisecondsSinceEpoch(val${propertyFieldName(p)})';
235+
return '$valueVar == null ? null : DateTime.fromMillisecondsSinceEpoch($valueVar)';
235236
} else if (p.type == OBXPropertyType.DateNano) {
236-
return 'val${propertyFieldName(p)} == null ? null : DateTime.fromMicrosecondsSinceEpoch((val${propertyFieldName(p)} / 1000).round())';
237+
return '$valueVar == null ? null : DateTime.fromMicrosecondsSinceEpoch(($valueVar / 1000).round())';
237238
}
238239
} else {
239240
if (p.type == OBXPropertyType.DateNano) {

0 commit comments

Comments
 (0)