overrideEquals function

void overrideEquals(
  1. Iterable<String> fields,
  2. String className,
  3. StringBuffer into
)

Writes a operator == override for a class consisting of the fields into the buffer provided by into.

Implementation

void overrideEquals(
    Iterable<String> fields, String className, StringBuffer into) {
  into
    ..write('@override\nbool operator ==(Object other) => ')
    ..write('identical(this, other) || (other is $className');

  if (fields.isNotEmpty) {
    into
      ..write(' && ')
      ..write(fields.map((field) {
        return 'other.$field == this.$field';
      }).join(' && '));
  }

  into.write(');\n');
}