collectCustomMapper method

_InitFileContributions collectCustomMapper(
  1. Map<String, dynamic> mapperData
)

Implementation

_InitFileContributions collectCustomMapper(Map<String, dynamic> mapperData) {
  final className = extractCodeProperty(mapperData, 'className');
  final mapperInterfaceType =
      extractCodeProperty(mapperData, 'mapperInterfaceType');
  final customMapperInstance =
      extractNullableCodeProperty(mapperData, 'customMapperInstance');
  final customMapperName = mapperData['customMapperName'] as String?;
  // Check if this mapper should be registered globally
  final registerGlobally = mapperData['registerGlobally'] as bool? ?? true;

  if (registerGlobally) {
    final code = customMapperInstance ??
        (customMapperName == null ? null : Code.literal(customMapperName));
    if (code == null) {
      throw ArgumentError('No valid code found for Custom mapper ');
    }
    final initFunctionParameter = customMapperName != null
        ? _InitFunctionParameter(
            type: mapperInterfaceType, name: customMapperName)
        : null;

    return (
      [
        _Mapper(
          type: className,
          code: code,
        )
      ],
      {
        if (initFunctionParameter?.name != null)
          initFunctionParameter!.name!: initFunctionParameter
      },
      const <String, String>{}, // No broader imports at mapper level
    );
  }
  return noInitFileContributions;
}