Skip to content

Commit db86e8f

Browse files
authored
[pigeon] isEnum, isClass, fix swift casting, default values, optional method arguments, named method arguments (flutter#5355)
* **Breaking change** [dart] Renames locally defined host API variables. * Host api static field `codec` changed to `pigeonChannelCodec`. * Adds named parameters to host API methods. * Adds optional parameters to host API methods. * Adds default values for class constructors and host API methods. * Adds `isEnum` and `isClass` to `TypeDeclaration`s. * Removes all `klass` variable names. fixes flutter#127719 fixes flutter#98448 fixes flutter#80048
1 parent a8bb833 commit db86e8f

File tree

56 files changed

+5379
-3270
lines changed

Some content is hidden

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

56 files changed

+5379
-3270
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
## 14.0.0
2+
3+
* **Breaking change** [dart] Renames locally defined host API variables.
4+
* [dart] Host api static field `codec` changed to `pigeonChannelCodec`.
5+
* [dart] Adds named parameters to host API methods.
6+
* [dart] Adds optional parameters to host API methods.
7+
* [dart] Adds default values for class constructors and host API methods.
8+
* Adds `isEnum` and `isClass` to `TypeDeclaration`s.
9+
* [cpp] Fixes `FlutterError` generation being tied to ErrorOr.
10+
111
## 13.1.2
212

3-
* Adds compatibilty with `analyzer` 6.x.
13+
* Adds compatibility with `analyzer` 6.x.
414

515
## 13.1.1
616

@@ -159,7 +169,7 @@
159169
* [java] Adds a `GeneratedApi.FlutterError` exception for passing custom error details (code, message, details).
160170
* [kotlin] Adds a `FlutterError` exception for passing custom error details (code, message, details).
161171
* [kotlin] Adds an `errorClassName` option in `KotlinOptions` for custom error class names.
162-
* [java] Removes legacy try catch from async apis.
172+
* [java] Removes legacy try catch from async APIs.
163173
* [java] Removes legacy null check on non-nullable method arguments.
164174
* [cpp] Fixes wrong order of items in `FlutterError`.
165175
* Adds `FlutterError` handling integration tests for all platforms.
@@ -212,7 +222,7 @@
212222

213223
## 7.2.1
214224

215-
* [kotlin] Fixes Flutter api int errors with updated casting.
225+
* [kotlin] Fixes Flutter API int errors with updated casting.
216226

217227
## 7.2.0
218228

@@ -238,7 +248,7 @@
238248

239249
## 7.1.2
240250

241-
* [swift] Adds error handling to sync host api methods.
251+
* [swift] Adds error handling to sync host API methods.
242252

243253
## 7.1.1
244254

@@ -352,7 +362,7 @@
352362

353363
## 4.2.4
354364

355-
* [kotlin] Fixes Kotlin generated sync host api error.
365+
* [kotlin] Fixes Kotlin generated sync host API error.
356366

357367
## 4.2.3
358368

@@ -831,7 +841,7 @@ class Foo {
831841

832842
## 0.1.0-experimental.11
833843

834-
* Fixed setting an api to null in Java.
844+
* Fixed setting an API to null in Java.
835845

836846
## 0.1.0-experimental.10
837847

packages/pigeon/example/app/lib/src/messages.g.dart

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// found in the LICENSE file.
44
// Autogenerated from Pigeon, do not edit directly.
55
// See also: https://pub.dev/packages/pigeon
6-
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
6+
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import, no_leading_underscores_for_local_identifiers
77

88
import 'dart:async';
99
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
@@ -98,111 +98,118 @@ class ExampleHostApi {
9898
/// available for dependency injection. If it is left null, the default
9999
/// BinaryMessenger will be used which routes to the host platform.
100100
ExampleHostApi({BinaryMessenger? binaryMessenger})
101-
: _binaryMessenger = binaryMessenger;
102-
final BinaryMessenger? _binaryMessenger;
101+
: __pigeon_binaryMessenger = binaryMessenger;
102+
final BinaryMessenger? __pigeon_binaryMessenger;
103103

104-
static const MessageCodec<Object?> codec = _ExampleHostApiCodec();
104+
static const MessageCodec<Object?> pigeonChannelCodec =
105+
_ExampleHostApiCodec();
105106

106107
Future<String> getHostLanguage() async {
107-
const String channelName =
108+
const String __pigeon_channelName =
108109
'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage';
109-
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
110-
channelName,
111-
codec,
112-
binaryMessenger: _binaryMessenger,
110+
final BasicMessageChannel<Object?> __pigeon_channel =
111+
BasicMessageChannel<Object?>(
112+
__pigeon_channelName,
113+
pigeonChannelCodec,
114+
binaryMessenger: __pigeon_binaryMessenger,
113115
);
114-
final List<Object?>? replyList = await channel.send(null) as List<Object?>?;
115-
if (replyList == null) {
116-
throw _createConnectionError(channelName);
117-
} else if (replyList.length > 1) {
116+
final List<Object?>? __pigeon_replyList =
117+
await __pigeon_channel.send(null) as List<Object?>?;
118+
if (__pigeon_replyList == null) {
119+
throw _createConnectionError(__pigeon_channelName);
120+
} else if (__pigeon_replyList.length > 1) {
118121
throw PlatformException(
119-
code: replyList[0]! as String,
120-
message: replyList[1] as String?,
121-
details: replyList[2],
122+
code: __pigeon_replyList[0]! as String,
123+
message: __pigeon_replyList[1] as String?,
124+
details: __pigeon_replyList[2],
122125
);
123-
} else if (replyList[0] == null) {
126+
} else if (__pigeon_replyList[0] == null) {
124127
throw PlatformException(
125128
code: 'null-error',
126129
message: 'Host platform returned null value for non-null return value.',
127130
);
128131
} else {
129-
return (replyList[0] as String?)!;
132+
return (__pigeon_replyList[0] as String?)!;
130133
}
131134
}
132135

133-
Future<int> add(int arg_a, int arg_b) async {
134-
const String channelName =
136+
Future<int> add(int a, int b) async {
137+
const String __pigeon_channelName =
135138
'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add';
136-
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
137-
channelName,
138-
codec,
139-
binaryMessenger: _binaryMessenger,
139+
final BasicMessageChannel<Object?> __pigeon_channel =
140+
BasicMessageChannel<Object?>(
141+
__pigeon_channelName,
142+
pigeonChannelCodec,
143+
binaryMessenger: __pigeon_binaryMessenger,
140144
);
141-
final List<Object?>? replyList =
142-
await channel.send(<Object?>[arg_a, arg_b]) as List<Object?>?;
143-
if (replyList == null) {
144-
throw _createConnectionError(channelName);
145-
} else if (replyList.length > 1) {
145+
final List<Object?>? __pigeon_replyList =
146+
await __pigeon_channel.send(<Object?>[a, b]) as List<Object?>?;
147+
if (__pigeon_replyList == null) {
148+
throw _createConnectionError(__pigeon_channelName);
149+
} else if (__pigeon_replyList.length > 1) {
146150
throw PlatformException(
147-
code: replyList[0]! as String,
148-
message: replyList[1] as String?,
149-
details: replyList[2],
151+
code: __pigeon_replyList[0]! as String,
152+
message: __pigeon_replyList[1] as String?,
153+
details: __pigeon_replyList[2],
150154
);
151-
} else if (replyList[0] == null) {
155+
} else if (__pigeon_replyList[0] == null) {
152156
throw PlatformException(
153157
code: 'null-error',
154158
message: 'Host platform returned null value for non-null return value.',
155159
);
156160
} else {
157-
return (replyList[0] as int?)!;
161+
return (__pigeon_replyList[0] as int?)!;
158162
}
159163
}
160164

161-
Future<bool> sendMessage(MessageData arg_message) async {
162-
const String channelName =
165+
Future<bool> sendMessage(MessageData message) async {
166+
const String __pigeon_channelName =
163167
'dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage';
164-
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
165-
channelName,
166-
codec,
167-
binaryMessenger: _binaryMessenger,
168+
final BasicMessageChannel<Object?> __pigeon_channel =
169+
BasicMessageChannel<Object?>(
170+
__pigeon_channelName,
171+
pigeonChannelCodec,
172+
binaryMessenger: __pigeon_binaryMessenger,
168173
);
169-
final List<Object?>? replyList =
170-
await channel.send(<Object?>[arg_message]) as List<Object?>?;
171-
if (replyList == null) {
172-
throw _createConnectionError(channelName);
173-
} else if (replyList.length > 1) {
174+
final List<Object?>? __pigeon_replyList =
175+
await __pigeon_channel.send(<Object?>[message]) as List<Object?>?;
176+
if (__pigeon_replyList == null) {
177+
throw _createConnectionError(__pigeon_channelName);
178+
} else if (__pigeon_replyList.length > 1) {
174179
throw PlatformException(
175-
code: replyList[0]! as String,
176-
message: replyList[1] as String?,
177-
details: replyList[2],
180+
code: __pigeon_replyList[0]! as String,
181+
message: __pigeon_replyList[1] as String?,
182+
details: __pigeon_replyList[2],
178183
);
179-
} else if (replyList[0] == null) {
184+
} else if (__pigeon_replyList[0] == null) {
180185
throw PlatformException(
181186
code: 'null-error',
182187
message: 'Host platform returned null value for non-null return value.',
183188
);
184189
} else {
185-
return (replyList[0] as bool?)!;
190+
return (__pigeon_replyList[0] as bool?)!;
186191
}
187192
}
188193
}
189194

190195
abstract class MessageFlutterApi {
191-
static const MessageCodec<Object?> codec = StandardMessageCodec();
196+
static const MessageCodec<Object?> pigeonChannelCodec =
197+
StandardMessageCodec();
192198

193199
String flutterMethod(String? aString);
194200

195201
static void setup(MessageFlutterApi? api,
196202
{BinaryMessenger? binaryMessenger}) {
197203
{
198-
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
204+
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<
205+
Object?>(
199206
'dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod',
200-
codec,
207+
pigeonChannelCodec,
201208
binaryMessenger: binaryMessenger);
202209
if (api == null) {
203-
channel.setMessageHandler(null);
210+
__pigeon_channel.setMessageHandler(null);
204211
} else {
205-
channel.setMessageHandler((Object? message) async {
212+
__pigeon_channel.setMessageHandler((Object? message) async {
206213
assert(message != null,
207214
'Argument for dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod was null.');
208215
final List<Object?> args = (message as List<Object?>?)!;

0 commit comments

Comments
 (0)