Skip to content
Open
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
21 changes: 13 additions & 8 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 26.4.0

* Overrides `toString` (or equivalent) methods on generated data classes.
* [swift] Updates `isNullish` to handle double nested `Any?` values.

## 26.3.4

* [kotlin] Updates generated error class to inherit from `RuntimeException`
Expand Down Expand Up @@ -915,7 +920,7 @@

## 3.0.3

* Adds ability for generators to do AST validation. This can help generators
* Adds ability for generators to do AST validation. This can help generators
without complete implementations to report gaps in coverage.

## 3.0.2
Expand Down Expand Up @@ -1078,11 +1083,11 @@
`dart:mirrors` doesn't support null-safe code so there were a class of
features we couldn't implement without this migration.
* **BREAKING CHANGE** - the `configurePigeon` function has been migrated to a
`@ConfigurePigeon` annotation. See `./pigeons/message.dart` for an example.
`@ConfigurePigeon` annotation. See `./pigeons/message.dart` for an example.
The annotation can be attached to anything in the file to take effect.
* **BREAKING CHANGE** - Now Pigeon files must be in one file per invocation of
Pigeon. For example, the classes your APIs use must be in the same file as
your APIs. If your Pigeon file imports another source file, it won't actually
Pigeon. For example, the classes your APIs use must be in the same file as
your APIs. If your Pigeon file imports another source file, it won't actually
import it.

## 0.2.4
Expand All @@ -1104,10 +1109,10 @@

## 0.2.0

* **BREAKING CHANGE** - Pigeon files must be null-safe now. That means the
* **BREAKING CHANGE** - Pigeon files must be null-safe now. That means the
fields inside of the classes must be declared nullable (
[non-null fields](https://github.com/flutter/flutter/issues/59118) aren't yet
supported). Migration example:
supported). Migration example:

```dart
// Version 0.1.x
Expand All @@ -1123,7 +1128,7 @@ class Foo {
}
```

* **BREAKING CHANGE** - The default output from Pigeon is now null-safe. If you
* **BREAKING CHANGE** - The default output from Pigeon is now null-safe. If you
want non-null-safe code you must provide the `--no-dart_null_safety` flag.
* The Pigeon source code is now null-safe.
* Fixed niladic non-value returning async functions in the Java generator.
Expand Down Expand Up @@ -1209,7 +1214,7 @@ class Foo {

## 0.1.8

* Started spawning pigeon_lib in an isolate instead of a subprocess. The
* Started spawning pigeon_lib in an isolate instead of a subprocess. The
subprocess could have lead to errors if the dart version on $PATH didn't match
the one that comes with flutter.

Expand Down
12 changes: 6 additions & 6 deletions packages/pigeon/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Description

Pigeon is a code generation tool that adds type safety to Flutter’s Platform
Channels. This document serves as an overview of how it functions to help
Channels. This document serves as an overview of how it functions to help
people who would like to contribute to the project.

## Source Index
Expand Down Expand Up @@ -32,15 +32,15 @@ Pigeon has 3 types of tests; you'll find them all in

* Unit tests - These are the fastest tests that are just typical unit tests,
they may be generating code and checking it against a regular expression to
see if it's correct. Example:
see if it's correct. Example:
[dart_generator_test.dart](./test/dart_generator_test.dart)
* Compilation tests - These tests generate code, then attempt to compile that
code. These are tests are much slower than unit tests, but not as slow as
integration tests. These tests are typically run against the Pigeon files in
code. These are tests are much slower than unit tests, but not as slow as
integration tests. These tests are typically run against the Pigeon files in
[pigeons](./pigeons).
* Integration tests - These tests generate code, then compile the generated
code, then execute the generated code. It can be thought of as unit-tests run
against the generated code. Examples: [platform_tests](./platform_tests)
code, then execute the generated code. It can be thought of as unit-tests run
against the generated code. Examples: [platform_tests](./platform_tests)

For local testing, always use `test.dart` rather than `run_tests.dart`, as
`run_tests.dart` is specifically a CI entrypoint. When iterating on a specific
Expand Down
4 changes: 2 additions & 2 deletions packages/pigeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ to the api to allow for multiple instances to be created and operate in parallel
1) Custom classes used by APIs are defined as classes with fields of the
supported datatypes (see the supported Datatypes section).
1) APIs should be defined as an `abstract class` with either `@HostApi()` or
`@FlutterApi()` as metadata. `@HostApi()` being for procedures that are defined
`@FlutterApi()` as metadata. `@HostApi()` being for procedures that are defined
on the host platform and the `@FlutterApi()` for procedures that are defined in Dart.
1) Method declarations on the API classes should have arguments and a return
value whose types are defined in the file, are supported datatypes, or are
Expand Down Expand Up @@ -150,7 +150,7 @@ to the api to allow for multiple instances to be created and operate in parallel
### Calling into Flutter from the host platform

