writeEnum method
void
writeEnum(
- KotlinOptions 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(
KotlinOptions generatorOptions,
Root root,
Indent indent,
Enum anEnum, {
required String dartPackageName,
}) {
indent.newln();
addDocumentationComments(
indent, anEnum.documentationComments, _docCommentSpec);
indent.write('enum class ${anEnum.name}(val raw: Int) ');
indent.addScoped('{', '}', () {
enumerate(anEnum.members, (int index, final EnumMember member) {
addDocumentationComments(
indent, member.documentationComments, _docCommentSpec);
indent.write('${member.name.toUpperCase()}($index)');
if (index != anEnum.members.length - 1) {
indent.addln(',');
} else {
indent.addln(';');
}
});
indent.newln();
indent.write('companion object ');
indent.addScoped('{', '}', () {
indent.write('fun ofRaw(raw: Int): ${anEnum.name}? ');
indent.addScoped('{', '}', () {
indent.writeln('return values().firstOrNull { it.raw == raw }');
});
});
});
}