Skip to content

Commit 7496306

Browse files
[pigeon] Fixes channel names of the named constructors of ProxyApis. (#8201)
1 parent 28160ca commit 7496306

File tree

15 files changed

+399
-5
lines changed

15 files changed

+399
-5
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 22.6.4
2+
3+
* [swift] Fixes the channel names of the named constructors of ProxyApis.
4+
15
## 22.6.3
26

37
* Replaces deprecated collection method usage.

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'ast.dart';
1414
/// The current version of pigeon.
1515
///
1616
/// This must match the version in pubspec.yaml.
17-
const String pigeonVersion = '22.6.3';
17+
const String pigeonVersion = '22.6.4';
1818

1919
/// Read all the content from [stdin] to a String.
2020
String readStdin() {

packages/pigeon/lib/swift_generator.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,9 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
20122012
: 'pigeonDefaultConstructor';
20132013
final String channelName = makeChannelNameWithStrings(
20142014
apiName: api.name,
2015-
methodName: '${classMemberNamePrefix}defaultConstructor',
2015+
methodName: constructor.name.isNotEmpty
2016+
? constructor.name
2017+
: '${classMemberNamePrefix}defaultConstructor',
20162018
dartPackageName: dartPackageName,
20172019
);
20182020
writeWithApiCheckIfNecessary(

packages/pigeon/pigeons/proxy_api_tests.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass
5454
ProxyApiSuperClass? nullableProxyApiParam,
5555
);
5656

57+
ProxyApiTestClass.namedConstructor();
58+
5759
late bool aBool;
5860
late int anInt;
5961
late double aDouble;

packages/pigeon/platform_tests/shared_test_plugin_code/lib/integration_tests.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,22 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
21702170
return;
21712171
}
21722172

2173+
testWidgets('named constructor', (_) async {
2174+
final ProxyApiTestClass instance = ProxyApiTestClass.namedConstructor(
2175+
aBool: true,
2176+
anInt: 0,
2177+
aDouble: 0.0,
2178+
aString: '',
2179+
aUint8List: Uint8List(0),
2180+
aList: const <Object?>[],
2181+
aMap: const <String?, Object?>{},
2182+
anEnum: ProxyApiTestEnum.one,
2183+
aProxyApi: ProxyApiSuperClass(),
2184+
);
2185+
// Ensure no error calling method on instance.
2186+
await instance.noop();
2187+
});
2188+
21732189
testWidgets('noop', (_) async {
21742190
final ProxyApiTestClass api = _createGenericProxyApiTestClass();
21752191

packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/proxy_api_tests.gen.dart

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,104 @@ class ProxyApiTestClass extends ProxyApiSuperClass
578578
}();
579579
}
580580

581+
ProxyApiTestClass.namedConstructor({
582+
super.pigeon_binaryMessenger,
583+
super.pigeon_instanceManager,
584+
required this.aBool,
585+
required this.anInt,
586+
required this.aDouble,
587+
required this.aString,
588+
required this.aUint8List,
589+
required this.aList,
590+
required this.aMap,
591+
required this.anEnum,
592+
required this.aProxyApi,
593+
this.aNullableBool,
594+
this.aNullableInt,
595+
this.aNullableDouble,
596+
this.aNullableString,
597+
this.aNullableUint8List,
598+
this.aNullableList,
599+
this.aNullableMap,
600+
this.aNullableEnum,
601+
this.aNullableProxyApi,
602+
this.anInterfaceMethod,
603+
this.flutterNoop,
604+
this.flutterThrowError,
605+
this.flutterThrowErrorFromVoid,
606+
this.flutterEchoBool,
607+
this.flutterEchoInt,
608+
this.flutterEchoDouble,
609+
this.flutterEchoString,
610+
this.flutterEchoUint8List,
611+
this.flutterEchoList,
612+
this.flutterEchoProxyApiList,
613+
this.flutterEchoMap,
614+
this.flutterEchoProxyApiMap,
615+
this.flutterEchoEnum,
616+
this.flutterEchoProxyApi,
617+
this.flutterEchoNullableBool,
618+
this.flutterEchoNullableInt,
619+
this.flutterEchoNullableDouble,
620+
this.flutterEchoNullableString,
621+
this.flutterEchoNullableUint8List,
622+
this.flutterEchoNullableList,
623+
this.flutterEchoNullableMap,
624+
this.flutterEchoNullableEnum,
625+
this.flutterEchoNullableProxyApi,
626+
this.flutterNoopAsync,
627+
this.flutterEchoAsyncString,
628+
}) : super.pigeon_detached() {
629+
final int pigeonVar_instanceIdentifier =
630+
pigeon_instanceManager.addDartCreatedInstance(this);
631+
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
632+
_pigeonVar_codecProxyApiTestClass;
633+
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
634+
() async {
635+
const String pigeonVar_channelName =
636+
'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor';
637+
final BasicMessageChannel<Object?> pigeonVar_channel =
638+
BasicMessageChannel<Object?>(
639+
pigeonVar_channelName,
640+
pigeonChannelCodec,
641+
binaryMessenger: pigeonVar_binaryMessenger,
642+
);
643+
final List<Object?>? pigeonVar_replyList =
644+
await pigeonVar_channel.send(<Object?>[
645+
pigeonVar_instanceIdentifier,
646+
aBool,
647+
anInt,
648+
aDouble,
649+
aString,
650+
aUint8List,
651+
aList,
652+
aMap,
653+
anEnum,
654+
aProxyApi,
655+
aNullableBool,
656+
aNullableInt,
657+
aNullableDouble,
658+
aNullableString,
659+
aNullableUint8List,
660+
aNullableList,
661+
aNullableMap,
662+
aNullableEnum,
663+
aNullableProxyApi
664+
]) as List<Object?>?;
665+
if (pigeonVar_replyList == null) {
666+
throw _createConnectionError(pigeonVar_channelName);
667+
} else if (pigeonVar_replyList.length > 1) {
668+
throw PlatformException(
669+
code: pigeonVar_replyList[0]! as String,
670+
message: pigeonVar_replyList[1] as String?,
671+
details: pigeonVar_replyList[2],
672+
);
673+
} else {
674+
return;
675+
}
676+
}();
677+
}
678+
581679
/// Constructs [ProxyApiTestClass] without creating the associated native object.
582680
///
583681
/// This should only be used by subclasses created by this library or to

packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ class ProxyApiTestClassApi(override val pigeonRegistrar: ProxyApiRegistrar) :
7474
return ProxyApiTestClass()
7575
}
7676

