Repository navigation
[pigeon] Adds @SwiftClass annotation - #6372
Conversation
|
@LouiseHsu Do you also need the ability to add the |
Yes, that would be helpful! <3 |
For api classes and data classes? or just data classes? |
I think just data classes will be good for now :) |
|
Might be best to combine the two annotations (the inheritance being optional within the class one) |
Done. @stuartmorgan I'm hoping we can push this through in the morning, if you have time to review it. |
…s into swift-struct-to-class
hellohuanlin
left a comment
There was a problem hiding this comment.
I like the idea of using annotation, because it can get complicated to detect recursive definition and decide struct vs class for developers.
| String inheritNSObject = ''; | ||
| if (classDefinition.isSwiftObjcInteropClass) { | ||
| inheritNSObject = ': NSObject'; | ||
| indent.writeln('@objc'); |
There was a problem hiding this comment.
iirc @objc isn't necessary since it's already a subclass of NSObject, which is already exposed to objc runtime.
There was a problem hiding this comment.
Oh sorry i missed it in my previous review - in addition to the above, we probably need to add @objc for all custom members that are not inherited from NSObject (basically all the properties and the init function defined here).
Can you also write some ObjC tests to make sure it works? (requesting changes since this is not tested)
There was a problem hiding this comment.
all properties? even primitives? or only custom types?
There was a problem hiding this comment.
All properties and methods that are not inherited from NSObject need to be annotated, in order for them to be accessible by objc runtime. The class definition itself and its members inherited from NSObject are already implicitly annotated.
There was a problem hiding this comment.
So yes, even the properties of primitive types.
| String inheritNSObject = ''; | ||
| if (classDefinition.isSwiftObjcInteropClass) { | ||
| inheritNSObject = ': NSObject'; | ||
| indent.writeln('@objc'); |
There was a problem hiding this comment.
Oh sorry i missed it in my previous review - in addition to the above, we probably need to add @objc for all custom members that are not inherited from NSObject (basically all the properties and the init function defined here).
Can you also write some ObjC tests to make sure it works? (requesting changes since this is not tested)
stuartmorgan-g
left a comment
There was a problem hiding this comment.
LGTM once @hellohuanlin's concerns are addressed. (Marking now since I'll be OOO.)
|
@hellohuanlin I removed the @objc feature for now to unblock this pr. I'll throw up a new pr with just that in a short while. |
hellohuanlin
left a comment
There was a problem hiding this comment.
As discussed offline, feel free to land this first and create a separate PR for objc interop.
|
Landing to fix the tree |
flutter/packages@28d126c...ab1630b 2024-03-26 [email protected] [pigeon] Adds @SwiftClass annotation (flutter/packages#6372) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Adds annotation for @SwiftClass which will cause the swift generator to create a `class` instead of a `struct` in the generated Swift code. This will allow for recursive classes as well as allow for Objc interop, without forcing users to lose the potential benefits of structs if they prefer them instead. Also creates recursive data class integration test to check for coverage on all languages. fixes flutter/flutter#145175 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates [following repository CHANGELOG style]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests --------- Co-authored-by: Stuart Morgan <[email protected]>
Adds annotation for @SwiftClass which will cause the swift generator to create a `class` instead of a `struct` in the generated Swift code. This will allow for recursive classes as well as allow for Objc interop, without forcing users to lose the potential benefits of structs if they prefer them instead. Also creates recursive data class integration test to check for coverage on all languages. fixes flutter/flutter#145175 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [relevant style guides] and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use `dart format`.) - [x] I signed the [CLA]. - [x] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]` - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [x] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [pub versioning philosophy]: https://dart.dev/tools/pub/versioning [exempt from version changes]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#version-and-changelog-updates [following repository CHANGELOG style]: https://github.com/flutter/flutter/wiki/Contributing-to-Plugins-and-Packages#changelog-style [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests --------- Co-authored-by: Stuart Morgan <[email protected]>
Adds annotation for @SwiftClass which will cause the swift generator to create a
classinstead of astructin the generated Swift code.This will allow for recursive classes as well as allow for Objc interop, without forcing users to lose the potential benefits of structs if they prefer them instead.
Also creates recursive data class integration test to check for coverage on all languages.
fixes flutter/flutter#145175
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.