getSortedFieldSet method
Gets the public instance fields of the class
This method will retrieve the fields of the
super classes when the includeInherited
parameter is true.
It will retrieve enum fields and non-static fields.
Implementation
Iterable<FieldElement> getSortedFieldSet({bool includeInherited = true}) {
// Get all of the fields that need to be assigned
final elementInstanceFields = Map.fromEntries(this
.fields
.where((e) => !e.isStatic || e.isEnumConstant)
.where((e) => !e.isPrivate)
.map((e) => MapEntry(e.name, e)));
final inheritedFields = <String, FieldElement>{};
final manager = InheritanceManager3();
if (includeInherited) {
for (final v in manager.getInheritedConcreteMap2(this).values) {
assert(v is! FieldElement);
if (_dartCoreObjectChecker.isExactly(v.enclosingElement)) {
continue;
}
if (v is PropertyAccessorElement && v.isGetter && !v.isPrivate) {
assert(v.variable is FieldElement);
final variable = v.variable as FieldElement;
assert(!inheritedFields.containsKey(variable.name));
inheritedFields[variable.name] = variable;
}
}
}
// Get the list of all fields for `element`
final allFields =
elementInstanceFields.keys.toSet().union(inheritedFields.keys.toSet());
final fields = allFields
.map((e) => _FieldSet(elementInstanceFields[e], inheritedFields[e]))
.toList()
..sort();
return fields
.map((fs) => fs.field)
.where((field) =>
(field.getter != null &&
(field.setter != null ||
field.isFinal &&
field.getter!.isSynthetic &&
this is! EnumElement)) ||
(field.getter == null && field.setter == null) ||
field.isEnumConstant ||
_fieldIsDefinedInConstructor(field))
.toList();
}