Prepare `code_builder` 4.11.1 for `fixnum` 1.2.0. (#2281)

diff --git a/pkgs/code_builder/CHANGELOG.md b/pkgs/code_builder/CHANGELOG.md
index fa40c8c..e153bd5 100644
--- a/pkgs/code_builder/CHANGELOG.md
+++ b/pkgs/code_builder/CHANGELOG.md
@@ -1,4 +1,10 @@
-## 4.11.1-wip
+## 4.11.1
+
+* Convert imports of implementation libraries under `package:fixnum/src/*` into
+  imports of `package:fixnum/fixnum.dart` to prevent issues when version 1.2.0
+  is released with platform-specific implementation libraries that generated
+  code should not import directly. This is a temporary workaround, it will be
+  replaced by a new way of managing imports in a future major version release.
 
 ## 4.11.0
 
diff --git a/pkgs/code_builder/lib/src/allocator.dart b/pkgs/code_builder/lib/src/allocator.dart
index 2e732b3..c7e821b 100644
--- a/pkgs/code_builder/lib/src/allocator.dart
+++ b/pkgs/code_builder/lib/src/allocator.dart
@@ -42,6 +42,11 @@
   String allocate(Reference reference);
 
   /// All imports that have so far been added implicitly via [allocate].
+  ///
+  /// As a special case, imports of `package:fixnum/src/*` are changed to refer
+  /// to the public `package:fixnum/fixnum.dart`. Version 1.2.0 of the package
+  /// introduces platform-specific implementation libraries that must not be
+  /// imported directly.
   Iterable<Directive> get imports;
 }
 
@@ -50,8 +55,9 @@
 
   @override
   String allocate(Reference reference) {
-    final url = reference.url;
+    var url = reference.url;
     if (url != null) {
+      url = _fixUrl(url);
       _imports.add(url);
     }
     return reference.symbol!;
@@ -80,10 +86,11 @@
   @override
   String allocate(Reference reference) {
     final symbol = reference.symbol;
-    final url = reference.url;
+    var url = reference.url;
     if (url == null || _doNotPrefix.contains(url)) {
       return symbol!;
     }
+    url = _fixUrl(url);
     return '_i${_imports.putIfAbsent(url, _nextKey)}.$symbol';
   }
 
@@ -93,3 +100,13 @@
   Iterable<Directive> get imports =>
       _imports.keys.map((u) => Directive.import(u, as: '_i${_imports[u]}'));
 }
+
+/// Applies hardcoded fixes to [url].
+///
+/// See [Allocator.imports] for explanations.
+String _fixUrl(String url) {
+  if (url.startsWith('package:fixnum/src/')) {
+    return 'package:fixnum/fixnum.dart';
+  }
+  return url;
+}
diff --git a/pkgs/code_builder/pubspec.yaml b/pkgs/code_builder/pubspec.yaml
index d551bcb..b1e1841 100644
--- a/pkgs/code_builder/pubspec.yaml
+++ b/pkgs/code_builder/pubspec.yaml
@@ -1,5 +1,5 @@
 name: code_builder
-version: 4.11.1-wip
+version: 4.11.1
 description: A fluent, builder-based library for generating valid Dart code.
 repository: https://github.com/dart-lang/tools/tree/main/pkgs/code_builder
 issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Acode_builder
diff --git a/pkgs/code_builder/test/allocator_test.dart b/pkgs/code_builder/test/allocator_test.dart
index 71c93cb..7e089f6 100644
--- a/pkgs/code_builder/test/allocator_test.dart
+++ b/pkgs/code_builder/test/allocator_test.dart
@@ -30,6 +30,15 @@
       ]);
     });
 
+    test('.simple replaces fixnum internal URIs', () {
+      allocator =
+          Allocator()
+            ..allocate(refer('Int64', 'package:fixnum/src/int64_native.dart'));
+      expect(allocator.imports.map((d) => d.url), [
+        'package:fixnum/fixnum.dart',
+      ]);
+    });
+
     test('.none should do nothing', () {
       allocator = Allocator.none;
       expect(allocator.allocate(refer('Foo', 'package:foo')), 'Foo');
@@ -47,5 +56,14 @@
         'dart:collection as _i1',
       ]);
     });
+
+    test('.simplePrefixing replaces fixnum internal URIs', () {
+      allocator =
+          Allocator.simplePrefixing()
+            ..allocate(refer('Int64', 'package:fixnum/src/int64_native.dart'));
+      expect(allocator.imports.map((d) => d.url), [
+        'package:fixnum/fixnum.dart',
+      ]);
+    });
   });
 }