pullUpParameter method

void pullUpParameter(
  1. BridgeModule srcInst,
  2. String srcParam, {
  3. String? newParamName,
})

Pull up a passthrough parameter to this level

Implementation

void pullUpParameter(BridgeModule srcInst, String srcParam,
    {String? newParamName}) {
  if (hasBuilt) {
    throw RohdBridgeException(
        'Cannot pull up parameter $srcParam from ${srcInst.name}'
        ' after build.');
  }
  newParamName ??= srcParam;
  final paramValue = srcInst.instantiationParameters[srcParam];

  final paramType = srcInst.definitionParameters
      .firstWhereOrNull((param) => param.name == srcParam)
      ?.type;

  if (paramValue == null && paramType == null) {
    throw RohdBridgeException(
        'Parameter $srcParam not found in ${srcInst.name}');
  }
  final insts = getHierarchyDownTo(srcInst);

  if (insts == null) {
    throw RohdBridgeException(
        'No hierarchy found between $name and ${srcInst.name}');
  }

  for (final inst in insts) {
    inst as BridgeModule;

    if (inst == srcInst) {
      inst.overrideParameter(srcParam, newParamName);
    } else {
      inst.createParameter(newParamName, paramValue!,
          type: paramType!, isMapped: true, mergeIfExist: true);
    }
  }
  overrideParameter(newParamName, paramValue!);
}