latentStdlibBridgeFor static method

BridgedClass? latentStdlibBridgeFor(
  1. Type nativeType, {
  2. bool structural = false,
})

The stdlib bridge for nativeType from any stdlib library, imported or not.

Precise (the default): the exact type, else the bridge whose name or nativeNames equals the type's name (without type arguments, a leading underscore or an Impl suffix). structural: SCC49's suffix rule, which the caller asks only after the imported scope's own suffix rule missed — so an imported library still wins at each tier, and widening to every library never lets a guess outrank a declared match.

Implementation

static BridgedClass? latentStdlibBridgeFor(
  Type nativeType, {
  bool structural = false,
}) {
  final cache = structural ? _latentStructural : _latentPrecise;
  if (cache.containsKey(nativeType)) return cache[nativeType];
  if (structural) {
    return cache[nativeType] = _latentStdlib.structuralSuffixBridge(
      nativeType,
    );
  }
  final byType = _latentStdlib.registeredBridgeTypes;
  BridgedClass? found = byType[nativeType];
  if (found == null) {
    final full = nativeType.toString();
    final generic = full.indexOf('<');
    final raw = generic < 0 ? full : full.substring(0, generic);
    var clean = raw.startsWith('_') ? raw.substring(1) : raw;
    if (clean.endsWith('Impl')) {
      clean = clean.substring(0, clean.length - 'Impl'.length);
    }
    for (final bridge in byType.values) {
      final names = bridge.nativeNames;
      if (bridge.name == clean ||
          (names != null && (names.contains(raw) || names.contains(clean)))) {
        found = bridge;
        break;
      }
    }
  }
  return cache[nativeType] = found;
}