generateBasicConstructor function

ConstructorBuilder generateBasicConstructor (ConstructorBuilder builder, List<FieldElement> fields)

Implementation

ConstructorBuilder generateBasicConstructor(
    ConstructorBuilder builder, List<FieldElement> fields) {
  var code = '';
  code += fields.map((f) {
    var annotation = defaultValueAnnotation(f);

    if (annotation != null) {
      var fieldCode =
          "this._cache[\"${f.name}\"] = ${getDefaultValue(f, annotation)};";
      return fieldCode;
    }
  }).join('\n');
  return builder
    ..initializers.add(Code("this._adapter = adapter"))
    ..body = Code(code)
    ..requiredParameters.add(
      Parameter((b) => b
        ..type = refer('PreferenceAdapter')
        ..name = 'adapter'),
    );
}