extractTypeParameterBounds static method

Map<String, RuntimeType?> extractTypeParameterBounds(
  1. STypeParameterList? typeParameters,
  2. Environment? resolveEnvironment
)

Implementation

static Map<String, RuntimeType?> extractTypeParameterBounds(
  STypeParameterList? typeParameters,
  Environment? resolveEnvironment,
) {
  final bounds = <String, RuntimeType?>{};
  if (typeParameters == null) return bounds;

  for (final typeParam in typeParameters.typeParameters) {
    final paramName = typeParam.name?.name ?? '';
    RuntimeType? bound;

    if (typeParam.bound != null && resolveEnvironment != null) {
      try {
        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Resolving bound for type parameter '$paramName'",
        );

        bound = resolveTypeAnnotationDynamic(
          typeParam.bound!,
          resolveEnvironment,
        );

        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Successfully resolved bound for '$paramName' to: ${bound.name}",
        );
      } catch (e) {
        Logger.debug(
          "[InterpretedClass._extractTypeParameterBounds] Failed to resolve bound for '$paramName': $e",
        );
        rethrow;
      }
    }

    bounds[paramName] = bound;
  }

  return bounds;
}