Pigeon also supports calling in the opposite direction. The steps are similar
but reversed. For more information look at the annotation `@FlutterApi()` which
but reversed. For more information look at the annotation `@FlutterApi()` which
denotes APIs that live in Flutter but are invoked from the host platform.
[Example](./example/README.md#FlutterApi_Example).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ public int hashCode() {
return pigeonDeepHashCode(fields);
}

@Override
public String toString() {
return "MessageData{"
+ "name="
+ name
+ ", "
+ "description="
+ description
+ ", "
+ "code="
+ code
+ ", "
+ "data="
+ data
+ "}";
}

public static final class Builder {

private @Nullable String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ data class IntEvent(val data: Long) : PlatformEvent() {
result = 31 * result + EventChannelMessagesPigeonUtils.deepHash(this.data)
return result
}

override fun toString(): String {
return "IntEvent(data=$data)"
}
}

/** Generated class from Pigeon that represents data sent in messages. */
Expand Down Expand Up @@ -227,6 +231,10 @@ data class StringEvent(val data: String) : PlatformEvent() {
result = 31 * result + EventChannelMessagesPigeonUtils.deepHash(this.data)
return result
}

override fun toString(): String {
return "StringEvent(data=$data)"
}
}

private open class EventChannelMessagesPigeonCodec : StandardMessageCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ data class MessageData(
result = 31 * result + MessagesPigeonUtils.deepHash(this.data)
return result
}

override fun toString(): String {
return "MessageData(name=$name, description=$description, code=$code, data=$data)"
}
}

private open class MessagesPigeonCodec : StandardMessageCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ import Foundation
#error("Unsupported platform.")
#endif

private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
enum EventChannelMessagesPigeonInternal {
static func isNullish(_ value: Any?) -> Bool {
guard let innerValue = value else {
return true
}

if case Optional<Any>.some(Optional<Any>.none) = value {
return true
}

return innerValue is NSNull
}
}

private func nilOrValue<T>(_ value: Any?) -> T? {
Expand Down Expand Up @@ -166,6 +176,10 @@ struct IntEvent: PlatformEvent {
hasher.combine("IntEvent")
deepHashEventChannelMessages(value: data, hasher: &hasher)
}

public var description: String {
return "IntEvent(data: \(String(describing: data)))"
}
}

/// Generated class from Pigeon that represents data sent in messages.
Expand Down Expand Up @@ -196,6 +210,10 @@ struct StringEvent: PlatformEvent {
hasher.combine("StringEvent")
deepHashEventChannelMessages(value: data, hasher: &hasher)
}

public var description: String {
return "StringEvent(data: \(String(describing: data)))"
}
}

private class EventChannelMessagesPigeonCodecReader: FlutterStandardReader {
Expand Down
22 changes: 19 additions & 3 deletions packages/pigeon/example/app/ios/Runner/Messages.g.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ private func createConnectionError(withChannelName channelName: String) -> Pigeo
details: "")
}

