fieldsOf function

List<_FieldInfo> fieldsOf(
  1. ClassElement cls
)

Implementation

List<_FieldInfo> fieldsOf(ClassElement cls) {
  final Map<String, _FieldInfo> seen = <String, _FieldInfo>{};
  ClassElement? current = cls;

  while (current != null && !current.isDartCoreObject) {
    final LibraryElement owningLib = current.library;

    // `fields` gives only the declarations on `current`, not inherited ones.
    for (final FieldElement f in current.fields) {
      if (f.isStatic || f.isSynthetic || f.isPrivate) continue;
      if (seen.containsKey(f.name)) continue; // overridden

      final DartType dt = f.type;
      final Uri uri = importForType(dt, owningLib);

      seen[f.name] = _FieldInfo(
        f.name,
        dt.getDisplayString(withNullability: true),
        uri,
        dt,
      );
    }

    final InterfaceType? superType = current.supertype;
    current = superType?.element as ClassElement?;
  }

  return seen.values.toList(growable: false);
}