mirror of
https://github.com/flutter/packages.git
synced 2025-07-03 09:08:54 +08:00
[pigeon] Minor Obj-C simplification (#1980)
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
## NEXT
|
||||
## 3.0.4
|
||||
|
||||
* [objc] Simplified some code output, including avoiding Xcode warnings about
|
||||
using `NSNumber*` directly as boolean value.
|
||||
* [tests] Moved test script to enable CI.
|
||||
|
||||
## 3.0.3
|
||||
|
@ -8,7 +8,7 @@ import 'dart:mirrors';
|
||||
import 'ast.dart';
|
||||
|
||||
/// The current version of pigeon. This must match the version in pubspec.yaml.
|
||||
const String pigeonVersion = '3.0.3';
|
||||
const String pigeonVersion = '3.0.4';
|
||||
|
||||
/// Read all the content from [stdin] to a String.
|
||||
String readStdin() {
|
||||
|
@ -572,7 +572,7 @@ String _dictValue(
|
||||
} else if (enumNames.contains(field.type.baseName)) {
|
||||
return '@(self.${field.name})';
|
||||
} else {
|
||||
return '(self.${field.name} ? self.${field.name} : [NSNull null])';
|
||||
return '(self.${field.name} ?: [NSNull null])';
|
||||
}
|
||||
}
|
||||
|
||||
@ -761,8 +761,7 @@ void _writeFlutterApiSource(Indent indent, ObjcOptions options, Api api) {
|
||||
if (func.arguments.isEmpty) {
|
||||
sendArgument = 'nil';
|
||||
} else {
|
||||
String makeVarOrNSNullExpression(String x) =>
|
||||
'($x == nil) ? [NSNull null] : $x';
|
||||
String makeVarOrNSNullExpression(String x) => '$x ?: [NSNull null]';
|
||||
sendArgument = '@[${argNames.map(makeVarOrNSNullExpression).join(', ')}]';
|
||||
}
|
||||
indent.write(_makeObjcSignature(
|
||||
@ -838,13 +837,13 @@ static NSDictionary<NSString *, id> *wrapResult(id result, FlutterError *error)
|
||||
\tNSDictionary *errorDict = (NSDictionary *)[NSNull null];
|
||||
\tif (error) {
|
||||
\t\terrorDict = @{
|
||||
\t\t\t\t@"${Keys.errorCode}": (error.code ? error.code : [NSNull null]),
|
||||
\t\t\t\t@"${Keys.errorMessage}": (error.message ? error.message : [NSNull null]),
|
||||
\t\t\t\t@"${Keys.errorDetails}": (error.details ? error.details : [NSNull null]),
|
||||
\t\t\t\t@"${Keys.errorCode}": (error.code ?: [NSNull null]),
|
||||
\t\t\t\t@"${Keys.errorMessage}": (error.message ?: [NSNull null]),
|
||||
\t\t\t\t@"${Keys.errorDetails}": (error.details ?: [NSNull null]),
|
||||
\t\t\t\t};
|
||||
\t}
|
||||
\treturn @{
|
||||
\t\t\t@"${Keys.result}": (result ? result : [NSNull null]),
|
||||
\t\t\t@"${Keys.result}": (result ?: [NSNull null]),
|
||||
\t\t\t@"${Keys.error}": errorDict,
|
||||
\t\t\t};
|
||||
}''');
|
||||
@ -908,12 +907,13 @@ static id GetNullableObjectAtIndex(NSArray* array, NSInteger key) {
|
||||
void writeToMap() {
|
||||
indent.write('- (NSDictionary *)toMap ');
|
||||
indent.scoped('{', '}', () {
|
||||
indent.write('return [NSDictionary dictionaryWithObjectsAndKeys:');
|
||||
for (final NamedType field in klass.fields) {
|
||||
indent.add(_dictValue(classNames, enumNames, field) +
|
||||
', @"${field.name}", ');
|
||||
}
|
||||
indent.addln('nil];');
|
||||
indent.write('return');
|
||||
indent.scoped(' @{', '};', () {
|
||||
for (final NamedType field in klass.fields) {
|
||||
indent.writeln(
|
||||
'@"${field.name}" : ${_dictValue(classNames, enumNames, field)},');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ name: pigeon
|
||||
description: Code generator tool to make communication between Flutter and the host platform type-safe and easier.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/pigeon
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3Apigeon
|
||||
version: 3.0.3 # This must match the version in lib/generator_tools.dart
|
||||
version: 3.0.4 # This must match the version in lib/generator_tools.dart
|
||||
|
||||
environment:
|
||||
sdk: ">=2.12.0 <3.0.0"
|
||||
|
@ -1507,7 +1507,7 @@ void main() {
|
||||
expect(
|
||||
code,
|
||||
contains(
|
||||
'[channel sendMessage:@[(arg_x == nil) ? [NSNull null] : arg_x, (arg_y == nil) ? [NSNull null] : arg_y] reply:'));
|
||||
'[channel sendMessage:@[arg_x ?: [NSNull null], arg_y ?: [NSNull null]] reply:'));
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user