in src/declarative-stack.ts [359:394]
function invokeMethod(stack: cdk.Stack, method: reflect.Callable, parameters: any) {
const typeClass = resolveType(method.parentType.fqn);
const args = new Array<any>();
for (let i = 0; i < method.parameters.length; ++i) {
const p = method.parameters[i];
// kwargs: if this is the last argument and a data type, flatten (treat as keyword args)
if (i === method.parameters.length - 1 && isDataType(p.type.type)) {
// we pass in all parameters are the value, and the positional arguments will be ignored since
// we are promised there are no conflicts
const kwargs = deserializeValue(stack, p.type, p.optional, p.name, parameters);
args.push(kwargs);
} else {
const val = parameters[p.name];
if (val === undefined && !p.optional) {
throw new Error(`Missing required parameter '${p.name}' for ${method.parentType.fqn}.${method.name}`);
}
if (val !== undefined) {
args.push(deserializeValue(stack, p.type, p.optional, p.name, val));
}
}
}
if (reflect.Initializer.isInitializer(method)) {
return new typeClass(...args);
}
const methodFn: (...s: any[]) => any = typeClass[method.name];
if (!methodFn) {
throw new Error(`Cannot find method named ${method.name} in ${typeClass.fqn}`);
}
return methodFn.apply(typeClass, args);
}