writeDataClass method

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

Writes a single data class to indent.

Implementation

@override
void writeDataClass(
  SwiftOptions generatorOptions,
  Root root,
  Indent indent,
  Class classDefinition, {
  required String dartPackageName,
}) {
  const List<String> generatedComments = <String>[
    ' Generated class from Pigeon that represents data sent in messages.'
  ];
  indent.newln();
  addDocumentationComments(
      indent, classDefinition.documentationComments, _docCommentSpec,
      generatorComments: generatedComments);

  if (classDefinition.isSwiftClass) {
    indent.write('class ${classDefinition.name} ');
  } else {
    indent.write('struct ${classDefinition.name} ');
  }
  indent.addScoped('{', '}', () {
    final Iterable<NamedType> fields =
        getFieldsInSerializationOrder(classDefinition);

    if (classDefinition.isSwiftClass) {
      _writeClassInit(indent, fields.toList());
    }

    for (final NamedType field in fields) {
      addDocumentationComments(
          indent, field.documentationComments, _docCommentSpec);
      indent.write('var ');
      _writeClassField(indent, field, addNil: !classDefinition.isSwiftClass);
      indent.newln();
    }

    indent.newln();
    writeClassDecode(
      generatorOptions,
      root,
      indent,
      classDefinition,
      dartPackageName: dartPackageName,
    );
    writeClassEncode(
      generatorOptions,
      root,
      indent,
      classDefinition,
      dartPackageName: dartPackageName,
    );
  });
}