defineBridgedEnum method

void defineBridgedEnum(
  1. BridgedEnum bridgedEnum, {
  2. String? sourceUri,
})

Implementation

void defineBridgedEnum(BridgedEnum bridgedEnum, {String? sourceUri}) {
  final name = bridgedEnum.name;
  if (_values.containsKey(name) ||
      _bridgedClasses.containsKey(name) ||
      _bridgedEnums.containsKey(name)) {
    // SCE25: same rule as classes and values — a cross-package same-name
    // enum is ambiguous, not last-wins. Before this, the displaced enum had
    // no `qualifier.Name` to be reached by either, so it was simply gone.
    final prior = _bridgedEnumsRaw?[name];
    if (sourceUri != null && prior != null) {
      if (_markAmbiguousBridgeName(name, prior, bridgedEnum, sourceUri)) {
        return;
      }
    } else {
      Logger.warn(
        "Redefining bridged enum or colliding with existing definition: $name",
      );
    }
  }
  if (sourceUri != null) _bridgeSourceUrisOrNew[name] = sourceUri;
  // SCD194: record before overwriting. The warning above is the only other
  // trace and it is off in a normal run, so without this the displaced enum
  // is simply gone — no candidate list, nothing for a guard to count. The
  // class path has done this unconditionally since SCC76; this is the same
  // bookkeeping on the namespace that lacked it.
  _recordShadowedEnum(name, _bridgedEnumsRaw?[name], bridgedEnum);
  _bridgedEnumsOrNew[name] = bridgedEnum;
  Logger.debugLazy(() => "[Environment] Defined bridge for enum: $name");
}