diff --git a/floor_generator/lib/processor/entity_processor.dart b/floor_generator/lib/processor/entity_processor.dart index faf4e93c..4fd0090d 100644 --- a/floor_generator/lib/processor/entity_processor.dart +++ b/floor_generator/lib/processor/entity_processor.dart @@ -53,16 +53,11 @@ class EntityProcessor extends Processor { @nonNull List _getFields() { return _classElement.fields - .where(_isNotHashCode) + .where((fieldElement) => fieldElement.shouldBeIncluded()) .map((field) => FieldProcessor(field).process()) .toList(); } - @nonNull - bool _isNotHashCode(final FieldElement fieldElement) { - return fieldElement.displayName != 'hashCode'; - } - @nonNull List _getForeignKeys() { return _classElement @@ -266,3 +261,9 @@ class EntityProcessor extends Processor { } } } + +extension on FieldElement { + bool shouldBeIncluded() { + return !(isStatic || displayName == 'hashCode'); + } +} diff --git a/floor_generator/test/processor/entity_processor_test.dart b/floor_generator/test/processor/entity_processor_test.dart index 510ed7c3..d51794e4 100644 --- a/floor_generator/test/processor/entity_processor_test.dart +++ b/floor_generator/test/processor/entity_processor_test.dart @@ -79,6 +79,47 @@ void main() { expect(actual, equals(expected)); }); + test('Ignore hashCode field', () async { + final classElement = await _createClassElement(''' + @entity + class Person { + @primaryKey + final int id; + + final String name; + + Person(this.id, this.name); + + @override + int get hashCode => id.hashCode ^ name.hashCode; + } + '''); + + final actual = EntityProcessor(classElement).process(); + + expect(actual.fields.length, equals(2)); + }); + + test('Ignore static field', () async { + final classElement = await _createClassElement(''' + @entity + class Person { + @primaryKey + final int id; + + final String name; + + Person(this.id, this.name); + + static String foo = 'foo'; + } + '''); + + final actual = EntityProcessor(classElement).process(); + + expect(actual.fields.length, equals(2)); + }); + group('foreign keys', () { test('foreign key holds correct values', () async { final classElements = await _createClassElements('''