-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[swift2objc] Support properties that throw #1939
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
PR HealthBreaking changes ✔️
Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
License Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
|
@@ -73,11 +73,10 @@ bool _parseVariableThrows(Json json) { | |||
final throws = json['declarationFragments'] | |||
.any((frag) => matchFragment(frag, 'keyword', 'throws')); | |||
if (throws) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can delete this whole if statement and just return throws
.
@@ -106,3 +109,23 @@ InitializerDeclaration _buildWrapperInitializer( | |||
hasObjCAnnotation: wrappedClassInstance.hasObjCAnnotation, | |||
); | |||
} | |||
|
|||
List<MethodDeclaration> _convertPropertiesToMethods( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand correctly, you've added a isCallingProperty
field to the method and function declarations, which changes the originalCallStatementGenerator
param passed to _transformFunction
to not pass args. That transformation happens in transformMethod
, which is called immediately after you set this flag. In other words, you've added a flag to the AST node, that is only set here, and then is immediately consumed. The flag is only necessary because you're merging these methods with originalCompound.methods
before passing them to transformMethod
.
It would be cleaner to remove isCallingProperty
, and remove _convertPropertiesToMethods
, and do all that transformation logic in transformProperty
. transformProperty
would check the throws
flag and decide whether to return a PropertyDeclaration
or a MethodDeclaration
(the declared return type would be AstNode
). Then you would merge any MethodDeclaration
s it returned with the other methods after they've been transformed:
// transformedProperties is a List<AstNode?>
final transformedProperties = originalCompound.properties
.map((property) => transformProperty(
property,
wrappedCompoundInstance,
parentNamer,
transformationMap,
)).nonNulls.toList();
final transformedMethods = originalCompound.methods
.map((method) => transformMethod(
method,
wrappedCompoundInstance,
parentNamer,
transformationMap,
)).nonNulls.toList();
transformedCompound.properties =
transformedProperties.whereType<PropertyDeclaration>()
..sort((Declaration a, Declaration b) => a.id.compareTo(b.id));
transformedCompound.methods = (transformedMethods +
transformedProperties.whereType<MethodDeclaration>())
..sort((Declaration a, Declaration b) => a.id.compareTo(b.id));
The same goes for GlobalFunctionDeclaration
.
Closes #1765
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.