77+
override fun namedConstructor(
78+
aBool: Boolean,
79+
anInt: Long,
80+
aDouble: Double,
81+
aString: String,
82+
aUint8List: ByteArray,
83+
aList: List<Any?>,
84+
aMap: Map<String?, Any?>,
85+
anEnum: ProxyApiTestEnum,
86+
aProxyApi: ProxyApiSuperClass,
87+
aNullableBool: Boolean?,
88+
aNullableInt: Long?,
89+
aNullableDouble: Double?,
90+
aNullableString: String?,
91+
aNullableUint8List: ByteArray?,
92+
aNullableList: List<Any?>?,
93+
aNullableMap: Map<String?, Any?>?,
94+
aNullableEnum: ProxyApiTestEnum?,
95+
aNullableProxyApi: ProxyApiSuperClass?,
96+
): ProxyApiTestClass {
97+
return ProxyApiTestClass()
98+
}
99+
77100
override fun attachedField(pigeon_instance: ProxyApiTestClass): ProxyApiSuperClass {
78101
return ProxyApiSuperClass()
79102
}

packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTests.gen.kt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,27 @@ abstract class PigeonApiProxyApiTestClass(
549549
nullableProxyApiParam: com.example.test_plugin.ProxyApiSuperClass?
550550
): ProxyApiTestClass
551551

