Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4337cd6
Add SwiftFunction annotation
ailtonvivaz Jul 3, 2022
d3eb40d
Bump version to 3.2.4
ailtonvivaz Jul 3, 2022
2920bbf
Remove unused imports
ailtonvivaz Jul 3, 2022
ac02d63
Improve methods map
ailtonvivaz Jul 5, 2022
f52ab0c
Remove unnecessary print
ailtonvivaz Jul 8, 2022
b5ec8ae
Force cast match of SwiftFunction
ailtonvivaz Jul 9, 2022
ac2b51b
Update packages/pigeon/lib/pigeon_lib.dart
ailtonvivaz Jul 27, 2022
f0bbf86
Merge branch 'main' into swift-function-annotation
ailtonvivaz Jul 27, 2022
5f70ea2
Improve documentation of function to parse method with SwiftFunction
ailtonvivaz Jul 27, 2022
718c1b3
Merge branch 'main' into swift-function-annotation
ailtonvivaz Aug 24, 2022
b034144
Merge branch 'main' into swift-function-annotation
ailtonvivaz Aug 25, 2022
519ff35
Merge branch 'main' into swift-function-annotation
ailtonvivaz Aug 27, 2022
9f86539
Fix some dartdocs
ailtonvivaz Aug 31, 2022
d754a58
Merge branch 'main' into swift-function-annotation
ailtonvivaz Sep 22, 2022
d8bf6d4
Merge branch 'swift-function-annotation' of github.com:ailtonvivaz/pa…
tarrinneal Jan 17, 2023
d4175a9
gen
tarrinneal Jan 17, 2023
09ebdea
analyze
tarrinneal Jan 17, 2023
6db9d1b
Improve SwiftFunction application
ailtonvivaz Jan 18, 2023
22af130
Merge branch 'main' into swift-function-annotation
ailtonvivaz Jan 18, 2023
399e4ae
Add type annotation
ailtonvivaz Jan 18, 2023
608b5ef
format
tarrinneal Jan 18, 2023
4bc40a3
Run format
ailtonvivaz Jan 18, 2023
a8c90f0
Update macos Swift tests
ailtonvivaz Jan 18, 2023
1bdde71
Bump version to 7.0.0
ailtonvivaz Jan 18, 2023
3da3698
Merge branch 'swift-function-annotation' of github.com:ailtonvivaz/pa…
tarrinneal Jan 18, 2023
b13b7ca
revert version change
tarrinneal Jan 18, 2023
ef9b5d0
Improve some code of SwiftGenerator
ailtonvivaz Jan 18, 2023
62b3163
Merge branch 'swift-function-annotation' of github.com:ailtonvivaz/pa…
ailtonvivaz Jan 18, 2023
a44aa18
Bump version to 6.1.0
ailtonvivaz Jan 18, 2023
5aa2197
Improve echo functions for Swift
ailtonvivaz Jan 18, 2023
9176579
Match order of parameters
ailtonvivaz Jan 18, 2023
372d7b7
Documents _SwiftFunctionComponents.fromMethod and _SwiftFunctionArgument
ailtonvivaz Jan 18, 2023
e734c28
Merge branch 'main' into swift-function-annotation
ailtonvivaz Jan 24, 2023
0039165
Improve doc comments
ailtonvivaz Jan 24, 2023
651f9fa
Fix tests
ailtonvivaz Jan 24, 2023
217e4f7
Merge branch 'main' of github.com:flutter/packages into swift-functio…
tarrinneal Jan 25, 2023
245a327
Fix SwiftFunction documentation
ailtonvivaz Jan 26, 2023
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
Prev Previous commit
Next Next commit
Improve some code of SwiftGenerator
  • Loading branch information
ailtonvivaz committed Jan 18, 2023
commit ef9b5d012c0ba232bda89a889889b02ba0dd525b
78 changes: 34 additions & 44 deletions packages/pigeon/lib/swift_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,8 @@ import FlutterMacOS
.map((NamedType e) => _nullsafeSwiftTypeForDartType(e.type));
final Iterable<String> argLabels = indexMap(components.arguments,
(int index, _SwiftFunctionArgument argument) {
final String? label = argument.label;
if (label == null) {
return _getArgumentName(index, argument.namedType);
} else {
return label;
}
return argument.label ??
_getArgumentName(index, argument.namedType);
});
final Iterable<String> argNames =
indexMap(func.arguments, _getSafeArgumentName);
Expand Down Expand Up @@ -395,11 +391,7 @@ import FlutterMacOS
final String? label = argument.label;
final String name = argument.name;
final String type = _nullsafeSwiftTypeForDartType(argument.type);
if (label != null) {
return '$label $name: $type';
} else {
return '$name: $type';
}
return '${label == null ? '' : '$label '}$name: $type';
}).toList();

final String returnType = method.returnType.isVoid
Expand Down Expand Up @@ -714,9 +706,9 @@ String _nullsafeSwiftTypeForDartType(TypeDeclaration type) {
class _SwiftFunctionArgument {
_SwiftFunctionArgument({
required this.name,
this.label,
required this.type,
required this.namedType,
this.label,
});

final String name;
Expand All @@ -739,43 +731,41 @@ class _SwiftFunctionComponents {
name: method.name,
returnType: method.returnType,
arguments: method.arguments
.map((NamedType e) => _SwiftFunctionArgument(
name: e.name,
type: e.type,
namedType: e,
.map((NamedType field) => _SwiftFunctionArgument(
name: field.name,
type: field.type,
namedType: field,
))
.toList(),
method: method,
);
} else {
final String argsCapturator =
repeat(r'(\w+):', method.arguments.length).join();
final RegExp signatureRegex =
RegExp(r'(\w+) *\(' + argsCapturator + r'\)');
final RegExpMatch match =
signatureRegex.firstMatch(method.swiftFunction)!;

final Iterable<String> customComponents = match
.groups(List<int>.generate(
method.arguments.length, (int index) => index + 2))
.whereType();

return _SwiftFunctionComponents._(
name: match.group(1)!,
returnType: method.returnType,
arguments: map2(
method.arguments,
customComponents,
(NamedType t, String u) => _SwiftFunctionArgument(
name: t.name,
label: u == t.name ? null : u,
type: t.type,
namedType: t,
),
).toList(),
method: method,
);
}

final String argsExtractor =
repeat(r'(\w+):', method.arguments.length).join();
final RegExp signatureRegex = RegExp(r'(\w+) *\(' + argsExtractor + r'\)');
final RegExpMatch match = signatureRegex.firstMatch(method.swiftFunction)!;

final Iterable<String> labels = match
.groups(List<int>.generate(
method.arguments.length, (int index) => index + 2))
.whereType();

return _SwiftFunctionComponents._(
name: match.group(1)!,
returnType: method.returnType,
arguments: map2(
method.arguments,
labels,
(NamedType field, String label) => _SwiftFunctionArgument(
name: field.name,
label: label == field.name ? null : label,
type: field.type,
namedType: field,
),
).toList(),
method: method,
);
}

final String name;
Expand Down