writeClassDecode method
void
writeClassDecode(
- JavaOptions generatorOptions,
- Root root,
- Indent indent,
- Class klass,
- Set<
String> customClassNames, - Set<
String> customEnumNames, { - 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;');
});
}