Skip to content

Commit e552b48

Browse files
committed
minor review changes
1 parent 0dc6461 commit e552b48

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

generator/integration-tests/basics/1.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ void main() {
4949
expect(property(model, 'T.tDate').type, OBXPropertyType.Date);
5050
expect(property(model, 'T.tDateNano').type, OBXPropertyType.DateNano);
5151
expect(property(model, 'T.tListInt').type, OBXPropertyType.ByteVector);
52-
expect(property(model, 'T.tListInt').flags, 0);
5352
expect(property(model, 'T.tInt8List').type, OBXPropertyType.ByteVector);
54-
expect(property(model, 'T.tInt8List').flags, 0);
5553
expect(property(model, 'T.tUint8List').type, OBXPropertyType.ByteVector);
56-
expect(property(model, 'T.tUint8List').flags, OBXPropertyFlags.UNSIGNED);
5754
expect(property(model, 'T.tListString').type, OBXPropertyType.StringVector);
5855
});
5956
}

generator/lib/src/entity_resolver.dart

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,10 @@ class EntityResolver extends Builder {
145145
fieldType = OBXPropertyType.StringVector;
146146
} else if (fieldTypeDart.element.name == 'Int8List') {
147147
fieldType = OBXPropertyType.ByteVector;
148-
dartFieldType =
149-
fieldTypeDart.element.name; // needed for code generation
148+
dartFieldType = fieldTypeDart.element.name; // for code generation
150149
} else if (fieldTypeDart.element.name == 'Uint8List') {
151150
fieldType = OBXPropertyType.ByteVector;
152-
// TODO check if UNSIGNED also applies to byte-vector in the core
153-
flags |= OBXPropertyFlags.UNSIGNED;
154-
dartFieldType =
155-
fieldTypeDart.element.name; // needed for code generation
151+
dartFieldType = fieldTypeDart.element.name; // for code generation
156152
} else {
157153
log.warning(
158154
" skipping property '${f.name}' in entity '${element.name}', as it has an unsupported type: '${fieldTypeDart}'");
@@ -206,23 +202,8 @@ class EntityResolver extends Builder {
206202

207203
// If available use index type from annotation.
208204
if (indexAnnotation != null && !indexAnnotation.isNull) {
209-
// find out @Index(type:) value - its an enum IndexType
210-
final indexTypeField = indexAnnotation.getField('type');
211-
if (!indexTypeField.isNull) {
212-
final indexTypeEnumValues = (indexTypeField.type as InterfaceType)
213-
.element
214-
.fields
215-
.where((f) => f.isEnumConstant)
216-
.toList();
217-
218-
// Find the index of the matching enum constant.
219-
for (var i = 0; i < indexTypeEnumValues.length; i++) {
220-
if (indexTypeEnumValues[i].computeConstantValue() == indexTypeField) {
221-
indexType = obx.IndexType.values[i];
222-
break;
223-
}
224-
}
225-
}
205+
final enumValItem = enumValueItem(indexAnnotation.getField('type'));
206+
if (enumValItem != null) indexType = obx.IndexType.values[enumValItem];
226207
}
227208

228209
// Fall back to index type based on property type.
@@ -263,25 +244,33 @@ class EntityResolver extends Builder {
263244
}
264245
}
265246

266-
// find out @Property(type:) field value - its an enum PropertyType
267-
int /*?*/ propertyTypeFromAnnotation(DartObject typeField) {
268-
if (typeField.isNull) return null;
269-
final enumValues = (typeField.type as InterfaceType)
270-
.element
271-
.fields
272-
.where((f) => f.isEnumConstant)
273-
.toList();
274-
275-
// Find the index of the matching enum constant.
276-
for (var i = 0; i < enumValues.length; i++) {
277-
if (enumValues[i].computeConstantValue() == typeField) {
278-
return propertyTypeToOBXPropertyType(obx.PropertyType.values[i]);
247+
int /*?*/ enumValueItem(DartObject typeField) {
248+
if (!typeField.isNull) {
249+
final enumValues = (typeField.type as InterfaceType)
250+
.element
251+
.fields
252+
.where((f) => f.isEnumConstant)
253+
.toList();
254+
255+
// Find the index of the matching enum constant.
256+
for (var i = 0; i < enumValues.length; i++) {
257+
if (enumValues[i].computeConstantValue() == typeField) {
258+
return i;
259+
}
279260
}
280261
}
281262

282263
return null;
283264
}
284265

266+
// find out @Property(type:) field value - its an enum PropertyType
267+
int /*?*/ propertyTypeFromAnnotation(DartObject typeField) {
268+
final item = enumValueItem(typeField);
269+
return item == null
270+
? null
271+
: propertyTypeToOBXPropertyType(obx.PropertyType.values[item]);
272+
}
273+
285274
DartType /*?*/ listItemType(DartType listType) {
286275
final typeArgs =
287276
listType is ParameterizedType ? listType.typeArguments : [];

test/query_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ void main() {
206206
final prop = TestEntity_.tStrings;
207207

208208
final qs0 = box.query(prop.contains('bar')).build();
209-
final qs1 = box.query(prop.contains('ar')).build();
210-
final qs2 = box.query(prop.contains('foo')).build();
211-
212209
expect(qs0.count(), 1);
210+
211+
final qs1 = box.query(prop.contains('ar')).build();
213212
expect(qs1.count(), 0);
213+
214+
final qs2 = box.query(prop.contains('foo')).build();
214215
expect(qs2.count(), 2);
215216

216217
[qs0, qs1, qs2].forEach((q) => q.close());

0 commit comments

Comments
 (0)