Skip to content

[pigeon] Fixes channel names of the named constructors of ProxyApis. #8201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 22.6.4

* [swift] Fixes the channel names of the named constructors of ProxyApis.

## 22.6.3

* Replaces deprecated collection method usage.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '22.6.3';
const String pigeonVersion = '22.6.4';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
4 changes: 3 additions & 1 deletion packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,9 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
: 'pigeonDefaultConstructor';
final String channelName = makeChannelNameWithStrings(
apiName: api.name,
methodName: '${classMemberNamePrefix}defaultConstructor',
methodName: constructor.name.isNotEmpty
? constructor.name
: '${classMemberNamePrefix}defaultConstructor',
dartPackageName: dartPackageName,
);
writeWithApiCheckIfNecessary(
Expand Down
2 changes: 2 additions & 0 deletions packages/pigeon/pigeons/proxy_api_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ abstract class ProxyApiTestClass extends ProxyApiSuperClass
ProxyApiSuperClass? nullableProxyApiParam,
);

ProxyApiTestClass.namedConstructor();

late bool aBool;
late int anInt;
late double aDouble;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,22 @@ void runPigeonIntegrationTests(TargetGenerator targetGenerator) {
return;
}

testWidgets('named constructor', (_) async {
final ProxyApiTestClass instance = ProxyApiTestClass.namedConstructor(
aBool: true,
anInt: 0,
aDouble: 0.0,
aString: '',
aUint8List: Uint8List(0),
aList: const <Object?>[],
aMap: const <String?, Object?>{},
anEnum: ProxyApiTestEnum.one,
aProxyApi: ProxyApiSuperClass(),
);
// Ensure no error calling method on instance.
await instance.noop();
});

testWidgets('noop', (_) async {
final ProxyApiTestClass api = _createGenericProxyApiTestClass();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,104 @@ class ProxyApiTestClass extends ProxyApiSuperClass
}();
}

ProxyApiTestClass.namedConstructor({
super.pigeon_binaryMessenger,
super.pigeon_instanceManager,
required this.aBool,
required this.anInt,
required this.aDouble,
required this.aString,
required this.aUint8List,
required this.aList,
required this.aMap,
required this.anEnum,
required this.aProxyApi,
this.aNullableBool,
this.aNullableInt,
this.aNullableDouble,
this.aNullableString,
this.aNullableUint8List,
this.aNullableList,
this.aNullableMap,
this.aNullableEnum,
this.aNullableProxyApi,
this.anInterfaceMethod,
this.flutterNoop,
this.flutterThrowError,
this.flutterThrowErrorFromVoid,
this.flutterEchoBool,
this.flutterEchoInt,
this.flutterEchoDouble,
this.flutterEchoString,
this.flutterEchoUint8List,
this.flutterEchoList,
this.flutterEchoProxyApiList,
this.flutterEchoMap,
this.flutterEchoProxyApiMap,
this.flutterEchoEnum,
this.flutterEchoProxyApi,
this.flutterEchoNullableBool,
this.flutterEchoNullableInt,
this.flutterEchoNullableDouble,
this.flutterEchoNullableString,
this.flutterEchoNullableUint8List,
this.flutterEchoNullableList,
this.flutterEchoNullableMap,
this.flutterEchoNullableEnum,
this.flutterEchoNullableProxyApi,
this.flutterNoopAsync,
this.flutterEchoAsyncString,
}) : super.pigeon_detached() {
final int pigeonVar_instanceIdentifier =
pigeon_instanceManager.addDartCreatedInstance(this);
final _PigeonInternalProxyApiBaseCodec pigeonChannelCodec =
_pigeonVar_codecProxyApiTestClass;
final BinaryMessenger? pigeonVar_binaryMessenger = pigeon_binaryMessenger;
() async {
const String pigeonVar_channelName =
'dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor';
final BasicMessageChannel<Object?> pigeonVar_channel =
BasicMessageChannel<Object?>(
pigeonVar_channelName,
pigeonChannelCodec,
binaryMessenger: pigeonVar_binaryMessenger,
);
final List<Object?>? pigeonVar_replyList =
await pigeonVar_channel.send(<Object?>[
pigeonVar_instanceIdentifier,
aBool,
anInt,
aDouble,
aString,
aUint8List,
aList,
aMap,
anEnum,
aProxyApi,
aNullableBool,
aNullableInt,
aNullableDouble,
aNullableString,
aNullableUint8List,
aNullableList,
aNullableMap,
aNullableEnum,
aNullableProxyApi
]) as List<Object?>?;
if (pigeonVar_replyList == null) {
throw _createConnectionError(pigeonVar_channelName);
} else if (pigeonVar_replyList.length > 1) {
throw PlatformException(
code: pigeonVar_replyList[0]! as String,
message: pigeonVar_replyList[1] as String?,
details: pigeonVar_replyList[2],
);
} else {
return;
}
}();
}

