Skip to content
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 @@
## 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, '

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the ! here the _ambiguate equivalent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that plus typing the return type of the getter above as TestDefaultBinaryMessengerBinding? to hide the fact that TestDefaultBinaryMessengerBinding.instance may be non-nullable in certain versions of Flutter.

: '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 =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being written once per class instead of at the file level?

@goderbauer goderbauer Mar 31, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main motivation was to keep the generator script more readable by generating the _testBinaryMessengerBinding getter close to where it is used and to make sure that the public DartGenerator.writeFlutterApi always generates functioning code - no matter from what context it is called. If we want to generate this only once per file, we'd have to move the getter generation out of DartGenerator.writeFlutterApi (where it will later be used) into DartGenerator.generateTest - it's possible, but overall seems more error-prone and the generator script becomes harder to follow. However, if you prefer doing it only once per file I am happy to change this. Please let me know.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not as familiar with the test generator; that seems reasonable, so feel free to leave it.

(Long term we want to do more to have shared utilities created in a clear, structured way, but that work may not have even started for this generator.)

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