Skip to content

[pigeon] Fixes double prefixes added to enum names for Objc HostApis and FlutterApis #6263

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

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 17.1.3

* [objc] Fixes double prefixes added to enum names.

## 17.1.2

* [swift] Separates message call code generation into separate methods.
Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'ast.dart';
/// The current version of pigeon.
///
/// This must match the version in pubspec.yaml.
const String pigeonVersion = '17.1.2';
const String pigeonVersion = '17.1.3';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
10 changes: 5 additions & 5 deletions packages/pigeon/lib/objc_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
String? lastArgType;
String? returnType;
final String enumReturnType = _enumName(
returnTypeName.baseName,
func.returnType.baseName,
suffix: ' *_Nullable',
prefix: generatorOptions.prefix,
box: true,
Expand Down Expand Up @@ -765,7 +765,7 @@ static FlutterError *createConnectionError(NSString *channelName) {
} else if (arg.type.isEnum) {
indent.writeln('NSNumber *${argName}AsNumber = $valueGetter;');
indent.writeln(
'${_enumName(arg.type.baseName, suffix: ' *', prefix: '', box: true)}$argName = ${argName}AsNumber == nil ? nil : [[${_enumName(arg.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${argName}AsNumber integerValue]];');
'${_enumName(arg.type.baseName, suffix: ' *', prefix: generatorOptions.prefix, box: true)}$argName = ${argName}AsNumber == nil ? nil : [[${_enumName(arg.type.baseName, prefix: generatorOptions.prefix, box: true)} alloc] initWithValue:[${argName}AsNumber integerValue]];');
} else {
indent.writeln('${objcArgType.beforeString}$argName = $valueGetter;');
}
Expand Down Expand Up @@ -799,7 +799,7 @@ static FlutterError *createConnectionError(NSString *channelName) {

if (func.returnType.isEnum) {
returnTypeString =
'${_enumName(returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue';
'${_enumName(func.returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue';
}
if (func.parameters.isEmpty) {
indent.writeScoped(
Expand Down Expand Up @@ -1132,7 +1132,7 @@ static FlutterError *createConnectionError(NSString *channelName) {
indent.writeln('completion(nil);');
} else {
if (func.returnType.isEnum) {
final String enumName = _enumName(returnType.baseName,
final String enumName = _enumName(func.returnType.baseName,
prefix: languageOptions.prefix, box: true);
indent.writeln('NSNumber *outputAsNumber = $nullCheck;');
indent.writeln(
Expand Down Expand Up @@ -1212,7 +1212,7 @@ String _callbackForType(
if (type.isVoid) {
return 'void (^)(FlutterError *_Nullable)';
} else if (type.isEnum) {
return 'void (^)(${_enumName(objcType.baseName, suffix: ' *_Nullable', prefix: options.prefix, box: true)}, FlutterError *_Nullable)';
return 'void (^)(${_enumName(type.baseName, suffix: ' *_Nullable', prefix: options.prefix, box: true)}, FlutterError *_Nullable)';
} else {
return 'void (^)(${objcType.beforeString}_Nullable, FlutterError *_Nullable)';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ @interface AllDatatypesTest : XCTestCase
@implementation AllDatatypesTest

- (void)testAllNull {
AllNullableTypes *everything = [[AllNullableTypes alloc] init];
FLTAllNullableTypes *everything = [[FLTAllNullableTypes alloc] init];
EchoBinaryMessenger *binaryMessenger =
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
FlutterIntegrationCoreApi *api =
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
FLTFlutterIntegrationCoreApi *api =
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[api echoAllNullableTypes:everything
completion:^(AllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
completion:^(FLTAllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
XCTAssertNil(result.aNullableBool);
XCTAssertNil(result.aNullableInt);
XCTAssertNil(result.aNullableDouble);
Expand All @@ -41,7 +41,7 @@ - (void)testAllNull {
}

- (void)testAllEquals {
AllNullableTypes *everything = [[AllNullableTypes alloc] init];
FLTAllNullableTypes *everything = [[FLTAllNullableTypes alloc] init];
everything.aNullableBool = @NO;
everything.aNullableInt = @(1);
everything.aNullableDouble = @(2.0);
Expand All @@ -58,12 +58,12 @@ - (void)testAllEquals {
everything.aNullableMap = @{@"hello" : @(1234)};
everything.nullableMapWithObject = @{@"hello" : @(1234), @"goodbye" : @"world"};
EchoBinaryMessenger *binaryMessenger =
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
FlutterIntegrationCoreApi *api =
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
FLTFlutterIntegrationCoreApi *api =
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[api echoAllNullableTypes:everything
completion:^(AllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
completion:^(FLTAllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
XCTAssertEqual(result.aNullableBool, everything.aNullableBool);
XCTAssertEqual(result.aNullableInt, everything.aNullableInt);
XCTAssertEqual(result.aNullableDouble, everything.aNullableDouble);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "MockBinaryMessenger.h"

///////////////////////////////////////////////////////////////////////////////////////////
@interface MockHostSmallApi : NSObject <HostSmallApi>
@interface MockHostSmallApi : NSObject <FLTHostSmallApi>
@property(nonatomic, copy) NSString *output;
@property(nonatomic, retain) FlutterError *voidVoidError;
@end
Expand Down Expand Up @@ -42,11 +42,11 @@ @implementation AsyncHandlersTest

- (void)testAsyncHost2Flutter {
MockBinaryMessenger *binaryMessenger =
[[MockBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
[[MockBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
NSString *value = @"Test";
binaryMessenger.result = value;
FlutterIntegrationCoreApi *flutterApi =
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
FLTFlutterIntegrationCoreApi *flutterApi =
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"echo callback"];
[flutterApi echoAsyncString:value
completion:^(NSString *_Nonnull output, FlutterError *_Nullable error) {
Expand All @@ -58,9 +58,9 @@ - (void)testAsyncHost2Flutter {

- (void)testAsyncFlutter2HostVoidVoid {
MockBinaryMessenger *binaryMessenger =
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid";
XCTAssertNotNil(binaryMessenger.handlers[channelName]);

Expand All @@ -75,12 +75,12 @@ - (void)testAsyncFlutter2HostVoidVoid {

- (void)testAsyncFlutter2HostVoidVoidError {
MockBinaryMessenger *binaryMessenger =
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
mockHostSmallApi.voidVoidError = [FlutterError errorWithCode:@"code"
message:@"message"
details:nil];
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid";
XCTAssertNotNil(binaryMessenger.handlers[channelName]);

Expand All @@ -96,11 +96,11 @@ - (void)testAsyncFlutter2HostVoidVoidError {

- (void)testAsyncFlutter2Host {
MockBinaryMessenger *binaryMessenger =
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
NSString *value = @"Test";
mockHostSmallApi.output = value;
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo";
XCTAssertNotNil(binaryMessenger.handlers[channelName]);

Expand All @@ -117,9 +117,9 @@ - (void)testAsyncFlutter2Host {

- (void)testAsyncFlutter2HostError {
MockBinaryMessenger *binaryMessenger =
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo";
XCTAssertNotNil(binaryMessenger.handlers[channelName]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ @interface ListTest : XCTestCase
@implementation ListTest

- (void)testListInList {
TestMessage *top = [[TestMessage alloc] init];
TestMessage *inside = [[TestMessage alloc] init];
FLTTestMessage *top = [[FLTTestMessage alloc] init];
FLTTestMessage *inside = [[FLTTestMessage alloc] init];
inside.testList = @[ @1, @2, @3 ];
top.testList = @[ inside ];
EchoBinaryMessenger *binaryMessenger =
[[EchoBinaryMessenger alloc] initWithCodec:FlutterSmallApiGetCodec()];
FlutterSmallApi *api = [[FlutterSmallApi alloc] initWithBinaryMessenger:binaryMessenger];
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterSmallApiGetCodec()];
FLTFlutterSmallApi *api = [[FLTFlutterSmallApi alloc] initWithBinaryMessenger:binaryMessenger];
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[api echoWrappedList:top
completion:^(TestMessage *_Nonnull result, FlutterError *_Nullable err) {
completion:^(FLTTestMessage *_Nonnull result, FlutterError *_Nullable err) {
XCTAssertEqual(1u, result.testList.count);
XCTAssertTrue([result.testList[0] isKindOfClass:[TestMessage class]]);
XCTAssertTrue([result.testList[0] isKindOfClass:[FLTTestMessage class]]);
XCTAssertEqualObjects(inside.testList, [result.testList[0] testList]);
[expectation fulfill];
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

#import "CoreTests.gen.h"

@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, HostIntegrationCoreApi>
@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, FLTHostIntegrationCoreApi>
@end
Loading