defineBridgeAlias method
GEN-078: Registers a class alias that maps aliasName to an existing
bridged class registered under targetName.
This allows deprecated type alias names (e.g., MaterialStateProperty)
to resolve to their canonical bridged class (e.g., WidgetStateProperty).
Implementation
void defineBridgeAlias(String aliasName, String targetName) {
// Walk the scope chain to find the target bridged class
BridgedClass? target;
Environment? current = this;
while (current != null) {
target = current._bridgedClasses[targetName];
if (target != null) break;
current = current._enclosing;
}
if (target == null) {
// SCI1: an alias may name an ENUM — `typedef MaterialState =
// WidgetState;` — and the generator emits it beside the class aliases.
// Looking among classes only defined nothing, so the alias was undefined
// in every run.
BridgedEnum? targetEnum;
for (Environment? env = this; env != null; env = env._enclosing) {
targetEnum = env._bridgedEnums[targetName];
if (targetEnum != null) break;
}
if (targetEnum != null) {
_bridgedEnumsOrNew[aliasName] = targetEnum;
Logger.debug(
"[Environment] Defined bridge alias: $aliasName -> enum $targetName",
);
return;
}
Logger.warn(
"[Environment] Cannot register alias '$aliasName' -> '$targetName': "
"target class or enum not found",
);
return;
}
_bridgedClassesOrNew[aliasName] = target;
Logger.debug(
"[Environment] Defined bridge alias: $aliasName -> $targetName",
);
}