writeDataClass method

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

  indent.write('public static final class ${classDefinition.name} ');
  indent.addScoped('{', '}', () {
    for (final NamedType field
        in getFieldsInSerializationOrder(classDefinition)) {
      _writeClassField(generatorOptions, root, indent, field);
      indent.newln();
    }

    if (getFieldsInSerializationOrder(classDefinition)
        .map((NamedType e) => !e.type.isNullable)
        .any((bool e) => e)) {
      indent.writeln(
          '$_docCommentPrefix Constructor is non-public to enforce null safety; use Builder.$_docCommentSuffix');
      indent.writeln('${classDefinition.name}() {}');
      indent.newln();
    }

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