Skip to content

Commit cb0683e

Browse files
authored
[pigeon] removes restriction on number of custom types per file (#6840)
removes restriction on number of custom types per file (except for gobject). also fixes bug in objc with multiple enums in a class resolves a couple other minor issues: fixes flutter/flutter#150385 fixes flutter/flutter#150108 work toward flutter/flutter#152916
1 parent 687c8a5 commit cb0683e

File tree

69 files changed

+11158
-5486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+11158
-5486
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
## NEXT
1+
## 21.2.0
22

3+
* Removes restriction on number of custom types.
4+
* [java] Fixes bug with multiple enums.
5+
* [java] Removes `Object` from generics.
6+
* [objc] Fixes bug with multiple enums per data class.
7+
* Updates `varPrefix` and `classMemberNamePrefix`.
38
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.
49

510
## 21.1.0

packages/pigeon/example/app/android/app/src/main/java/io/flutter/plugins/Messages.java

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public FlutterError(@NonNull String code, @Nullable String message, @Nullable Ob
4646

4747
@NonNull
4848
protected static ArrayList<Object> wrapError(@NonNull Throwable exception) {
49-
ArrayList<Object> errorList = new ArrayList<Object>(3);
49+
ArrayList<Object> errorList = new ArrayList<>(3);
5050
if (exception instanceof FlutterError) {
5151
FlutterError error = (FlutterError) exception;
5252
errorList.add(error.code);
@@ -77,7 +77,7 @@ public enum Code {
7777

7878
final int index;
7979

80-
private Code(final int index) {
80+
Code(final int index) {
8181
this.index = index;
8282
}
8383
}
@@ -199,23 +199,23 @@ public static final class Builder {
199199

200200
@NonNull
201201
ArrayList<Object> toList() {
202-
ArrayList<Object> toListResult = new ArrayList<Object>(4);
202+
ArrayList<Object> toListResult = new ArrayList<>(4);
203203
toListResult.add(name);
204204
toListResult.add(description);
205205
toListResult.add(code);
206206
toListResult.add(data);
207207
return toListResult;
208208
}
209209

210-
static @NonNull MessageData fromList(@NonNull ArrayList<Object> __pigeon_list) {
210+
static @NonNull MessageData fromList(@NonNull ArrayList<Object> pigeonVar_list) {
211211
MessageData pigeonResult = new MessageData();
212-
Object name = __pigeon_list.get(0);
212+
Object name = pigeonVar_list.get(0);
213213
pigeonResult.setName((String) name);
214-
Object description = __pigeon_list.get(1);
214+
Object description = pigeonVar_list.get(1);
215215
pigeonResult.setDescription((String) description);
216-
Object code = __pigeon_list.get(2);
216+
Object code = pigeonVar_list.get(2);
217217
pigeonResult.setCode((Code) code);
218-
Object data = __pigeon_list.get(3);
218+
Object data = pigeonVar_list.get(3);
219219
pigeonResult.setData((Map<String, String>) data);
220220
return pigeonResult;
221221
}
@@ -230,23 +230,25 @@ private PigeonCodec() {}
230230
protected Object readValueOfType(byte type, @NonNull ByteBuffer buffer) {
231231
switch (type) {
232232
case (byte) 129:
233-
return MessageData.fromList((ArrayList<Object>) readValue(buffer));
233+
{
234+
Object value = readValue(buffer);
235+
return value == null ? null : Code.values()[(int) value];
236+
}
234237
case (byte) 130:
235-
Object value = readValue(buffer);
236-
return value == null ? null : Code.values()[(int) value];
238+
return MessageData.fromList((ArrayList<Object>) readValue(buffer));
237239
default:
238240
return super.readValueOfType(type, buffer);
239241
}
240242
}
241243

242244
@Override
243245
protected void writeValue(@NonNull ByteArrayOutputStream stream, Object value) {
244-
if (value instanceof MessageData) {
246+
if (value instanceof Code) {
245247
stream.write(129);
246-
writeValue(stream, ((MessageData) value).toList());
247-
} else if (value instanceof Code) {
248-
stream.write(130);
249248
writeValue(stream, value == null ? null : ((Code) value).index);
249+
} else if (value instanceof MessageData) {
250+
stream.write(130);
251+
writeValue(stream, ((MessageData) value).toList());
250252
} else {
251253
super.writeValue(stream, value);
252254
}
@@ -312,13 +314,12 @@ static void setUp(
312314
if (api != null) {
313315
channel.setMessageHandler(
314316
(message, reply) -> {
315-
ArrayList<Object> wrapped = new ArrayList<Object>();
317+
ArrayList<Object> wrapped = new ArrayList<>();
316318
try {
317319
String output = api.getHostLanguage();
318320
wrapped.add(0, output);
319321
} catch (Throwable exception) {
320-
ArrayList<Object> wrappedError = wrapError(exception);
321-
wrapped = wrappedError;
322+
wrapped = wrapError(exception);
322323
}
323324
reply.reply(wrapped);
324325
});
@@ -336,7 +337,7 @@ static void setUp(
336337
if (api != null) {
337338
channel.setMessageHandler(
338339
(message, reply) -> {
339-
ArrayList<Object> wrapped = new ArrayList<Object>();
340+
ArrayList<Object> wrapped = new ArrayList<>();
340341
ArrayList<Object> args = (ArrayList<Object>) message;
341342
Number aArg = (Number) args.get(0);
342343
Number bArg = (Number) args.get(1);
@@ -347,8 +348,7 @@ static void setUp(
347348
(bArg == null) ? null : bArg.longValue());
348349
wrapped.add(0, output);
349350
} catch (Throwable exception) {
350-
ArrayList<Object> wrappedError = wrapError(exception);
351-
wrapped = wrappedError;
351+
wrapped = wrapError(exception);
352352
}
353353
reply.reply(wrapped);
354354
});
@@ -366,7 +366,7 @@ static void setUp(
366366
if (api != null) {
367367
channel.setMessageHandler(
368368
(message, reply) -> {
369-
ArrayList<Object> wrapped = new ArrayList<Object>();
369+
ArrayList<Object> wrapped = new ArrayList<>();
370370
ArrayList<Object> args = (ArrayList<Object>) message;
371371
MessageData messageArg = (MessageData) args.get(0);
372372
Result<Boolean> resultCallback =
@@ -405,8 +405,7 @@ public MessageFlutterApi(
405405
this.messageChannelSuffix = messageChannelSuffix.isEmpty() ? "" : "." + messageChannelSuffix;
406406
}
407407

408-
/** Public interface for sending reply. */
409-
/** The codec used by MessageFlutterApi. */
408+
/** Public interface for sending reply. The codec used by MessageFlutterApi. */
410409
static @NonNull MessageCodec<Object> getCodec() {
411410
return PigeonCodec.INSTANCE;
412411
}
@@ -418,16 +417,14 @@ public void flutterMethod(@Nullable String aStringArg, @NonNull Result<String> r
418417
BasicMessageChannel<Object> channel =
419418
new BasicMessageChannel<>(binaryMessenger, channelName, getCodec());
420419
channel.send(
421-
new ArrayList<Object>(Collections.singletonList(aStringArg)),
420+
new ArrayList<>(Collections.singletonList(aStringArg)),
422421
channelReply -> {
423422
if (channelReply instanceof List) {
424423
List<Object> listReply = (List<Object>) channelReply;
425424
if (listReply.size() > 1) {
426425
result.error(
427426
new FlutterError(
428-
(String) listReply.get(0),
429-
(String) listReply.get(1),
430-
(String) listReply.get(2)));
427+
(String) listReply.get(0), (String) listReply.get(1), listReply.get(2)));
431428
} else if (listReply.get(0) == null) {
432429
result.error(
433430
new FlutterError(

packages/pigeon/example/app/android/app/src/main/kotlin/dev/flutter/pigeon_example_app/Messages.g.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ data class MessageData(
6565
val data: Map<String?, String?>
6666
) {
6767
companion object {
68-
@Suppress("LocalVariableName")
69-
fun fromList(__pigeon_list: List<Any?>): MessageData {
70-
val name = __pigeon_list[0] as String?
71-
val description = __pigeon_list[1] as String?
72-
val code = __pigeon_list[2] as Code
73-
val data = __pigeon_list[3] as Map<String?, String?>
68+
fun fromList(pigeonVar_list: List<Any?>): MessageData {
69+
val name = pigeonVar_list[0] as String?
70+
val description = pigeonVar_list[1] as String?
71+
val code = pigeonVar_list[2] as Code
72+
val data = pigeonVar_list[3] as Map<String?, String?>
7473
return MessageData(name, description, code, data)
7574
}
7675
}
@@ -89,24 +88,24 @@ private object MessagesPigeonCodec : StandardMessageCodec() {
8988
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
9089
return when (type) {
9190
129.toByte() -> {
92-
return (readValue(buffer) as? List<Any?>)?.let { MessageData.fromList(it) }
91+
return (readValue(buffer) as Int?)?.let { Code.ofRaw(it) }
9392
}
9493
130.toByte() -> {
95-
return (readValue(buffer) as Int?)?.let { Code.ofRaw(it) }
94+
return (readValue(buffer) as? List<Any?>)?.let { MessageData.fromList(it) }
9695
}
9796
else -> super.readValueOfType(type, buffer)
9897
}
9998
}
10099

101100
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
102101
when (value) {
103-
is MessageData -> {
102+
is Code -> {
104103
stream.write(129)
105-
writeValue(stream, value.toList())
104+
writeValue(stream, value.raw)
106105
}
107-
is Code -> {
106+
is MessageData -> {
108107
stream.write(130)
109-
writeValue(stream, value.raw)
108+
writeValue(stream, value.toList())
110109
}
111110
else -> super.writeValue(stream, value)
112111
}

packages/pigeon/example/app/ios/Runner/Messages.g.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ struct MessageData {
8686
var data: [String?: String?]
8787

8888
// swift-format-ignore: AlwaysUseLowerCamelCase
89-
static func fromList(_ __pigeon_list: [Any?]) -> MessageData? {
90-
let name: String? = nilOrValue(__pigeon_list[0])
91-
let description: String? = nilOrValue(__pigeon_list[1])
92-
let code = __pigeon_list[2] as! Code
93-
let data = __pigeon_list[3] as! [String?: String?]
89+
static func fromList(_ pigeonVar_list: [Any?]) -> MessageData? {
90+
let name: String? = nilOrValue(pigeonVar_list[0])
91+
let description: String? = nilOrValue(pigeonVar_list[1])
92+
let code = pigeonVar_list[2] as! Code
93+
let data = pigeonVar_list[3] as! [String?: String?]
9494

9595
return MessageData(
9696
name: name,
@@ -108,18 +108,18 @@ struct MessageData {
108108
]
109109
}
110110
}
111+
111112
private class MessagesPigeonCodecReader: FlutterStandardReader {
112113
override func readValue(ofType type: UInt8) -> Any? {
113114
switch type {
114115
case 129:
115-
return MessageData.fromList(self.readValue() as! [Any?])
116-
case 130:
117-
var enumResult: Code? = nil
118116
let enumResultAsInt: Int? = nilOrValue(self.readValue() as? Int)
119117
if let enumResultAsInt = enumResultAsInt {
120-
enumResult = Code(rawValue: enumResultAsInt)
118+
return Code(rawValue: enumResultAsInt)
121119
}
122-
return enumResult
120+
return nil
121+
case 130:
122+
return MessageData.fromList(self.readValue() as! [Any?])
123123
default:
124124
return super.readValue(ofType: type)
125125
}
@@ -128,12 +128,12 @@ private class MessagesPigeonCodecReader: FlutterStandardReader {
128128

129129
private class MessagesPigeonCodecWriter: FlutterStandardWriter {
130130
override func writeValue(_ value: Any) {
131-
if let value = value as? MessageData {
131+
if let value = value as? Code {
132132
super.writeByte(129)
133-
super.writeValue(value.toList())
134-
} else if let value = value as? Code {
135-
super.writeByte(130)
136133
super.writeValue(value.rawValue)
134+
} else if let value = value as? MessageData {
135+
super.writeByte(130)
136+
super.writeValue(value.toList())
137137
} else {
138138
super.writeValue(value)
139139
}

0 commit comments

Comments
 (0)