getInstanceFieldNames method

Set<String> getInstanceFieldNames()

Returns a set of all instance field names in this class and its superclass chain. Fields implicitly provide getters (and setters for non-final fields). G-DOV2-6 FIX: Walk the superclass chain to find fields from parent classes.

Implementation

Set<String> getInstanceFieldNames() {
  final fieldNames = <String>{};
  InterpretedClass? current = this;
  while (current != null) {
    // Include fields from the current class
    for (final fieldDecl in current.fieldDeclarations) {
      if (!fieldDecl.isStatic) {
        for (final variable in fieldDecl.fields?.variables ?? []) {
          fieldNames.add(variable.name?.name ?? '');
        }
      }
    }
    // Also include fields from mixins at this level
    for (final mixin in current.mixins) {
      for (final fieldDecl in mixin.fieldDeclarations) {
        if (!fieldDecl.isStatic) {
          for (final variable in fieldDecl.fields?.variables ?? []) {
            fieldNames.add(variable.name?.name ?? '');
          }
        }
      }
    }
    // Move up the superclass chain
    current = current.superclass;
  }
  return fieldNames;
}