From 989ca78f4655752d335434b74409e59f494959e4 Mon Sep 17 00:00:00 2001 From: hendrikvanderkaaden Date: Fri, 24 May 2024 12:46:45 +0200 Subject: [PATCH] Fix format issues --- .../lib/misc/extension/embeds_extension.dart | 7 ++-- .../extension/field_element_extension.dart | 5 +-- .../lib/processor/embed_processor.dart | 6 ++-- .../lib/processor/entity_processor.dart | 5 ++- .../lib/processor/field_processor.dart | 22 ++++++------ .../lib/processor/queryable_processor.dart | 34 ++++++++++++------- floor_generator/lib/value_object/embed.dart | 8 ++--- floor_generator/lib/value_object/field.dart | 19 ++++++----- .../test/processor/entity_processor_test.dart | 30 ++++++++++------ .../processor/queryable_processor_test.dart | 12 ++++--- .../test/processor/view_processor_test.dart | 9 +++-- .../test/value_object/entity_test.dart | 11 ++---- 12 files changed, 95 insertions(+), 73 deletions(-) diff --git a/floor_generator/lib/misc/extension/embeds_extension.dart b/floor_generator/lib/misc/extension/embeds_extension.dart index 0e788da7..a6a01f1d 100644 --- a/floor_generator/lib/misc/extension/embeds_extension.dart +++ b/floor_generator/lib/misc/extension/embeds_extension.dart @@ -7,8 +7,7 @@ extension EmbedsExtension on Iterable { /// Returns the [Embed] in the closest [TypeConverterScope] for /// [dartType] or null Embed? getClosestOrNull(DartType dartType) { - return toList() - .firstWhereOrNull( - (embed) => embed.classElement.name == dartType.toString()); + return toList().firstWhereOrNull( + (embed) => embed.classElement.name == dartType.toString()); } -} \ No newline at end of file +} diff --git a/floor_generator/lib/misc/extension/field_element_extension.dart b/floor_generator/lib/misc/extension/field_element_extension.dart index 88b5bdeb..037dc06e 100644 --- a/floor_generator/lib/misc/extension/field_element_extension.dart +++ b/floor_generator/lib/misc/extension/field_element_extension.dart @@ -9,6 +9,7 @@ extension FieldElementExtension on FieldElement { } bool get isEmbedded { - return (type.element?.hasAnnotation(annotations.Embed) ?? false) && type.element is ClassElement; + return (type.element?.hasAnnotation(annotations.Embed) ?? false) && + type.element is ClassElement; } -} \ No newline at end of file +} diff --git a/floor_generator/lib/processor/embed_processor.dart b/floor_generator/lib/processor/embed_processor.dart index cb4f5d7f..5ab5a4f7 100644 --- a/floor_generator/lib/processor/embed_processor.dart +++ b/floor_generator/lib/processor/embed_processor.dart @@ -24,9 +24,11 @@ class EmbedProcessor extends Processor { List _getFields() { final fields = _classElement.fields .where((fieldElement) => fieldElement.shouldBeIncluded()) - .map((field) => FieldProcessor(field, typeConverters.getClosestOrNull(field.type), null).process()) + .map((field) => FieldProcessor( + field, typeConverters.getClosestOrNull(field.type), null) + .process()) .toList(); return fields; } -} \ No newline at end of file +} diff --git a/floor_generator/lib/processor/entity_processor.dart b/floor_generator/lib/processor/entity_processor.dart index 059ab742..23514ee4 100644 --- a/floor_generator/lib/processor/entity_processor.dart +++ b/floor_generator/lib/processor/entity_processor.dart @@ -291,9 +291,8 @@ class EntityProcessor extends QueryableProcessor { final Map map = {}; _processFields(map, fields); - final keyValueList = map.entries - .map((entry) => "'${entry.key}': ${entry.value}") - .toList(); + final keyValueList = + map.entries.map((entry) => "'${entry.key}': ${entry.value}").toList(); return '{${keyValueList.join(', ')}}'; } diff --git a/floor_generator/lib/processor/field_processor.dart b/floor_generator/lib/processor/field_processor.dart index caa9e8af..db2db04c 100644 --- a/floor_generator/lib/processor/field_processor.dart +++ b/floor_generator/lib/processor/field_processor.dart @@ -36,14 +36,13 @@ class FieldProcessor extends Processor { }.whereNotNull().closestOrNull; return Field( - _fieldElement, - name, - columnName, - isNullable, - _getSqlType(typeConverter, _embedConverter), - typeConverter, - _embedConverter - ); + _fieldElement, + name, + columnName, + isNullable, + _getSqlType(typeConverter, _embedConverter), + typeConverter, + _embedConverter); } String _getColumnName(final String name) { @@ -56,15 +55,16 @@ class FieldProcessor extends Processor { : name; } - String _getSqlType(final TypeConverter? typeConverter, final Embed? embedConverter) { + String _getSqlType( + final TypeConverter? typeConverter, final Embed? embedConverter) { final type = _fieldElement.type; if (typeConverter != null) { return typeConverter.databaseType.asSqlType(); } else if (type.isDefaultSqlType || type.isEnumType) { return type.asSqlType(); - } else if (embedConverter != null) { + } else if (embedConverter != null) { return ''; - }else { + } else { throw InvalidGenerationSourceError( 'Column type is not supported for $type.', todo: 'Either make to use a supported type or supply a type converter.', diff --git a/floor_generator/lib/processor/queryable_processor.dart b/floor_generator/lib/processor/queryable_processor.dart index 75519bdd..f48193a8 100644 --- a/floor_generator/lib/processor/queryable_processor.dart +++ b/floor_generator/lib/processor/queryable_processor.dart @@ -31,8 +31,8 @@ abstract class QueryableProcessor extends Processor { QueryableProcessor( this.classElement, final Set typeConverters, - this.embedConverters, - ) : _queryableProcessorError = QueryableProcessorError(classElement), + this.embedConverters, + ) : _queryableProcessorError = QueryableProcessorError(classElement), queryableTypeConverters = typeConverters + classElement.getTypeConverters(TypeConverterScope.queryable); @@ -48,9 +48,13 @@ abstract class QueryableProcessor extends Processor { return fields.map((field) { if (field.isEmbedded) { - return FieldProcessor(field, null, embedConverters.getClosestOrNull(field.type)).process(); + return FieldProcessor( + field, null, embedConverters.getClosestOrNull(field.type)) + .process(); } else { - return FieldProcessor(field, queryableTypeConverters.getClosestOrNull(field.type), null).process(); + return FieldProcessor(field, + queryableTypeConverters.getClosestOrNull(field.type), null) + .process(); } }).toList(); } @@ -60,7 +64,8 @@ abstract class QueryableProcessor extends Processor { return _getConstructor(classElement, fields); } - String _getConstructor(ClassElement classElement, final List fields, {String prefix = ''}) { + String _getConstructor(ClassElement classElement, final List fields, + {String prefix = ''}) { final constructorParameters = classElement.constructors .firstWhereOrNull((element) => element.isPublic && !element.isFactory) ?.parameters; @@ -81,12 +86,12 @@ abstract class QueryableProcessor extends Processor { /// Returns `null` whenever field is @ignored String? _getParameterValue( final ParameterElement parameterElement, - final List fields, { - final String prefix = '', - } - ) { + final List fields, { + final String prefix = '', + }) { final parameterName = parameterElement.displayName; - final field = fields.firstWhereOrNull((field) => field.fieldElement.displayName == parameterName); + final field = fields.firstWhereOrNull( + (field) => field.fieldElement.displayName == parameterName); if (field != null) { final databaseValue = "row['$prefix${field.columnName}']"; @@ -98,7 +103,9 @@ abstract class QueryableProcessor extends Processor { ); } else if (field.embedConverter != null) { final embedVar = field.columnName.isEmpty ? '' : '${field.columnName}_'; - parameterValue = _getConstructor(field.embedConverter!.classElement, field.embedConverter!.fields, prefix: '$prefix$embedVar'); + parameterValue = _getConstructor( + field.embedConverter!.classElement, field.embedConverter!.fields, + prefix: '$prefix$embedVar'); } else { final typeConverter = [ ...queryableTypeConverters, @@ -110,14 +117,15 @@ abstract class QueryableProcessor extends Processor { parameterElement, ); - parameterValue = '_${typeConverter.name.decapitalize()}.decode($castedDatabaseValue)'; + parameterValue = + '_${typeConverter.name.decapitalize()}.decode($castedDatabaseValue)'; } if (parameterElement.isNamed) { return '$parameterName: $parameterValue'; } return parameterValue; // also covers positional parameter - } + } return null; } } diff --git a/floor_generator/lib/value_object/embed.dart b/floor_generator/lib/value_object/embed.dart index 6db3bf51..1cda9b56 100644 --- a/floor_generator/lib/value_object/embed.dart +++ b/floor_generator/lib/value_object/embed.dart @@ -11,9 +11,9 @@ class Embed { @override bool operator ==(Object other) => identical(this, other) || - other is Embed && - runtimeType == other.runtimeType && - const ListEquality().equals(fields, other.fields); + other is Embed && + runtimeType == other.runtimeType && + const ListEquality().equals(fields, other.fields); @override int get hashCode => classElement.hashCode ^ fields.hashCode; @@ -22,4 +22,4 @@ class Embed { String toString() { return 'Embed{classElement: $classElement, fields: $fields}'; } -} \ No newline at end of file +} diff --git a/floor_generator/lib/value_object/field.dart b/floor_generator/lib/value_object/field.dart index b743543b..8fe3d564 100644 --- a/floor_generator/lib/value_object/field.dart +++ b/floor_generator/lib/value_object/field.dart @@ -27,7 +27,7 @@ class Field { String getDatabaseDefinition(final bool autoGenerate) { if (embedConverter != null) { throw InvalidGenerationSourceError( - 'You ', + 'You ', todo: 'Either make to use a supported type or supply a type converter.', element: fieldElement, ); @@ -47,13 +47,16 @@ class Field { Field copyWith({ String columnNamePrefix = '', - }) => Field(fieldElement, - name, - '$columnNamePrefix$columnName', - isNullable, - sqlType, - typeConverter, embedConverter, - ); + }) => + Field( + fieldElement, + name, + '$columnNamePrefix$columnName', + isNullable, + sqlType, + typeConverter, + embedConverter, + ); @override bool operator ==(Object other) => diff --git a/floor_generator/test/processor/entity_processor_test.dart b/floor_generator/test/processor/entity_processor_test.dart index 9f8aa003..3ed3735c 100644 --- a/floor_generator/test/processor/entity_processor_test.dart +++ b/floor_generator/test/processor/entity_processor_test.dart @@ -33,7 +33,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey([fields[0]], false); const foreignKeys = []; @@ -81,7 +82,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey([fields[0]], false); const foreignKeys = []; @@ -119,7 +121,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey(fields, false); const foreignKeys = []; @@ -158,7 +161,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey(fields.sublist(0, 1), false); const foreignKeys = []; @@ -206,7 +210,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey([fields[0]], false); const foreignKeys = []; @@ -346,7 +351,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); final primaryKey = PrimaryKey([fields[0]], false); const foreignKeys = []; @@ -381,7 +387,8 @@ void main() { } '''); - final actual = EntityProcessor(classElement, {}, {}).process().valueMapping; + final actual = + EntityProcessor(classElement, {}, {}).process().valueMapping; const expected = '{' "'id': item.id, " @@ -403,7 +410,8 @@ void main() { } '''); - final actual = EntityProcessor(classElement, {}, {}).process().valueMapping; + final actual = + EntityProcessor(classElement, {}, {}).process().valueMapping; const expected = '{' "'id': item.id, " @@ -428,7 +436,8 @@ void main() { } '''); - final actual = EntityProcessor(classElement, {}, {}).process().valueMapping; + final actual = + EntityProcessor(classElement, {}, {}).process().valueMapping; const expected = '{' "'id': item.id, " @@ -453,7 +462,8 @@ void main() { } '''); - final actual = EntityProcessor(classElement, {}, {}).process().valueMapping; + final actual = + EntityProcessor(classElement, {}, {}).process().valueMapping; const expected = '{' "'id': item.id, " diff --git a/floor_generator/test/processor/queryable_processor_test.dart b/floor_generator/test/processor/queryable_processor_test.dart index 6273fe8f..5b67f2f0 100644 --- a/floor_generator/test/processor/queryable_processor_test.dart +++ b/floor_generator/test/processor/queryable_processor_test.dart @@ -26,7 +26,8 @@ void main() { final actual = TestProcessor(classElement).process(); final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); const constructor = "Person(row['id'] as int, row['name'] as String)"; final expected = TestQueryable( @@ -57,7 +58,8 @@ void main() { final actual = TestProcessor(classElement, {typeConverter}).process(); - final idField = FieldProcessor(classElement.fields[0], null, null).process(); + final idField = + FieldProcessor(classElement.fields[0], null, null).process(); final dateTimeField = FieldProcessor(classElement.fields[1], typeConverter, null).process(); final fields = [idField, dateTimeField]; @@ -103,7 +105,8 @@ void main() { await intDartType, TypeConverterScope.queryable, ); - final idField = FieldProcessor(classElement.fields[0], null, null).process(); + final idField = + FieldProcessor(classElement.fields[0], null, null).process(); final dateTimeField = FieldProcessor(classElement.fields[1], typeConverter, null).process(); final fields = [idField, dateTimeField]; @@ -157,7 +160,8 @@ void main() { await intDartType, TypeConverterScope.queryable, ); - final idField = FieldProcessor(classElement.fields[0], null, null).process(); + final idField = + FieldProcessor(classElement.fields[0], null, null).process(); final dateTimeField = FieldProcessor(classElement.fields[1], typeConverter, null).process(); final fields = [idField, dateTimeField]; diff --git a/floor_generator/test/processor/view_processor_test.dart b/floor_generator/test/processor/view_processor_test.dart index 21b4405a..55fc776d 100644 --- a/floor_generator/test/processor/view_processor_test.dart +++ b/floor_generator/test/processor/view_processor_test.dart @@ -22,7 +22,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); const query = 'SELECT * from otherentity'; const constructor = "Person(row['id'] as int, row['name'] as String)"; @@ -52,7 +53,8 @@ void main() { const name = 'Person'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); const query = 'WITH subquery as (SELECT * from otherentity) SELECT subquery.*'; @@ -179,7 +181,8 @@ void main() { const name = 'personview'; final fields = classElement.fields - .map((fieldElement) => FieldProcessor(fieldElement, null, null).process()) + .map((fieldElement) => + FieldProcessor(fieldElement, null, null).process()) .toList(); const query = 'SELECT * from otherentity'; const constructor = "Person(row['id'] as int, row['name'] as String)"; diff --git a/floor_generator/test/value_object/entity_test.dart b/floor_generator/test/value_object/entity_test.dart index a91c2ef4..ce0952da 100644 --- a/floor_generator/test/value_object/entity_test.dart +++ b/floor_generator/test/value_object/entity_test.dart @@ -14,15 +14,8 @@ void main() { final fakeClassElement = FakeClassElement(); final fakeFieldElement = FakeFieldElement(); - final field = Field( - fakeFieldElement, - 'field1Name', - 'field1ColumnName', - false, - SqlType.integer, - null, - null - ); + final field = Field(fakeFieldElement, 'field1Name', 'field1ColumnName', false, + SqlType.integer, null, null); final nullableField = Field( fakeFieldElement, 'field2Name',