writeClassEncode method

  1. @override
void writeClassEncode(
  1. JavaOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Class classDefinition, {
  5. required String dartPackageName,
})
override

Writes a single class encode method to indent.

Implementation

@override
void writeClassEncode(
  JavaOptions generatorOptions,
  Root root,
  Indent indent,
  Class classDefinition, {
  required String dartPackageName,
}) {
  indent.newln();
  indent.writeln('@NonNull');
  indent.write('ArrayList<Object> toList() ');
  indent.addScoped('{', '}', () {
    indent.writeln(
        'ArrayList<Object> toListResult = new ArrayList<Object>(${classDefinition.fields.length});');
    for (final NamedType field
        in getFieldsInSerializationOrder(classDefinition)) {
      String toWriteValue = '';
      final String fieldName = field.name;
      if (field.type.isEnum) {
        toWriteValue = '$fieldName == null ? null : $fieldName.index';
      } else {
        toWriteValue = field.name;
      }
      indent.writeln('toListResult.add($toWriteValue);');
    }
    indent.writeln('return toListResult;');
  });
}