writeDataClass method

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

Writes a single data class to indent.

Implementation

@override
void writeDataClass(
  JavaOptions generatorOptions,
  Root root,
  Indent indent,
  Class klass, {
  required String dartPackageName,
}) {
  final Set<String> customClassNames =
      root.classes.map((Class x) => x.name).toSet();
  final Set<String> customEnumNames =
      root.enums.map((Enum x) => x.name).toSet();

  const List<String> generatedMessages = <String>[
    ' Generated class from Pigeon that represents data sent in messages.'
  ];
  indent.newln();
  addDocumentationComments(
      indent, klass.documentationComments, _docCommentSpec,
      generatorComments: generatedMessages);

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

    if (getFieldsInSerializationOrder(klass)
        .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('${klass.name}() {}');
      indent.newln();
    }

    _writeClassBuilder(generatorOptions, root, indent, klass);
    writeClassEncode(
      generatorOptions,
      root,
      indent,
      klass,
      customClassNames,
      customEnumNames,
      dartPackageName: dartPackageName,
    );
    writeClassDecode(
      generatorOptions,
      root,
      indent,
      klass,
      customClassNames,
      customEnumNames,
      dartPackageName: dartPackageName,
    );
  });
}