writeEnum method

  1. @override
void writeEnum(
  1. GObjectOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Enum anEnum, {
  5. required String dartPackageName,
})
override

Writes a single Enum to indent. This is needed in most generators.

Implementation

@override
void writeEnum(
  GObjectOptions generatorOptions,
  Root root,
  Indent indent,
  Enum anEnum, {
  required String dartPackageName,
}) {
  final String module = _getModule(generatorOptions, dartPackageName);
  final String enumName = _getClassName(module, anEnum.name);

  indent.newln();
  final List<String> enumValueCommentLines = <String>[];
  for (int i = 0; i < anEnum.members.length; i++) {
    final EnumMember member = anEnum.members[i];
    final String itemName =
        _getEnumValue(dartPackageName, anEnum.name, member.name);
    enumValueCommentLines.add('$itemName:');
    enumValueCommentLines.addAll(member.documentationComments);
  }
  addDocumentationComments(
      indent,
      <String>[
        '$enumName:',
        ...enumValueCommentLines,
        '',
        ...anEnum.documentationComments
      ],
      _docCommentSpec);
  indent.writeScoped('typedef enum {', '} $enumName;', () {
    for (int i = 0; i < anEnum.members.length; i++) {
      final EnumMember member = anEnum.members[i];
      final String itemName =
          _getEnumValue(dartPackageName, anEnum.name, member.name);
      indent.writeln(
          '$itemName = $i${i == anEnum.members.length - 1 ? '' : ','}');
    }
  });
}