writeClassDecode method

  1. @override
void writeClassDecode(
  1. JavaOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Class klass,
  5. Set<String> customClassNames,
  6. Set<String> customEnumNames, {
  7. required String dartPackageName,
})
override

Writes a single class decode method to indent.

Implementation

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