Skip to content

Commit

Permalink
[pigeon] Migrates off old BinaryMessenger API (#3600)
Browse files Browse the repository at this point in the history
[pigeon] Migrates off old BinaryMessenger API
  • Loading branch information
goderbauer authored Apr 1, 2023
1 parent 6502403 commit c68fa09
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 35 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.1.4

* Migrates off deprecated `BinaryMessenger` API.

## 9.1.3

* [cpp] Requires passing any non-nullable fields of generated data classes as
Expand Down
14 changes: 10 additions & 4 deletions packages/pigeon/lib/dart_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ $resultAt != null

indent.write('abstract class ${api.name} ');
indent.addScoped('{', '}', () {
if (isMockHandler) {
indent.writeln(
'static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance;');
}
indent
.writeln('static const MessageCodec<Object?> codec = $codecName();');
indent.newln();
Expand Down Expand Up @@ -332,16 +336,18 @@ $resultAt != null
'binaryMessenger: binaryMessenger);',
);
});
final String messageHandlerSetter =
isMockHandler ? 'setMockMessageHandler' : 'setMessageHandler';
final String messageHandlerSetterWithOpeningParentheses = isMockHandler
? '_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, '
: 'channel.setMessageHandler(';
indent.write('if (api == null) ');
indent.addScoped('{', '}', () {
indent.writeln('channel.$messageHandlerSetter(null);');
indent.writeln(
'${messageHandlerSetterWithOpeningParentheses}null);');
}, addTrailingNewline: false);
indent.add(' else ');
indent.addScoped('{', '}', () {
indent.write(
'channel.$messageHandlerSetter((Object? message) async ',
'$messageHandlerSetterWithOpeningParentheses(Object? message) async ',
);
indent.addScoped('{', '});', () {
final String returnType =
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 @@ -11,7 +11,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '9.1.3';
const String pigeonVersion = '9.1.4';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/mock_handler_tester/test/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
27 changes: 20 additions & 7 deletions packages/pigeon/mock_handler_tester/test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
// ignore_for_file: avoid_relative_lib_imports
Expand Down Expand Up @@ -46,6 +46,8 @@ class _TestHostApiCodec extends StandardMessageCodec {
///
/// This comment also tests multiple line comments.
abstract class TestHostApi {
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
TestDefaultBinaryMessengerBinding.instance;
static const MessageCodec<Object?> codec = _TestHostApiCodec();

/// This comment is to test documentation comments.
Expand All @@ -62,9 +64,12 @@ abstract class TestHostApi {
'dev.flutter.pigeon.MessageApi.initialize', codec,
binaryMessenger: binaryMessenger);
if (api == null) {
channel.setMockMessageHandler(null);
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel, null);
} else {
channel.setMockMessageHandler((Object? message) async {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel,
(Object? message) async {
// ignore message
api.initialize();
return <Object?>[];
Expand All @@ -76,9 +81,12 @@ abstract class TestHostApi {
'dev.flutter.pigeon.MessageApi.search', codec,
binaryMessenger: binaryMessenger);
if (api == null) {
channel.setMockMessageHandler(null);
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel, null);
} else {
channel.setMockMessageHandler((Object? message) async {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel,
(Object? message) async {
assert(message != null,
'Argument for dev.flutter.pigeon.MessageApi.search was null.');
final List<Object?> args = (message as List<Object?>?)!;
Expand Down Expand Up @@ -129,6 +137,8 @@ class _TestNestedApiCodec extends StandardMessageCodec {

/// This comment is to test api documentation comments.
abstract class TestNestedApi {
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding =>
TestDefaultBinaryMessengerBinding.instance;
static const MessageCodec<Object?> codec = _TestNestedApiCodec();

/// This comment is to test method documentation comments.
Expand All @@ -142,9 +152,12 @@ abstract class TestNestedApi {
'dev.flutter.pigeon.MessageNestedApi.search', codec,
binaryMessenger: binaryMessenger);
if (api == null) {
channel.setMockMessageHandler(null);
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel, null);
} else {
channel.setMockMessageHandler((Object? message) async {
_testBinaryMessengerBinding!.defaultBinaryMessenger
.setMockDecodedMessageHandler<Object?>(channel,
(Object? message) async {
assert(message != null,
'Argument for dev.flutter.pigeon.MessageNestedApi.search was null.');
final List<Object?> args = (message as List<Object?>?)!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.alternate_language_test_plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#import "CoreTests.gen.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import 'test_util.dart';
NullableCollectionReturnFlutterApi,
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final TestWidgetsFlutterBinding binding =
TestWidgetsFlutterBinding.ensureInitialized();

test('with values filled', () {
final FlutterSearchReply reply = FlutterSearchReply()
Expand Down Expand Up @@ -134,7 +135,7 @@ void main() {
NullableArgFlutterApi.setup(mockFlutterApi);

final Completer<int> resultCompleter = Completer<int>();
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
binding.defaultBinaryMessenger.handlePlatformMessage(
'dev.flutter.pigeon.NullableArgFlutterApi.doit',
NullableArgFlutterApi.codec.encodeMessage(<Object?>[null]),
(ByteData? data) {
Expand All @@ -158,7 +159,7 @@ void main() {
NullableCollectionArgFlutterApi.setup(mockFlutterApi);

final Completer<List<String?>> resultCompleter = Completer<List<String?>>();
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
binding.defaultBinaryMessenger.handlePlatformMessage(
'dev.flutter.pigeon.NullableCollectionArgFlutterApi.doit',
NullableCollectionArgFlutterApi.codec.encodeMessage(<Object?>[null]),
(ByteData? data) {
Expand Down Expand Up @@ -210,7 +211,7 @@ void main() {
NullableReturnFlutterApi.setup(mockFlutterApi);

final Completer<int?> resultCompleter = Completer<int?>();
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
binding.defaultBinaryMessenger.handlePlatformMessage(
'dev.flutter.pigeon.NullableReturnFlutterApi.doit',
NullableReturnFlutterApi.codec.encodeMessage(<Object?>[]),
(ByteData? data) {
Expand All @@ -233,7 +234,7 @@ void main() {

final Completer<List<String?>?> resultCompleter =
Completer<List<String?>?>();
ServicesBinding.instance.defaultBinaryMessenger.handlePlatformMessage(
binding.defaultBinaryMessenger.handlePlatformMessage(
'dev.flutter.pigeon.NullableCollectionReturnFlutterApi.doit',
NullableCollectionReturnFlutterApi.codec.encodeMessage(<Object?>[]),
(ByteData? data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

package com.example.test_plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#undef _HAS_EXCEPTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Autogenerated from Pigeon (v9.1.3), do not edit directly.
// Autogenerated from Pigeon (v9.1.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon

#ifndef PIGEON_CORE_TESTS_GEN_H_
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pigeon
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
version: 9.1.3 # This must match the version in lib/generator_tools.dart
version: 9.1.4 # This must match the version in lib/generator_tools.dart

environment:
sdk: ">=2.18.0 <4.0.0"
Expand Down

0 comments on commit c68fa09

Please sign in to comment.