552+
abstract fun namedConstructor(
553+
aBool: Boolean,
554+
anInt: Long,
555+
aDouble: Double,
556+
aString: String,
557+
aUint8List: ByteArray,
558+
aList: List<Any?>,
559+
aMap: Map<String?, Any?>,
560+
anEnum: ProxyApiTestEnum,
561+
aProxyApi: com.example.test_plugin.ProxyApiSuperClass,
562+
aNullableBool: Boolean?,
563+
aNullableInt: Long?,
564+
aNullableDouble: Double?,
565+
aNullableString: String?,
566+
aNullableUint8List: ByteArray?,
567+
aNullableList: List<Any?>?,
568+
aNullableMap: Map<String?, Any?>?,
569+
aNullableEnum: ProxyApiTestEnum?,
570+
aNullableProxyApi: com.example.test_plugin.ProxyApiSuperClass?
571+
): ProxyApiTestClass
572+
552573
abstract fun attachedField(
553574
pigeon_instance: ProxyApiTestClass
554575
): com.example.test_plugin.ProxyApiSuperClass
@@ -1108,6 +1129,67 @@ abstract class PigeonApiProxyApiTestClass(
11081129
channel.setMessageHandler(null)
11091130
}
11101131
}
1132+
run {
1133+
val channel =
1134+
BasicMessageChannel<Any?>(
1135+
binaryMessenger,
1136+
"dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor",
1137+
codec)
1138+
if (api != null) {
1139+
channel.setMessageHandler { message, reply ->
1140+
val args = message as List<Any?>
1141+
val pigeon_identifierArg = args[0] as Long
1142+
val aBoolArg = args[1] as Boolean
1143+
val anIntArg = args[2] as Long
1144+
val aDoubleArg = args[3] as Double
1145+
val aStringArg = args[4] as String
1146+
val aUint8ListArg = args[5] as ByteArray
1147+
val aListArg = args[6] as List<Any?>
1148+
val aMapArg = args[7] as Map<String?, Any?>
1149+
val anEnumArg = args[8] as ProxyApiTestEnum
1150+
val aProxyApiArg = args[9] as com.example.test_plugin.ProxyApiSuperClass
1151+
val aNullableBoolArg = args[10] as Boolean?
1152+
val aNullableIntArg = args[11] as Long?
1153+
val aNullableDoubleArg = args[12] as Double?
1154+
val aNullableStringArg = args[13] as String?
1155+
val aNullableUint8ListArg = args[14] as ByteArray?
1156+
val aNullableListArg = args[15] as List<Any?>?
1157+
val aNullableMapArg = args[16] as Map<String?, Any?>?
1158+
val aNullableEnumArg = args[17] as ProxyApiTestEnum?
1159+
val aNullableProxyApiArg = args[18] as com.example.test_plugin.ProxyApiSuperClass?
1160+
val wrapped: List<Any?> =
1161+
try {
1162+
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
1163+
api.namedConstructor(
1164+
aBoolArg,
1165+
anIntArg,
1166+
aDoubleArg,
1167+
aStringArg,
1168+
aUint8ListArg,
1169+
aListArg,
1170+
aMapArg,
1171+
anEnumArg,
1172+
aProxyApiArg,
1173+
aNullableBoolArg,
1174+
aNullableIntArg,
1175+
aNullableDoubleArg,
1176+
aNullableStringArg,
1177+
aNullableUint8ListArg,
1178+
aNullableListArg,
1179+
aNullableMapArg,
1180+
aNullableEnumArg,
1181+
aNullableProxyApiArg),
1182+
pigeon_identifierArg)
1183+
listOf(null)
1184+
} catch (exception: Throwable) {
1185+
wrapError(exception)
1186+
}
1187+
reply.reply(wrapped)
1188+
}
1189+
} else {
1190+
channel.setMessageHandler(null)
1191+
}
1192+
}
11111193
run {
11121194
val channel =
11131195
BasicMessageChannel<Any?>(

packages/pigeon/platform_tests/test_plugin/ios/Classes/ProxyApiTests.gen.swift

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,15 @@ protocol PigeonApiDelegateProxyApiTestClass {
628628
nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?,
629629
nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass?
630630
) throws -> ProxyApiTestClass
631+
func namedConstructor(
632+
pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double,
633+
aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?],
634+
anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?,
635+
aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?,
636+
aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?,
637+
aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?,
638+
aNullableProxyApi: ProxyApiSuperClass?
639+
) throws -> ProxyApiTestClass
631640
func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass)
632641
throws -> ProxyApiSuperClass
633642
func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass
@@ -1168,6 +1177,50 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
11681177
} else {
11691178
pigeonDefaultConstructorChannel.setMessageHandler(nil)
11701179
}
1180+
let namedConstructorChannel = FlutterBasicMessageChannel(
1181+
name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor",
1182+
binaryMessenger: binaryMessenger, codec: codec)
1183+
if let api = api {
1184+
namedConstructorChannel.setMessageHandler { message, reply in
1185+
let args = message as! [Any?]
1186+
let pigeonIdentifierArg = args[0] as! Int64
1187+
let aBoolArg = args[1] as! Bool
1188+
let anIntArg = args[2] as! Int64
1189+
let aDoubleArg = args[3] as! Double
1190+
let aStringArg = args[4] as! String
1191+
let aUint8ListArg = args[5] as! FlutterStandardTypedData
1192+
let aListArg = args[6] as! [Any?]
1193+
let aMapArg = args[7] as! [String?: Any?]
1194+
let anEnumArg = args[8] as! ProxyApiTestEnum
1195+
let aProxyApiArg = args[9] as! ProxyApiSuperClass
1196+
let aNullableBoolArg: Bool? = nilOrValue(args[10])
1197+
let aNullableIntArg: Int64? = nilOrValue(args[11])
1198+
let aNullableDoubleArg: Double? = nilOrValue(args[12])
1199+
let aNullableStringArg: String? = nilOrValue(args[13])
1200+
let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14])
1201+
let aNullableListArg: [Any?]? = nilOrValue(args[15])
1202+
let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16])
1203+
let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17])
1204+
let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18])
1205+
do {
1206+
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
1207+
try api.pigeonDelegate.namedConstructor(
1208+
pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg,
1209+
aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg,
1210+
anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg,
1211+
aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg,
1212+
aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg,
1213+
aNullableList: aNullableListArg, aNullableMap: aNullableMapArg,
1214+
aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg),
1215+
withIdentifier: pigeonIdentifierArg)
1216+
reply(wrapResult(nil))
1217+
} catch {
1218+
reply(wrapError(error))
1219+
}
1220+
}
1221+
} else {
1222+
namedConstructorChannel.setMessageHandler(nil)
1223+
}
11711224
let attachedFieldChannel = FlutterBasicMessageChannel(
11721225
name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField",
11731226
binaryMessenger: binaryMessenger, codec: codec)

packages/pigeon/platform_tests/test_plugin/ios/Classes/TestPlugin.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,18 @@ class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate {
12381238
return ProxyApiTestClass()
12391239
}
12401240

1241+
func namedConstructor(
1242+
pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double,
1243+
aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?],
1244+
anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?,
1245+
aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?,
1246+
aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?,
1247+
aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?,
1248+
aNullableProxyApi: ProxyApiSuperClass?
1249+
) throws -> ProxyApiTestClass {
1250+
return ProxyApiTestClass()
1251+
}
1252+
12411253
func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass)
12421254
throws -> ProxyApiSuperClass
12431255
{

0 commit comments

Comments
 (0)