writeEnum method
void
writeEnum(
- GObjectOptions generatorOptions,
- Root root,
- Indent indent,
- Enum anEnum, {
- 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 ? '' : ','}');
}
});
}