/// Constructs [ProxyApiTestClass] without creating the associated native object.
///
/// This should only be used by subclasses created by this library or to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,29 @@ class ProxyApiTestClassApi(override val pigeonRegistrar: ProxyApiRegistrar) :
return ProxyApiTestClass()
}

override fun namedConstructor(
aBool: Boolean,
anInt: Long,
aDouble: Double,
aString: String,
aUint8List: ByteArray,
aList: List<Any?>,
aMap: Map<String?, Any?>,
anEnum: ProxyApiTestEnum,
aProxyApi: ProxyApiSuperClass,
aNullableBool: Boolean?,
aNullableInt: Long?,
aNullableDouble: Double?,
aNullableString: String?,
aNullableUint8List: ByteArray?,
aNullableList: List<Any?>?,
aNullableMap: Map<String?, Any?>?,
aNullableEnum: ProxyApiTestEnum?,
aNullableProxyApi: ProxyApiSuperClass?,
): ProxyApiTestClass {
return ProxyApiTestClass()
}

override fun attachedField(pigeon_instance: ProxyApiTestClass): ProxyApiSuperClass {
return ProxyApiSuperClass()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,27 @@ abstract class PigeonApiProxyApiTestClass(
nullableProxyApiParam: com.example.test_plugin.ProxyApiSuperClass?
): ProxyApiTestClass

abstract fun namedConstructor(
aBool: Boolean,
anInt: Long,
aDouble: Double,
aString: String,
aUint8List: ByteArray,
aList: List<Any?>,
aMap: Map<String?, Any?>,
anEnum: ProxyApiTestEnum,
aProxyApi: com.example.test_plugin.ProxyApiSuperClass,
aNullableBool: Boolean?,
aNullableInt: Long?,
aNullableDouble: Double?,
aNullableString: String?,
aNullableUint8List: ByteArray?,
aNullableList: List<Any?>?,
aNullableMap: Map<String?, Any?>?,
aNullableEnum: ProxyApiTestEnum?,
aNullableProxyApi: com.example.test_plugin.ProxyApiSuperClass?
): ProxyApiTestClass

abstract fun attachedField(
pigeon_instance: ProxyApiTestClass
): com.example.test_plugin.ProxyApiSuperClass
Expand Down Expand Up @@ -1108,6 +1129,67 @@ abstract class PigeonApiProxyApiTestClass(
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
binaryMessenger,
"dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor",
codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val pigeon_identifierArg = args[0] as Long
val aBoolArg = args[1] as Boolean
val anIntArg = args[2] as Long
val aDoubleArg = args[3] as Double
val aStringArg = args[4] as String
val aUint8ListArg = args[5] as ByteArray
val aListArg = args[6] as List<Any?>
val aMapArg = args[7] as Map<String?, Any?>
val anEnumArg = args[8] as ProxyApiTestEnum
val aProxyApiArg = args[9] as com.example.test_plugin.ProxyApiSuperClass
val aNullableBoolArg = args[10] as Boolean?
val aNullableIntArg = args[11] as Long?
val aNullableDoubleArg = args[12] as Double?
val aNullableStringArg = args[13] as String?
val aNullableUint8ListArg = args[14] as ByteArray?
val aNullableListArg = args[15] as List<Any?>?
val aNullableMapArg = args[16] as Map<String?, Any?>?
val aNullableEnumArg = args[17] as ProxyApiTestEnum?
val aNullableProxyApiArg = args[18] as com.example.test_plugin.ProxyApiSuperClass?
val wrapped: List<Any?> =
try {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
api.namedConstructor(
aBoolArg,
anIntArg,
aDoubleArg,
aStringArg,
aUint8ListArg,
aListArg,
aMapArg,
anEnumArg,
aProxyApiArg,
aNullableBoolArg,
aNullableIntArg,
aNullableDoubleArg,
aNullableStringArg,
aNullableUint8ListArg,
aNullableListArg,
aNullableMapArg,
aNullableEnumArg,
aNullableProxyApiArg),
pigeon_identifierArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel =
BasicMessageChannel<Any?>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,15 @@ protocol PigeonApiDelegateProxyApiTestClass {
nullableListParam: [Any?]?, nullableMapParam: [String?: Any?]?,
nullableEnumParam: ProxyApiTestEnum?, nullableProxyApiParam: ProxyApiSuperClass?
) throws -> ProxyApiTestClass
func namedConstructor(
pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double,
aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?],
anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?,
aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?,
aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?,
aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?,
aNullableProxyApi: ProxyApiSuperClass?
) throws -> ProxyApiTestClass
func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass)
throws -> ProxyApiSuperClass
func staticAttachedField(pigeonApi: PigeonApiProxyApiTestClass) throws -> ProxyApiSuperClass
Expand Down Expand Up @@ -1168,6 +1177,50 @@ final class PigeonApiProxyApiTestClass: PigeonApiProtocolProxyApiTestClass {
} else {
pigeonDefaultConstructorChannel.setMessageHandler(nil)
}
let namedConstructorChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.namedConstructor",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
namedConstructorChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonIdentifierArg = args[0] as! Int64
let aBoolArg = args[1] as! Bool
let anIntArg = args[2] as! Int64
let aDoubleArg = args[3] as! Double
let aStringArg = args[4] as! String
let aUint8ListArg = args[5] as! FlutterStandardTypedData
let aListArg = args[6] as! [Any?]
let aMapArg = args[7] as! [String?: Any?]
let anEnumArg = args[8] as! ProxyApiTestEnum
let aProxyApiArg = args[9] as! ProxyApiSuperClass
let aNullableBoolArg: Bool? = nilOrValue(args[10])
let aNullableIntArg: Int64? = nilOrValue(args[11])
let aNullableDoubleArg: Double? = nilOrValue(args[12])
let aNullableStringArg: String? = nilOrValue(args[13])
let aNullableUint8ListArg: FlutterStandardTypedData? = nilOrValue(args[14])
let aNullableListArg: [Any?]? = nilOrValue(args[15])
let aNullableMapArg: [String?: Any?]? = nilOrValue(args[16])
let aNullableEnumArg: ProxyApiTestEnum? = nilOrValue(args[17])
let aNullableProxyApiArg: ProxyApiSuperClass? = nilOrValue(args[18])
do {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
try api.pigeonDelegate.namedConstructor(
pigeonApi: api, aBool: aBoolArg, anInt: anIntArg, aDouble: aDoubleArg,
aString: aStringArg, aUint8List: aUint8ListArg, aList: aListArg, aMap: aMapArg,
anEnum: anEnumArg, aProxyApi: aProxyApiArg, aNullableBool: aNullableBoolArg,
aNullableInt: aNullableIntArg, aNullableDouble: aNullableDoubleArg,
aNullableString: aNullableStringArg, aNullableUint8List: aNullableUint8ListArg,
aNullableList: aNullableListArg, aNullableMap: aNullableMapArg,
aNullableEnum: aNullableEnumArg, aNullableProxyApi: aNullableProxyApiArg),
withIdentifier: pigeonIdentifierArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
namedConstructorChannel.setMessageHandler(nil)
}
let attachedFieldChannel = FlutterBasicMessageChannel(
name: "dev.flutter.pigeon.pigeon_integration_tests.ProxyApiTestClass.attachedField",
binaryMessenger: binaryMessenger, codec: codec)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,18 @@ class ProxyApiDelegate: ProxyApiTestsPigeonProxyApiDelegate {
return ProxyApiTestClass()
}

func namedConstructor(
pigeonApi: PigeonApiProxyApiTestClass, aBool: Bool, anInt: Int64, aDouble: Double,
aString: String, aUint8List: FlutterStandardTypedData, aList: [Any?], aMap: [String?: Any?],
anEnum: ProxyApiTestEnum, aProxyApi: ProxyApiSuperClass, aNullableBool: Bool?,
aNullableInt: Int64?, aNullableDouble: Double?, aNullableString: String?,
aNullableUint8List: FlutterStandardTypedData?, aNullableList: [Any?]?,
aNullableMap: [String?: Any?]?, aNullableEnum: ProxyApiTestEnum?,
aNullableProxyApi: ProxyApiSuperClass?
) throws -> ProxyApiTestClass {
return ProxyApiTestClass()
}

func attachedField(pigeonApi: PigeonApiProxyApiTestClass, pigeonInstance: ProxyApiTestClass)
throws -> ProxyApiSuperClass
{
Expand Down
Loading
Loading