-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[pigeon] Adds SwiftFunction annotation #2304
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
Changes from 12 commits
4337cd6
d3eb40d
2920bbf
ac02d63
f52ab0c
b5ec8ae
ac2b51b
f0bbf86
5f70ea2
718c1b3
b034144
519ff35
9f86539
d754a58
d8bf6d4
d4175a9
09ebdea
6db9d1b
22af130
399e4ae
608b5ef
4bc40a3
a8c90f0
1bdde71
3da3698
b13b7ca
ef9b5d0
62b3163
a44aa18
5aa2197
9176579
372d7b7
e734c28
0039165
651f9fa
217e4f7
245a327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,44 @@ class SwiftOptions { | |
| /// Calculates the name of the codec that will be generated for [api]. | ||
| String _getCodecName(Api api) => '${api.name}Codec'; | ||
|
|
||
| /// Returns a new [Method] using the swift function signature from [func], | ||
| /// ie the name of function e the strings between the semicolons. | ||
ailtonvivaz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ailtonvivaz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// Example: | ||
ailtonvivaz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// _swiftMethod('@SwiftFunction('add(_:with:)') void add(int x, int y)') | ||
| /// will return 'void add(int _ x, int with y)' | ||
|
||
| /// which represents 'func add(_ x: Int32, with y: Int32) -> Void' in Swift. | ||
| Method _swiftMethod(Method func) { | ||
| if (func.swiftFunction.isEmpty) { | ||
| return func; | ||
| } else { | ||
| final String argsCapturator = | ||
| repeat(r'(\w+):', func.arguments.length).join(); | ||
| final RegExp signatureRegex = RegExp(r'(\w+) *\(' + argsCapturator + r'\)'); | ||
| final RegExpMatch match = signatureRegex.firstMatch(func.swiftFunction)!; | ||
|
|
||
| final Iterable<String> customComponents = match | ||
| .groups( | ||
| List<int>.generate(func.arguments.length, (int index) => index + 2)) | ||
| .whereType(); | ||
|
|
||
| return Method( | ||
| name: match.group(1)!, | ||
| returnType: func.returnType, | ||
| arguments: | ||
| map2(func.arguments, customComponents, (NamedType t, String u) { | ||
| if (u == t.name) { | ||
| return t; | ||
| } | ||
|
|
||
| return NamedType(name: '$u ${t.name}', type: t.type); | ||
| }).toList(), | ||
| isAsynchronous: func.isAsynchronous, | ||
| offset: func.offset, | ||
| taskQueueType: func.taskQueueType, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Writes the codec classwill be used for encoding messages for the [api]. | ||
| /// Example: | ||
| /// private class FooHostApiCodecReader: FlutterStandardReader {...} | ||
|
|
@@ -601,6 +639,9 @@ void generateSwift(SwiftOptions options, Root root, StringSink sink) { | |
| for (final Api api in root.apis) { | ||
| _writeCodec(indent, api, root); | ||
| indent.addln(''); | ||
|
|
||
| api.methods = api.methods.map(_swiftMethod).toList(); | ||
|
|
||
| writeApi(api, root); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.