private emitConstructClass()

in src/cfn-resource-generator.ts [102:158]


  private emitConstructClass(code: j2j.Code) {
    code.line('/**');
    code.line(` * A CloudFormation \`${this.typeName}\``);
    code.line(' *');
    code.line(` * @cloudformationResource ${this.typeName}`);
    code.line(' * @stability external');
    if (this.typeDef.SourceUrl) {
      code.line(` * @link ${this.typeDef.SourceUrl}`);
    }
    code.line(' */');
    code.openBlock(`export class ${this.constructClassName} extends cdk.CfnResource`);
    code.line('/**');
    code.line('* The CloudFormation resource type name for this resource class.');
    code.line('*/');
    code.line(`public static readonly CFN_RESOURCE_TYPE_NAME = "${this.typeName}";`);
    code.line();

    // emit a "props" property which includes the set of props passed to the constructor
    code.line('/**');
    code.line(' * Resource props.');
    code.line(' */');
    code.line(`public readonly props: ${this.propsStructName};`);
    code.line();

    for (const prop of this.resourceAttributes) {
      code.line('/**');
      code.line(` * Attribute \`${this.typeName}.${prop}\``);
      if (this.typeDef.SourceUrl) {
        code.line(` * @link ${this.typeDef.SourceUrl}`);
      }
      code.line(' */');
      code.line(`public readonly attr${pascal(prop)}: ${this.getTypeOfProperty(prop)};`);
    }

    code.line();

    code.line('/**');
    code.line(` * Create a new \`${this.typeName}\`.`);
    code.line(' *');
    code.line(' * @param scope - scope in which this resource is defined');
    code.line(' * @param id    - scoped id of the resource');
    code.line(' * @param props - resource properties');
    code.line(' */');
    code.openBlock(`constructor(scope: cdk.Construct, id: string, props: ${this.propsStructName})`);
    code.line(`super(scope, id, { type: ${this.constructClassName}.CFN_RESOURCE_TYPE_NAME, properties: toJson_${this.propsStructName}(props)! });`);
    code.line('');
    code.line('this.props = props;');
    code.line();
    for (const prop of this.resourceAttributes) {
      const propertyName = `attr${pascal(prop)}`;
      code.line(`this.${propertyName} = ${this.renderGetAtt(prop)};`);
    }
    code.closeBlock();

    // Close construct class
    code.closeBlock();
  }