44
55import '../generator_tools.dart' ;
66
7+ /// Name for the generated InstanceManager for ProxyApis.
8+ ///
9+ /// This lowers the chances of variable name collisions with user defined
10+ /// parameters.
11+ const String dartInstanceManagerClassName =
12+ '${proxyApiClassNamePrefix }InstanceManager' ;
13+
14+ /// Name for the generated InstanceManager API for ProxyApis.
15+ ///
16+ /// This lowers the chances of variable name collisions with user defined
17+ /// parameters.
18+ const String dartInstanceManagerApiClassName =
19+ '_${classNamePrefix }InstanceManagerApi' ;
20+
721/// Creates the `InstanceManager` with the passed string values.
822String instanceManagerTemplate ({
923 required Iterable <String > allProxyApiNames,
@@ -30,9 +44,9 @@ String instanceManagerTemplate({
3044/// is added as a weak reference with the same identifier. This prevents a
3145/// scenario where the weak referenced instance was released and then later
3246/// returned by the host platform.
33- class $instanceManagerClassName {
34- /// Constructs a [$instanceManagerClassName ].
35- $instanceManagerClassName ({required void Function(int) onWeakReferenceRemoved}) {
47+ class $dartInstanceManagerClassName {
48+ /// Constructs a [$dartInstanceManagerClassName ].
49+ $dartInstanceManagerClassName ({required void Function(int) onWeakReferenceRemoved}) {
3650 this.onWeakReferenceRemoved = (int identifier) {
3751 _weakInstances.remove(identifier);
3852 onWeakReferenceRemoved(identifier);
@@ -46,12 +60,12 @@ class $instanceManagerClassName {
4660 // 0 <= n < 2^16.
4761 static const int _maxDartCreatedIdentifier = 65536;
4862
49- /// The default [$instanceManagerClassName ] used by ProxyApis.
63+ /// The default [$dartInstanceManagerClassName ] used by ProxyApis.
5064 ///
5165 /// On creation, this manager makes a call to clear the native
5266 /// InstanceManager. This is to prevent identifier conflicts after a host
5367 /// restart.
54- static final $instanceManagerClassName instance = _initInstance();
68+ static final $dartInstanceManagerClassName instance = _initInstance();
5569
5670 // Expando is used because it doesn't prevent its keys from becoming
5771 // inaccessible. This allows the manager to efficiently retrieve an identifier
@@ -72,17 +86,17 @@ class $instanceManagerClassName {
7286 /// or becomes inaccessible.
7387 late final void Function(int) onWeakReferenceRemoved;
7488
75- static $instanceManagerClassName _initInstance() {
89+ static $dartInstanceManagerClassName _initInstance() {
7690 WidgetsFlutterBinding.ensureInitialized();
77- final _${ instanceManagerClassName }Api api = _${ instanceManagerClassName }Api ();
78- // Clears the native `$instanceManagerClassName ` on the initial use of the Dart one.
91+ final $ dartInstanceManagerApiClassName api = $ dartInstanceManagerApiClassName ();
92+ // Clears the native `$dartInstanceManagerClassName ` on the initial use of the Dart one.
7993 api.clear();
80- final $instanceManagerClassName instanceManager = $instanceManagerClassName (
94+ final $dartInstanceManagerClassName instanceManager = $dartInstanceManagerClassName (
8195 onWeakReferenceRemoved: (int identifier) {
8296 api.removeStrongReference(identifier);
8397 },
8498 );
85- _${ instanceManagerClassName }Api .setUpMessageHandlers(instanceManager: instanceManager);
99+ $ dartInstanceManagerApiClassName .setUpMessageHandlers(instanceManager: instanceManager);
86100 ${apiHandlerSetUps .join ('\n\t\t ' )}
87101 return instanceManager;
88102 }
@@ -229,9 +243,9 @@ abstract class $proxyApiBaseClassName {
229243 /// Construct a [$proxyApiBaseClassName ].
230244 $proxyApiBaseClassName ({
231245 this.$_proxyApiBaseClassMessengerVarName ,
232- $instanceManagerClassName ? $_proxyApiBaseClassInstanceManagerVarName ,
246+ $dartInstanceManagerClassName ? $_proxyApiBaseClassInstanceManagerVarName ,
233247 }) : $_proxyApiBaseClassInstanceManagerVarName =
234- $_proxyApiBaseClassInstanceManagerVarName ?? $instanceManagerClassName .instance;
248+ $_proxyApiBaseClassInstanceManagerVarName ?? $dartInstanceManagerClassName .instance;
235249
236250 /// Sends and receives binary data across the Flutter platform barrier.
237251 ///
@@ -242,12 +256,12 @@ abstract class $proxyApiBaseClassName {
242256
243257 /// Maintains instances stored to communicate with native language objects.
244258 @protected
245- final $instanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName ;
259+ final $dartInstanceManagerClassName $_proxyApiBaseClassInstanceManagerVarName ;
246260
247261 /// Instantiates and returns a functionally identical object to oneself.
248262 ///
249263 /// Outside of tests, this method should only ever be called by
250- /// [$instanceManagerClassName ].
264+ /// [$dartInstanceManagerClassName ].
251265 ///
252266 /// Subclasses should always override their parent's implementation of this
253267 /// method.
@@ -264,11 +278,11 @@ abstract class $proxyApiBaseClassName {
264278const String proxyApiBaseCodec = '''
265279class $_proxyApiCodecName extends _PigeonCodec {
266280 const $_proxyApiCodecName (this.instanceManager);
267- final $instanceManagerClassName instanceManager;
281+ final $dartInstanceManagerClassName instanceManager;
268282 @override
269283 void writeValue(WriteBuffer buffer, Object? value) {
270284 if (value is $proxyApiBaseClassName ) {
271- buffer.putUint8(128 );
285+ buffer.putUint8($ proxyApiCodecInstanceManagerKey );
272286 writeValue(buffer, instanceManager.getIdentifier(value));
273287 } else {
274288 super.writeValue(buffer, value);
@@ -277,7 +291,7 @@ class $_proxyApiCodecName extends _PigeonCodec {
277291 @override
278292 Object? readValueOfType(int type, ReadBuffer buffer) {
279293 switch (type) {
280- case 128 :
294+ case $ proxyApiCodecInstanceManagerKey :
281295 return instanceManager
282296 .getInstanceWithWeakReference(readValue(buffer)! as int);
283297 default:
0 commit comments