diff --git a/packages/pigeon/CHANGELOG.md b/packages/pigeon/CHANGELOG.md index 9181db83d8..33ed27c0d8 100644 --- a/packages/pigeon/CHANGELOG.md +++ b/packages/pigeon/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.8 + +* [front-end] Started accepting explicit Object references in type arguments. +* [codecs] Fixed nuisance where duplicate entries could show up in custom codecs. + ## 1.0.7 * [front-end] Fixed bug where nested classes' type arguments aren't included in diff --git a/packages/pigeon/lib/ast.dart b/packages/pigeon/lib/ast.dart index 8ad4ccf36d..f4da0180a6 100644 --- a/packages/pigeon/lib/ast.dart +++ b/packages/pigeon/lib/ast.dart @@ -2,6 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:collection/collection.dart' show ListEquality; +import 'package:meta/meta.dart'; + +final Function _listEquals = const ListEquality().equals; + /// Enum that represents where an [Api] is located, on the host or Flutter. enum ApiLocation { /// The API is for calling functions defined on the host. @@ -79,16 +84,17 @@ class Api extends Node { } /// A specific instance of a type. +@immutable class TypeDeclaration { /// Constructor for [TypeDeclaration]. - TypeDeclaration({ + const TypeDeclaration({ required this.baseName, required this.isNullable, this.typeArguments = const [], }); /// Void constructor. - TypeDeclaration.voidDeclaration() + const TypeDeclaration.voidDeclaration() : baseName = 'void', isNullable = false, typeArguments = const []; @@ -105,6 +111,31 @@ class TypeDeclaration { /// True if the type is nullable. final bool isNullable; + @override + int get hashCode { + // This has to be implemented because TypeDeclaration is used as a Key to a + // Map in generator_tools.dart. + int hash = 17; + hash = hash * 37 + baseName.hashCode; + hash = hash * 37 + isNullable.hashCode; + for (final TypeDeclaration typeArgument in typeArguments) { + hash = hash * 37 + typeArgument.hashCode; + } + return hash; + } + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } else { + return other is TypeDeclaration && + baseName == other.baseName && + isNullable == other.isNullable && + _listEquals(typeArguments, other.typeArguments); + } + } + @override String toString() { return '(TypeDeclaration baseName:$baseName isNullable:$isNullable typeArguments:$typeArguments)'; diff --git a/packages/pigeon/lib/generator_tools.dart b/packages/pigeon/lib/generator_tools.dart index cb74607a96..8164d2457f 100644 --- a/packages/pigeon/lib/generator_tools.dart +++ b/packages/pigeon/lib/generator_tools.dart @@ -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 = '1.0.7'; +const String pigeonVersion = '1.0.8'; /// Read all the content from [stdin] to a String. String readStdin() { @@ -275,6 +275,7 @@ const List validTypes = [ 'Float64List', 'List', 'Map', + 'Object', ]; /// Custom codecs' custom types are enumerated from 255 down to this number to diff --git a/packages/pigeon/lib/objc_generator.dart b/packages/pigeon/lib/objc_generator.dart index 1d21c5e192..da9c4beca9 100644 --- a/packages/pigeon/lib/objc_generator.dart +++ b/packages/pigeon/lib/objc_generator.dart @@ -62,48 +62,58 @@ String _className(String? prefix, String className) { } } -String _callbackForType(TypeDeclaration type, String objcType) { +String _callbackForType(TypeDeclaration type, _ObjcPtr objcType) { return type.isVoid ? 'void(^)(NSError *_Nullable)' - : 'void(^)($objcType *, NSError *_Nullable)'; + : 'void(^)(${objcType.ptr.trim()}, NSError *_Nullable)'; } -const Map _objcTypeForDartTypeMap = { - 'bool': 'NSNumber', - 'int': 'NSNumber', - 'String': 'NSString', - 'double': 'NSNumber', - 'Uint8List': 'FlutterStandardTypedData', - 'Int32List': 'FlutterStandardTypedData', - 'Int64List': 'FlutterStandardTypedData', - 'Float64List': 'FlutterStandardTypedData', - 'List': 'NSArray', - 'Map': 'NSDictionary', +class _ObjcPtr { + const _ObjcPtr({required this.baseName}) : hasAsterisk = baseName != 'id'; + final String baseName; + final bool hasAsterisk; + String get ptr => '$baseName${hasAsterisk ? ' *' : ' '}'; +} + +const Map _objcTypeForDartTypeMap = { + 'bool': _ObjcPtr(baseName: 'NSNumber'), + 'int': _ObjcPtr(baseName: 'NSNumber'), + 'String': _ObjcPtr(baseName: 'NSString'), + 'double': _ObjcPtr(baseName: 'NSNumber'), + 'Uint8List': _ObjcPtr(baseName: 'FlutterStandardTypedData'), + 'Int32List': _ObjcPtr(baseName: 'FlutterStandardTypedData'), + 'Int64List': _ObjcPtr(baseName: 'FlutterStandardTypedData'), + 'Float64List': _ObjcPtr(baseName: 'FlutterStandardTypedData'), + 'List': _ObjcPtr(baseName: 'NSArray'), + 'Map': _ObjcPtr(baseName: 'NSDictionary'), + 'Object': _ObjcPtr(baseName: 'id'), }; String _flattenTypeArguments(String? classPrefix, List args) { final String result = args - .map( - (TypeDeclaration e) => '${_objcTypeForDartType(classPrefix, e)} *') + .map((TypeDeclaration e) => + _objcTypeForDartType(classPrefix, e).ptr.trim()) .join(', '); return result; } String? _objcTypePtrForPrimitiveDartType(String? classPrefix, NamedType field) { return _objcTypeForDartTypeMap.containsKey(field.type.baseName) - ? '${_objcTypeForDartType(classPrefix, field.type)} *' + ? _objcTypeForDartType(classPrefix, field.type).ptr : null; } /// Returns the objc type for a dart [type], prepending the [classPrefix] for /// generated classes. For example: /// _objcTypeForDartType(null, 'int') => 'NSNumber'. -String _objcTypeForDartType(String? classPrefix, TypeDeclaration field) { +_ObjcPtr _objcTypeForDartType(String? classPrefix, TypeDeclaration field) { return _objcTypeForDartTypeMap.containsKey(field.baseName) ? field.typeArguments.isEmpty ? _objcTypeForDartTypeMap[field.baseName]! - : '${_objcTypeForDartTypeMap[field.baseName]}<${_flattenTypeArguments(classPrefix, field.typeArguments)}>' - : _className(classPrefix, field.baseName); + : _ObjcPtr( + baseName: + '${_objcTypeForDartTypeMap[field.baseName]!.baseName}<${_flattenTypeArguments(classPrefix, field.typeArguments)}>') + : _ObjcPtr(baseName: _className(classPrefix, field.baseName)); } String _propertyTypeForDartType(NamedType field) { @@ -293,8 +303,8 @@ String _makeObjcSignature({ final Iterable argTypes = followedByOne( func.arguments.map((NamedType arg) { final String nullable = func.isAsynchronous ? 'nullable ' : ''; - final String argType = _objcTypeForDartType(options.prefix, arg.type); - return '$nullable$argType *'; + final _ObjcPtr argType = _objcTypeForDartType(options.prefix, arg.type); + return '$nullable${argType.ptr.trim()}'; }), lastArgType, ); @@ -313,7 +323,7 @@ void _writeHostApiDeclaration(Indent indent, Api api, ObjcOptions options) { final String apiName = _className(options.prefix, api.name); indent.writeln('@protocol $apiName'); for (final Method func in api.methods) { - final String returnTypeName = + final _ObjcPtr returnTypeName = _objcTypeForDartType(options.prefix, func.returnType); String? lastArgName; @@ -326,12 +336,13 @@ void _writeHostApiDeclaration(Indent indent, Api api, ObjcOptions options) { lastArgName = 'completion'; } else { lastArgType = - 'void(^)($returnTypeName *_Nullable, FlutterError *_Nullable)'; + 'void(^)(${returnTypeName.ptr}_Nullable, FlutterError *_Nullable)'; lastArgName = 'completion'; } } else { - returnType = - func.returnType.isVoid ? 'void' : 'nullable $returnTypeName *'; + returnType = func.returnType.isVoid + ? 'void' + : 'nullable ${returnTypeName.ptr.trim()}'; lastArgType = 'FlutterError *_Nullable *_Nonnull'; lastArgName = 'error'; } @@ -356,7 +367,7 @@ void _writeFlutterApiDeclaration(Indent indent, Api api, ObjcOptions options) { indent.writeln( '- (instancetype)initWithBinaryMessenger:(id)binaryMessenger;'); for (final Method func in api.methods) { - final String returnType = + final _ObjcPtr returnType = _objcTypeForDartType(options.prefix, func.returnType); final String callbackType = _callbackForType(func.returnType, returnType); indent.writeln(_makeObjcSignature( @@ -492,7 +503,7 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) { indent.write( '[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) '); indent.scoped('{', '}];', () { - final String returnType = + final _ObjcPtr returnType = _objcTypeForDartType(options.prefix, func.returnType); String syncCall; String? callSignature; @@ -506,9 +517,9 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) { indexMap(func.arguments, _getSafeArgName); map3(wholeNumbers.take(func.arguments.length), argNames, func.arguments, (int count, String argName, NamedType arg) { - final String argType = + final _ObjcPtr argType = _objcTypeForDartType(options.prefix, arg.type); - return '$argType *$argName = args[$count];'; + return '${argType.ptr}$argName = args[$count];'; }).forEach(indent.writeln); callSignature = map2(selectorComponents.take(argNames.length), argNames, @@ -537,13 +548,13 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) { const String callback = 'callback(wrapResult(output, error));'; if (func.arguments.isEmpty) { indent.writeScoped( - '[api ${selectorComponents.first}:^($returnType *_Nullable output, FlutterError *_Nullable error) {', + '[api ${selectorComponents.first}:^(${returnType.ptr}_Nullable output, FlutterError *_Nullable error) {', '}];', () { indent.writeln(callback); }); } else { indent.writeScoped( - '[api $callSignature ${selectorComponents.last}:^($returnType *_Nullable output, FlutterError *_Nullable error) {', + '[api $callSignature ${selectorComponents.last}:^(${returnType.ptr}_Nullable output, FlutterError *_Nullable error) {', '}];', () { indent.writeln(callback); }); @@ -555,7 +566,7 @@ void _writeHostApiSource(Indent indent, ObjcOptions options, Api api) { indent.writeln('$syncCall;'); indent.writeln('callback(wrapResult(nil, error));'); } else { - indent.writeln('$returnType *output = $syncCall;'); + indent.writeln('${returnType.ptr}output = $syncCall;'); indent.writeln('callback(wrapResult(output, error));'); } } @@ -591,7 +602,7 @@ void _writeFlutterApiSource(Indent indent, ObjcOptions options, Api api) { }); indent.addln(''); for (final Method func in api.methods) { - final String returnType = + final _ObjcPtr returnType = _objcTypeForDartType(options.prefix, func.returnType); final String callbackType = _callbackForType(func.returnType, returnType); @@ -627,7 +638,7 @@ void _writeFlutterApiSource(Indent indent, ObjcOptions options, Api api) { if (func.returnType.isVoid) { indent.writeln('completion(nil);'); } else { - indent.writeln('$returnType *output = reply;'); + indent.writeln('${returnType.ptr}output = reply;'); indent.writeln('completion(output, nil);'); } }); diff --git a/packages/pigeon/lib/pigeon_lib.dart b/packages/pigeon/lib/pigeon_lib.dart index 3c29fc7d99..439f5cd824 100644 --- a/packages/pigeon/lib/pigeon_lib.dart +++ b/packages/pigeon/lib/pigeon_lib.dart @@ -565,6 +565,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { !validTypes.contains(element.key.baseName) && !element.key.isVoid && element.key.baseName != 'dynamic' && + element.key.baseName != 'Object' && element.key.baseName.isNotEmpty) { final int? lineNumber = element.value.isEmpty ? null @@ -709,7 +710,7 @@ class _RootBuilder extends dart_ast_visitor.RecursiveAstVisitor { } else { return NamedType( name: '', - type: TypeDeclaration(baseName: '', isNullable: false), + type: const TypeDeclaration(baseName: '', isNullable: false), offset: parameter.offset, ); } diff --git a/packages/pigeon/pigeons/all_datatypes.dart b/packages/pigeon/pigeons/all_datatypes.dart index 138b4caf62..8a260d25c6 100644 --- a/packages/pigeon/pigeons/all_datatypes.dart +++ b/packages/pigeon/pigeons/all_datatypes.dart @@ -19,6 +19,7 @@ class Everything { Map? aMap; List?>? nestedList; Map? mapWithAnnotations; + Map? mapWithObject; } @HostApi() diff --git a/packages/pigeon/platform_tests/android_unit_tests/android/app/src/test/java/com/example/android_unit_tests/AllDatatypesTest.java b/packages/pigeon/platform_tests/android_unit_tests/android/app/src/test/java/com/example/android_unit_tests/AllDatatypesTest.java index b6a8cf1675..6cef5dd509 100644 --- a/packages/pigeon/platform_tests/android_unit_tests/android/app/src/test/java/com/example/android_unit_tests/AllDatatypesTest.java +++ b/packages/pigeon/platform_tests/android_unit_tests/android/app/src/test/java/com/example/android_unit_tests/AllDatatypesTest.java @@ -51,6 +51,7 @@ public class AllDatatypesTest { assertNull(everything.getAFloatArray()); assertNull(everything.getAList()); assertNull(everything.getAMap()); + assertNull(everything.getMapWithObject()); }); assertTrue(didCall[0]); } @@ -61,6 +62,12 @@ public class AllDatatypesTest { return result; } + private static HashMap makeStringMap(String key, Integer value) { + HashMap result = new HashMap(); + result.put(key, value); + return result; + } + private static boolean floatArraysEqual(double[] x, double[] y) { if (x.length != y.length) { return false; @@ -86,6 +93,7 @@ public class AllDatatypesTest { everything.setAFloatArray(new double[] {0.5, 0.25, 1.5, 1.25}); everything.setAList(Arrays.asList(new int[] {1, 2, 3})); everything.setAMap(makeMap("hello", 1234)); + everything.setMapWithObject(makeStringMap("hello", 1234)); BinaryMessenger binaryMessenger = mock(BinaryMessenger.class); doAnswer( invocation -> { @@ -120,6 +128,9 @@ public class AllDatatypesTest { everything.getAMap().keySet().toArray(), result.getAMap().keySet().toArray()); assertArrayEquals( everything.getAMap().values().toArray(), result.getAMap().values().toArray()); + assertArrayEquals( + everything.getMapWithObject().values().toArray(), + result.getMapWithObject().values().toArray()); }); assertTrue(didCall[0]); } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart index 4c983f31eb..06ba8f5b19 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/lib/all_datatypes.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // -// Autogenerated from Pigeon (v0.3.0), do not edit directly. +// Autogenerated from Pigeon (v1.0.8), do not edit directly. // See also: https://pub.dev/packages/pigeon // ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name // @dart = 2.12 @@ -25,6 +25,7 @@ class Everything { Map? aMap; List?>? nestedList; Map? mapWithAnnotations; + Map? mapWithObject; Object encode() { final Map pigeonMap = {}; @@ -40,6 +41,7 @@ class Everything { pigeonMap['aMap'] = aMap; pigeonMap['nestedList'] = nestedList; pigeonMap['mapWithAnnotations'] = mapWithAnnotations; + pigeonMap['mapWithObject'] = mapWithObject; return pigeonMap; } @@ -60,7 +62,9 @@ class Everything { (pigeonMap['nestedList'] as List?)?.cast?>() ..mapWithAnnotations = (pigeonMap['mapWithAnnotations'] as Map?) - ?.cast(); + ?.cast() + ..mapWithObject = (pigeonMap['mapWithObject'] as Map?) + ?.cast(); } } diff --git a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/all_datatypes_test.dart b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/all_datatypes_test.dart index 78accde898..6d82d91405 100644 --- a/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/all_datatypes_test.dart +++ b/packages/pigeon/platform_tests/flutter_null_safe_unit_tests/test/all_datatypes_test.dart @@ -35,6 +35,7 @@ void main() { expect(result.aMap, isNull); expect(result.nestedList, isNull); expect(result.mapWithAnnotations, isNull); + expect(result.mapWithObject, isNull); }); test('with values', () async { @@ -54,6 +55,7 @@ void main() { [true] ]; everything.mapWithAnnotations = {'hello': 'world'}; + everything.mapWithObject = {'hello': 1234}; final BinaryMessenger mockMessenger = MockBinaryMessenger(); echoOneArgument( mockMessenger, @@ -74,5 +76,6 @@ void main() { expect(result.aMap, everything.aMap); expect(result.aList, everything.aList); expect(result.mapWithAnnotations, everything.mapWithAnnotations); + expect(result.mapWithObject, everything.mapWithObject); }); } diff --git a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index 97e0ecb021..20fcf69030 100644 --- a/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/pigeon/platform_tests/ios_unit_tests/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =2.12.0 <3.0.0' @@ -10,6 +10,8 @@ environment: dependencies: analyzer: ^2.4.0 args: ^2.0.0 + collection: ^1.15.0 + meta: ^1.7.0 path: ^1.8.0 dev_dependencies: diff --git a/packages/pigeon/run_tests.sh b/packages/pigeon/run_tests.sh index 660055ad61..aaa73dd2ee 100755 --- a/packages/pigeon/run_tests.sh +++ b/packages/pigeon/run_tests.sh @@ -234,8 +234,8 @@ run_mock_handler_tests() { --input pigeons/message.dart \ --dart_out mock_handler_tester/test/message.dart \ --dart_test_out mock_handler_tester/test/test.dart - dartfmt -w mock_handler_tester/test/message.dart - dartfmt -w mock_handler_tester/test/test.dart + dart format mock_handler_tester/test/message.dart + dart format mock_handler_tester/test/test.dart cd mock_handler_tester flutter test popd @@ -299,7 +299,7 @@ run_ios_e2e_tests() { --objc_header_out $DARTLE_H \ --objc_source_out $DARTLE_M \ --java_out $PIGEON_JAVA - dartfmt -w $DARTLE_DART + dart format $DARTLE_DART pushd $PWD cd e2e_tests/test_objc diff --git a/packages/pigeon/test/dart_generator_test.dart b/packages/pigeon/test/dart_generator_test.dart index 02aa5ad03b..92b73f8a21 100644 --- a/packages/pigeon/test/dart_generator_test.dart +++ b/packages/pigeon/test/dart_generator_test.dart @@ -13,7 +13,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'dataType1', isNullable: true, ), @@ -61,21 +61,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'input', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -84,7 +85,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -107,12 +108,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) @@ -133,12 +136,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) @@ -161,7 +166,7 @@ void main() { name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -173,7 +178,7 @@ void main() { name: 'Nested', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: true, ), @@ -206,21 +211,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'input', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -229,7 +235,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -252,21 +258,21 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -288,21 +294,21 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -326,14 +332,15 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -355,21 +362,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'EnumClass', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'EnumClass', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'EnumClass', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'EnumClass', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Enum', isNullable: true, ), @@ -401,21 +409,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'EnumClass', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'EnumClass', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'EnumClass', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'EnumClass', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Enum', isNullable: true, ), @@ -448,14 +457,15 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -480,7 +490,7 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), @@ -488,28 +498,28 @@ void main() { offset: null) ], returnType: - TypeDeclaration(baseName: 'Output', isNullable: false), + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ), Method( name: 'voidReturner', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -518,7 +528,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -552,7 +562,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'dataType1', isNullable: true, ), @@ -578,21 +588,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -601,7 +612,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -625,21 +636,21 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -648,7 +659,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -671,21 +682,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -694,7 +706,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -715,14 +727,15 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -758,7 +771,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: true, typeArguments: [ @@ -785,7 +798,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Map', isNullable: true, typeArguments: [ @@ -814,10 +827,10 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -843,10 +856,10 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -872,7 +885,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -900,7 +913,7 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -908,7 +921,7 @@ void main() { ]), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ diff --git a/packages/pigeon/test/generator_tools_test.dart b/packages/pigeon/test/generator_tools_test.dart index 6daaf0cb74..b50dea6bf2 100644 --- a/packages/pigeon/test/generator_tools_test.dart +++ b/packages/pigeon/test/generator_tools_test.dart @@ -72,7 +72,7 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -83,7 +83,8 @@ void main() { offset: null, ) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]); @@ -110,12 +111,12 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration(baseName: 'Output', isNullable: false), + type: const TypeDeclaration(baseName: 'Output', isNullable: false), name: '', offset: null, ) ], - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -148,17 +149,17 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration(baseName: 'Foo', isNullable: false), + type: const TypeDeclaration(baseName: 'Foo', isNullable: false), name: '', offset: null, ), NamedType( - type: TypeDeclaration(baseName: 'Bar', isNullable: false), + type: const TypeDeclaration(baseName: 'Bar', isNullable: false), name: '', offset: null, ), ], - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [TypeDeclaration.voidDeclaration()], @@ -190,14 +191,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration( + type: const TypeDeclaration( isNullable: false, baseName: 'List', typeArguments: [ TypeDeclaration(baseName: 'Foo', isNullable: true) ])), ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) @@ -205,12 +206,12 @@ void main() { Class(name: 'Foo', fields: [ NamedType( name: 'bar', - type: TypeDeclaration(baseName: 'Bar', isNullable: true)), + type: const TypeDeclaration(baseName: 'Bar', isNullable: true)), ]), Class(name: 'Bar', fields: [ NamedType( name: 'value', - type: TypeDeclaration(baseName: 'int', isNullable: true)) + type: const TypeDeclaration(baseName: 'int', isNullable: true)) ]) ], enums: []); final List classes = @@ -227,4 +228,57 @@ void main() { .length, 1); }); + + test('getCodecClasses: unique entries', () { + final Root root = Root(apis: [ + Api( + name: 'Api1', + location: ApiLocation.flutter, + methods: [ + Method( + name: 'foo', + arguments: [ + NamedType( + name: 'x', + type: const TypeDeclaration( + isNullable: false, baseName: 'Foo')), + ], + returnType: const TypeDeclaration.voidDeclaration(), + isAsynchronous: false, + ) + ], + ), + Api( + name: 'Api2', + location: ApiLocation.host, + methods: [ + Method( + name: 'foo', + arguments: [ + NamedType( + name: 'x', + type: const TypeDeclaration( + isNullable: false, baseName: 'Foo')), + ], + returnType: const TypeDeclaration.voidDeclaration(), + isAsynchronous: false, + ) + ], + ) + ], classes: [ + Class(name: 'Foo', fields: [ + NamedType( + name: 'bar', + type: const TypeDeclaration(baseName: 'int', isNullable: true)), + ]), + ], enums: []); + final List classes = + getCodecClasses(root.apis[0], root).toList(); + expect(classes.length, 1); + expect( + classes + .where((EnumeratedClass element) => element.name == 'Foo') + .length, + 1); + }); } diff --git a/packages/pigeon/test/java_generator_test.dart b/packages/pigeon/test/java_generator_test.dart index 835725a1c8..461a806df7 100644 --- a/packages/pigeon/test/java_generator_test.dart +++ b/packages/pigeon/test/java_generator_test.dart @@ -12,7 +12,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'int', isNullable: true, ), @@ -64,7 +64,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'int', isNullable: true, ), @@ -93,21 +93,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -116,7 +117,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -137,56 +138,56 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'bool', isNullable: true, ), name: 'aBool', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'int', isNullable: true, ), name: 'aInt', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'double', isNullable: true, ), name: 'aDouble', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), name: 'aString', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Uint8List', isNullable: true, ), name: 'aUint8List', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Int32List', isNullable: true, ), name: 'aInt32List', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Int64List', isNullable: true, ), name: 'aInt64List', offset: null), NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Float64List', isNullable: true, ), @@ -216,21 +217,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -239,7 +241,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -262,21 +264,21 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -299,21 +301,21 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -335,14 +337,15 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -364,14 +367,15 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: false, ) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -391,7 +395,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: true, ), @@ -411,7 +415,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Map', isNullable: true, ), @@ -432,7 +436,7 @@ void main() { name: 'Outer', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Nested', isNullable: true, ), @@ -444,7 +448,7 @@ void main() { name: 'Nested', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'int', isNullable: true, ), @@ -477,21 +481,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'arg', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -500,7 +505,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -528,21 +533,22 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true, ) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -551,7 +557,7 @@ void main() { ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'String', isNullable: true, ), @@ -579,7 +585,7 @@ void main() { name: 'EnumClass', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Enum1', isNullable: true, ), @@ -628,7 +634,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: true, typeArguments: [ @@ -656,7 +662,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Map', isNullable: true, typeArguments: [ @@ -686,10 +692,10 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -716,10 +722,10 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -746,7 +752,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -772,7 +778,7 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -800,12 +806,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) @@ -832,12 +840,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) diff --git a/packages/pigeon/test/objc_generator_test.dart b/packages/pigeon/test/objc_generator_test.dart index 241ba810f0..d1ddbc3bea 100644 --- a/packages/pigeon/test/objc_generator_test.dart +++ b/packages/pigeon/test/objc_generator_test.dart @@ -11,7 +11,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null) ]), @@ -27,7 +27,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null) ]), @@ -83,11 +83,13 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: + const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Enum1', isNullable: true), + type: + const TypeDeclaration(baseName: 'Enum1', isNullable: true), name: 'enum1', offset: null), ], @@ -119,11 +121,13 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: + const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Enum1', isNullable: true), + type: + const TypeDeclaration(baseName: 'Enum1', isNullable: true), name: 'enum1', offset: null), ], @@ -152,22 +156,24 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration(baseName: 'Input', isNullable: false), + type: const TypeDeclaration( + baseName: 'Input', isNullable: false), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]) @@ -189,25 +195,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]) @@ -229,35 +236,39 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'bool', isNullable: true), + type: const TypeDeclaration(baseName: 'bool', isNullable: true), name: 'aBool', offset: null), NamedType( - type: TypeDeclaration(baseName: 'int', isNullable: true), + type: const TypeDeclaration(baseName: 'int', isNullable: true), name: 'aInt', offset: null), NamedType( - type: TypeDeclaration(baseName: 'double', isNullable: true), + type: const TypeDeclaration(baseName: 'double', isNullable: true), name: 'aDouble', offset: null), NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'aString', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Uint8List', isNullable: true), + type: + const TypeDeclaration(baseName: 'Uint8List', isNullable: true), name: 'aUint8List', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Int32List', isNullable: true), + type: + const TypeDeclaration(baseName: 'Int32List', isNullable: true), name: 'aInt32List', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Int64List', isNullable: true), + type: + const TypeDeclaration(baseName: 'Int64List', isNullable: true), name: 'aInt64List', offset: null), NamedType( - type: TypeDeclaration(baseName: 'Float64List', isNullable: true), + type: const TypeDeclaration( + baseName: 'Float64List', isNullable: true), name: 'aFloat64List', offset: null), ]), @@ -286,7 +297,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'bool', isNullable: true), + type: const TypeDeclaration(baseName: 'bool', isNullable: true), name: 'aBool', offset: null), ]), @@ -303,13 +314,13 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Nested', fields: [ NamedType( - type: TypeDeclaration(baseName: 'Input', isNullable: true), + type: const TypeDeclaration(baseName: 'Input', isNullable: true), name: 'nested', offset: null) ]) @@ -325,13 +336,13 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Nested', fields: [ NamedType( - type: TypeDeclaration(baseName: 'Input', isNullable: true), + type: const TypeDeclaration(baseName: 'Input', isNullable: true), name: 'nested', offset: null) ]) @@ -347,7 +358,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null) ]), @@ -362,7 +373,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'field1', offset: null) ]), @@ -380,25 +391,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Nested', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Nested', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Nested', fields: [ NamedType( - type: TypeDeclaration(baseName: 'Input', isNullable: true), + type: const TypeDeclaration(baseName: 'Input', isNullable: true), name: 'nested', offset: null) ]) @@ -418,25 +430,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Nested', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Nested', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Nested', fields: [ NamedType( - type: TypeDeclaration(baseName: 'Input', isNullable: true), + type: const TypeDeclaration(baseName: 'Input', isNullable: true), name: 'nested', offset: null) ]) @@ -456,25 +469,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]) @@ -497,25 +511,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]) @@ -534,19 +549,19 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration()) + returnType: const TypeDeclaration.voidDeclaration()) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), @@ -565,19 +580,19 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration()) + returnType: const TypeDeclaration.voidDeclaration()) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), @@ -598,19 +613,19 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration()) + returnType: const TypeDeclaration.voidDeclaration()) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), @@ -629,19 +644,19 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration.voidDeclaration()) + returnType: const TypeDeclaration.voidDeclaration()) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), @@ -660,12 +675,13 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -683,12 +699,13 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -706,12 +723,13 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -732,12 +750,13 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false)) + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false)) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -757,7 +776,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'List', isNullable: true), + type: const TypeDeclaration(baseName: 'List', isNullable: true), name: 'field1', offset: null) ]), @@ -773,7 +792,7 @@ void main() { final Root root = Root(apis: [], classes: [ Class(name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration(baseName: 'Map', isNullable: true), + type: const TypeDeclaration(baseName: 'Map', isNullable: true), name: 'field1', offset: null) ]), @@ -785,6 +804,56 @@ void main() { expect(code, matches('@property.*NSDictionary.*field1')); }); + test('gen map field with object', () { + final Root root = Root(apis: [], classes: [ + Class(name: 'Foobar', fields: [ + NamedType( + type: const TypeDeclaration( + baseName: 'Map', + isNullable: true, + typeArguments: [ + TypeDeclaration(baseName: 'String', isNullable: true), + TypeDeclaration(baseName: 'Object', isNullable: true), + ]), + name: 'field1', + offset: null) + ]), + ], enums: []); + final StringBuffer sink = StringBuffer(); + generateObjcHeader(const ObjcOptions(), root, sink); + final String code = sink.toString(); + expect(code, contains('@interface Foobar')); + expect( + code, + contains( + '@property(nonatomic, strong, nullable) NSDictionary *')); + }); + + test('gen map argument with object', () { + final Root root = Root(apis: [ + Api(name: 'Api', location: ApiLocation.host, methods: [ + Method( + name: 'doit', + returnType: const TypeDeclaration.voidDeclaration(), + arguments: [ + NamedType( + name: 'foo', + type: const TypeDeclaration( + baseName: 'Map', + isNullable: true, + typeArguments: [ + TypeDeclaration(baseName: 'String', isNullable: true), + TypeDeclaration(baseName: 'Object', isNullable: true), + ])) + ]), + ]) + ], classes: [], enums: []); + final StringBuffer sink = StringBuffer(); + generateObjcHeader(const ObjcOptions(), root, sink); + final String code = sink.toString(); + expect(code, contains('(NSDictionary *)foo')); + }); + test('async void(input) HostApi header', () { final Root root = Root(apis: [ Api(name: 'Api', location: ApiLocation.host, methods: [ @@ -792,26 +861,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'input', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -833,26 +902,27 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'input', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -873,13 +943,14 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -900,7 +971,7 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) ], classes: [], enums: []); @@ -921,26 +992,27 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: '', offset: null) ], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -962,26 +1034,26 @@ void main() { name: 'doSomething', arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'Input', isNullable: false, ), name: 'foo', offset: null) ], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) ], classes: [ Class(name: 'Input', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'input', offset: null) ]), Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -1002,7 +1074,7 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), isAsynchronous: true) ]) ], classes: [], enums: []); @@ -1022,13 +1094,14 @@ void main() { Method( name: 'doSomething', arguments: [], - returnType: TypeDeclaration(baseName: 'Output', isNullable: false), + returnType: + const TypeDeclaration(baseName: 'Output', isNullable: false), isAsynchronous: true) ]) ], classes: [ Class(name: 'Output', fields: [ NamedType( - type: TypeDeclaration(baseName: 'String', isNullable: true), + type: const TypeDeclaration(baseName: 'String', isNullable: true), name: 'output', offset: null) ]), @@ -1082,7 +1155,7 @@ void main() { name: 'Foobar', fields: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: true, typeArguments: [ @@ -1110,10 +1183,10 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -1149,10 +1222,10 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -1188,10 +1261,10 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration.voidDeclaration(), + returnType: const TypeDeclaration.voidDeclaration(), arguments: [ NamedType( - type: TypeDeclaration( + type: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -1226,7 +1299,7 @@ void main() { Api(name: 'Api', location: ApiLocation.host, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -1261,7 +1334,7 @@ void main() { Api(name: 'Api', location: ApiLocation.flutter, methods: [ Method( name: 'doit', - returnType: TypeDeclaration( + returnType: const TypeDeclaration( baseName: 'List', isNullable: false, typeArguments: [ @@ -1299,12 +1372,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) @@ -1340,12 +1415,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: true, ) ]) @@ -1380,12 +1457,14 @@ void main() { arguments: [ NamedType( name: 'x', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), NamedType( name: 'y', - type: TypeDeclaration(isNullable: false, baseName: 'int')), + type: + const TypeDeclaration(isNullable: false, baseName: 'int')), ], - returnType: TypeDeclaration(baseName: 'int', isNullable: false), + returnType: const TypeDeclaration(baseName: 'int', isNullable: false), isAsynchronous: false, ) ]) @@ -1421,16 +1500,18 @@ void main() { objcSelector: 'divideValue:by:', arguments: [ NamedType( - type: TypeDeclaration(baseName: 'int', isNullable: false), + type: const TypeDeclaration( + baseName: 'int', isNullable: false), name: 'x', ), NamedType( - type: TypeDeclaration(baseName: 'int', isNullable: false), + type: const TypeDeclaration( + baseName: 'int', isNullable: false), name: 'y', ), ], - returnType: - TypeDeclaration(baseName: 'double', isNullable: false)) + returnType: const TypeDeclaration( + baseName: 'double', isNullable: false)) ]) ], classes: [], diff --git a/packages/pigeon/test/pigeon_lib_test.dart b/packages/pigeon/test/pigeon_lib_test.dart index 8f2a587839..63c9498238 100644 --- a/packages/pigeon/test/pigeon_lib_test.dart +++ b/packages/pigeon/test/pigeon_lib_test.dart @@ -890,4 +890,15 @@ abstract class Api { expect(results.errors[0].lineNumber, 3); expect(results.errors[0].message, contains('Unknown type: Foo')); }); + + test('Object type argument', () { + const String code = ''' +@HostApi() +abstract class Api { + void storeAll(List foos); +} +'''; + final ParseResults results = _parseSource(code); + expect(results.errors.length, 0); + }); }