Properly handle overridden elements when parsing columns

This commit is contained in:
Simon Binder 2019-10-11 18:00:17 +02:00
parent 337e260667
commit 0b9d4c897b
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 13 additions and 4 deletions

View File

@ -110,13 +110,21 @@ class TableParser {
}
Future<List<SpecifiedColumn>> _parseColumns(ClassElement element) {
final columns = element.allSupertypes
final columnNames = element.allSupertypes
.map((t) => t.element)
.followedBy([element])
.expand((e) => e.fields)
.where((field) => isColumn(field.type) && field.getter != null);
.where((field) => isColumn(field.type) && field.getter != null)
.map((field) => field.name)
.toSet();
return Future.wait(columns.map((field) async {
final fields = columnNames.map((name) {
final getter = element.getGetter(name) ??
element.lookUpInheritedConcreteGetter(name, element.library);
return getter.variable;
});
return Future.wait(fields.map((field) async {
final resolved = await base.loadElementDeclaration(field.getter);
final node = resolved.node as MethodDeclaration;

View File

@ -53,7 +53,7 @@ void main() {
}
class Foos extends HasNameTable with IntIdTable {
TextColumn get name => text().nullable()();
}
'''
});
@ -159,6 +159,7 @@ void main() {
test('handles inheritance in column definitions', () async {
final table = await parse('Foos');
expect(table.columns, hasLength(2));
expect(table.columns.map((c) => c.name.name), containsAll(['id', 'name']));
});
}