writeClassDecode method

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

Writes a single class decode method to indent.

Implementation

@override
void writeClassDecode(
  JavaOptions generatorOptions,
  Root root,
  Indent indent,
  Class classDefinition, {
  required String dartPackageName,
}) {
  indent.newln();
  indent.write(
      'static @NonNull ${classDefinition.name} fromList(@NonNull ArrayList<Object> ${varNamePrefix}list) ');
  indent.addScoped('{', '}', () {
    const String result = 'pigeonResult';
    indent.writeln(
        '${classDefinition.name} $result = new ${classDefinition.name}();');
    enumerate(getFieldsInSerializationOrder(classDefinition),
        (int index, final NamedType field) {
      final String fieldVariable = field.name;
      final String setter = _makeSetter(field);
      indent.writeln(
          'Object $fieldVariable = ${varNamePrefix}list.get($index);');
      if (field.type.isEnum) {
        indent.writeln(
            '$result.$setter(${_intToEnum(fieldVariable, field.type.baseName, field.type.isNullable)});');
      } else {
        indent.writeln(
            '$result.$setter(${_castObject(field, fieldVariable)});');
      }
    });
    indent.writeln('return $result;');
  });
}