function codeForBuilderFromExistingObjectClassMethodForValueType()

in src/plugins/builder.ts [119:158]


function codeForBuilderFromExistingObjectClassMethodForValueType(
  objectType: ObjectSpec.Type,
): string[] {
  const returnOpening: string = 'return ';
  const openingBracesForWithMethodInvocations: string[] =
    objectType.attributes.map(openingBrace);
  const builderCreationCall: string =
    '[' +
    nameOfBuilderForValueTypeWithName(objectType.typeName) +
    ' ' +
    shortNameOfObjectToBuildForValueTypeWithName(objectType.typeName) +
    ']';
  const openingLine: string =
    returnOpening +
    openingBracesForWithMethodInvocations.join('') +
    builderCreationCall;

  const indentationProvider: (index: number) => string =
    indentationForItemAtIndexWithOffset(
      returnOpening.length + openingBracesForWithMethodInvocations.length,
    );
  const existingObjectName: string =
    keywordArgumentNameForBuilderFromExistingObjectClassMethodForValueType(
      objectType,
    );
  const linesForBuildingValuesIntoBuilder: string[] =
    objectType.attributes.reduce(
      toWithInvocationCallForBuilderFromExistingObjectClassMethodForAttribute.bind(
        null,
        indentationProvider,
        existingObjectName,
      ),
      [],
    );

  const code: string[] = [openingLine].concat(
    linesForBuildingValuesIntoBuilder,
  );
  return stringsWithLastItemContainingStringAtEnd(code, ';');
}