fragmentClassDefinitionToSpec function

Spec fragmentClassDefinitionToSpec(
  1. FragmentClassDefinition definition
)

Generates a Spec of a single fragment class definition.

Implementation

Spec fragmentClassDefinitionToSpec(FragmentClassDefinition definition) {
  final fields = definition.properties.map((p) {
    final lines = <String>[];
    lines.addAll(p.annotations.map((e) => '@$e'));
    lines.add(
        '${p.type.isNonNull ? 'late ' : ''}${p.type.namePrintable} ${p.name.namePrintable};');
    return lines.join('\n');
  });

  return CodeExpression(Code('''mixin ${definition.name.namePrintable} {
  ${fields.join('\n')}
}'''));
}