ClassSpecAttributeBuilder function

Class ClassSpecAttributeBuilder(
  1. SpecDefinitionContext context
)

Implementation

Class ClassSpecAttributeBuilder(SpecDefinitionContext context) {
  final specClassName = context.options.specClassName;
  final specAttributeClassName = context.options.specAttributeClassName;
  final fields = context.options.fields;
  final extendsType = 'SpecAttribute<$specClassName>';

  return Class((b) {
    b.name = specAttributeClassName;
    b.extend = refer(extendsType);
    b.docs.addAll([
      '/// Represents the attributes of a [$specClassName].',
      '///',
      '/// This class encapsulates properties defining the layout and',
      '/// appearance of a [$specClassName].',
      '///',
      '/// Use this class to configure the attributes of a [$specClassName] and pass it to',
      '/// the [$specClassName] constructor.',
    ]);

    b.fields.addAll(fields.classDtoFields);
    // Constructor
    b.constructors.add(
      Constructor((builder) {
        builder.constant = true;
        builder.optionalParameters.addAll(fields.constructorParams);
      }),
    );

    b.methods.addAll([
      MethodResolveBuilder(resolveToType: specClassName, fields: fields),
      MethodMergeBuilder(className: specAttributeClassName, fields: fields),
      GetterPropsBuilder(className: specAttributeClassName, fields: fields),
    ]);
  });
}