private func isNullish(_ value: Any?) -> Bool {
return value is NSNull || value == nil
enum MessagesPigeonInternal {
static func isNullish(_ value: Any?) -> Bool {
guard let innerValue = value else {
return true
}

if case Optional<Any>.some(Optional<Any>.none) = value {
return true
}

return innerValue is NSNull
}
}

private func nilOrValue<T>(_ value: Any?) -> T? {
Expand Down Expand Up @@ -188,7 +198,7 @@ enum Code: Int {
}

/// Generated class from Pigeon that represents data sent in messages.
struct MessageData: Hashable {
struct MessageData: Hashable, CustomStringConvertible {
var name: String? = nil
var description: String? = nil
var code: Code
Expand Down Expand Up @@ -232,6 +242,11 @@ struct MessageData: Hashable {
deepHashMessages(value: code, hasher: &hasher)
deepHashMessages(value: data, hasher: &hasher)
}

public var description: String {
return
"MessageData(name: \(String(describing: name)), description: \(String(describing: description)), code: \(String(describing: code)), data: \(String(describing: data)))"
}
}

private class MessagesPigeonCodecReader: FlutterStandardReader {
Expand Down Expand Up @@ -349,6 +364,7 @@ class ExampleHostApiSetup {
}
}
}

/// Generated protocol from Pigeon that represents Flutter messages that can be called from Swift.
protocol MessageFlutterApiProtocol {
func flutterMethod(
Expand Down
10 changes: 10 additions & 0 deletions packages/pigeon/example/app/lib/src/event_channel_messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class IntEvent extends PlatformEvent {
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);

@override
String toString() {
return 'IntEvent(data: $data)';
}
}

class StringEvent extends PlatformEvent {
Expand Down Expand Up @@ -145,6 +150,11 @@ class StringEvent extends PlatformEvent {
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);

@override
String toString() {
return 'StringEvent(data: $data)';
}
}

class _PigeonCodec extends StandardMessageCodec {
Expand Down
9 changes: 7 additions & 2 deletions packages/pigeon/example/app/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class MessageData {
@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);

@override
String toString() {
return 'MessageData(name: $name, description: $description, code: $code, data: $data)';
}
}

class _PigeonCodec extends StandardMessageCodec {
Expand Down Expand Up @@ -203,8 +208,8 @@ class _PigeonCodec extends StandardMessageCodec {
}

class ExampleHostApi {
/// Constructor for [ExampleHostApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// Constructor for [ExampleHostApi]. The [binaryMessenger] named argument is
/// available for dependency injection. If it is left null, the default
/// BinaryMessenger will be used which routes to the host platform.
ExampleHostApi({
BinaryMessenger? binaryMessenger,
Expand Down
24 changes: 24 additions & 0 deletions packages/pigeon/example/app/linux/messages.g.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,30 @@ guint pigeon_example_package_message_data_hash(
return result;
}

gchar* pigeon_example_package_message_data_to_string(
PigeonExamplePackageMessageData* self) {
g_return_val_if_fail(PIGEON_EXAMPLE_PACKAGE_IS_MESSAGE_DATA(self), NULL);
GString* str = g_string_new("MessageData(");
g_string_append(str, "name: ");
if (self->name != nullptr) {
g_string_append_printf(str, "\"%s\"", self->name);
} else {
g_string_append(str, "null");
}
g_string_append(str, ", description: ");
if (self->description != nullptr) {
g_string_append_printf(str, "\"%s\"", self->description);
} else {
g_string_append(str, "null");
}
g_string_append(str, ", code: ");
g_string_append(str, "...");
g_string_append(str, ", data: ");
g_string_append(str, "...");
g_string_append(str, ")");
return g_string_free(str, FALSE);
}

struct _PigeonExamplePackageMessageCodec {
FlStandardMessageCodec parent_instance;
};
Expand Down
11 changes: 11 additions & 0 deletions packages/pigeon/example/app/linux/messages.g.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ gboolean pigeon_example_package_message_data_equals(
guint pigeon_example_package_message_data_hash(
PigeonExamplePackageMessageData* object);

/**
* pigeon_example_package_message_data_to_string:
* @object: a #PigeonExamplePackageMessageData.
*
* Returns a string representation of a #PigeonExamplePackageMessageData object.
*
* Returns: (transfer full): a new string, free with g_free().
*/
gchar* pigeon_example_package_message_data_to_string(
PigeonExamplePackageMessageData* object);

G_DECLARE_FINAL_TYPE(PigeonExamplePackageMessageCodec,
pigeon_example_package_message_codec,
PIGEON_EXAMPLE_PACKAGE, MESSAGE_CODEC,
Expand Down
5 changes: 5 additions & 0 deletions packages/pigeon/example/app/macos/Runner/messages.g.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ - (NSUInteger)hash {
result = result * 31 + FLTPigeonDeepHash(self.data);
return result;
}
- (NSString *)description {
return
[NSString stringWithFormat:@"PGNMessageData(name: %@, description: %@, code: %@, data: %@)",
self.name, self.description, @(self.code), self.data];
}
@end

@interface PGNMessagesPigeonCodecReader : FlutterStandardReader
Expand Down
Loading
Loading