Skip to content

Commit 0895119

Browse files
[pigeon] Fixes double prefixes added to enum names for Objc HostApis and FlutterApis (#6263)
In some areas of the Objc generator, the the name created from [_objcTypeForDartType](https://github.com/flutter/packages/blob/main/packages/pigeon/lib/objc_generator.dart#L1353) is being passed to [_enumName](https://github.com/flutter/packages/blob/main/packages/pigeon/lib/objc_generator.dart#L1196) and both of these methods add a prefix to enums. The locations are when they are used in `HostApi` or `FlutterApi` methods, but the name of the generated enum would be correct. e.g. `FLTEnumName` vs `FLTFLTEnumName`. This fixes the locations where this is happening by passing the AST name to `_enumName` instead.
1 parent 92a8b7a commit 0895119

File tree

13 files changed

+769
-576
lines changed

13 files changed

+769
-576
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 17.1.3
2+
3+
* [objc] Fixes double prefixes added to enum names.
4+
15
## 17.1.2
26

37
* [swift] Separates message call code generation into separate methods.

packages/pigeon/lib/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'ast.dart';
1313
/// The current version of pigeon.
1414
///
1515
/// This must match the version in pubspec.yaml.
16-
const String pigeonVersion = '17.1.2';
16+
const String pigeonVersion = '17.1.3';
1717

1818
/// Read all the content from [stdin] to a String.
1919
String readStdin() {

packages/pigeon/lib/objc_generator.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class ObjcHeaderGenerator extends StructuredGenerator<ObjcOptions> {
359359
String? lastArgType;
360360
String? returnType;
361361
final String enumReturnType = _enumName(
362-
returnTypeName.baseName,
362+
func.returnType.baseName,
363363
suffix: ' *_Nullable',
364364
prefix: generatorOptions.prefix,
365365
box: true,
@@ -765,7 +765,7 @@ static FlutterError *createConnectionError(NSString *channelName) {
765765
} else if (arg.type.isEnum) {
766766
indent.writeln('NSNumber *${argName}AsNumber = $valueGetter;');
767767
indent.writeln(
768-
'${_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]];');
768+
'${_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]];');
769769
} else {
770770
indent.writeln('${objcArgType.beforeString}$argName = $valueGetter;');
771771
}
@@ -799,7 +799,7 @@ static FlutterError *createConnectionError(NSString *channelName) {
799799

800800
if (func.returnType.isEnum) {
801801
returnTypeString =
802-
'${_enumName(returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue';
802+
'${_enumName(func.returnType.baseName, suffix: ' *_Nullable', prefix: generatorOptions.prefix, box: true)} enumValue';
803803
}
804804
if (func.parameters.isEmpty) {
805805
indent.writeScoped(
@@ -1132,7 +1132,7 @@ static FlutterError *createConnectionError(NSString *channelName) {
11321132
indent.writeln('completion(nil);');
11331133
} else {
11341134
if (func.returnType.isEnum) {
1135-
final String enumName = _enumName(returnType.baseName,
1135+
final String enumName = _enumName(func.returnType.baseName,
11361136
prefix: languageOptions.prefix, box: true);
11371137
indent.writeln('NSNumber *outputAsNumber = $nullCheck;');
11381138
indent.writeln(
@@ -1212,7 +1212,7 @@ String _callbackForType(
12121212
if (type.isVoid) {
12131213
return 'void (^)(FlutterError *_Nullable)';
12141214
} else if (type.isEnum) {
1215-
return 'void (^)(${_enumName(objcType.baseName, suffix: ' *_Nullable', prefix: options.prefix, box: true)}, FlutterError *_Nullable)';
1215+
return 'void (^)(${_enumName(type.baseName, suffix: ' *_Nullable', prefix: options.prefix, box: true)}, FlutterError *_Nullable)';
12161216
} else {
12171217
return 'void (^)(${objcType.beforeString}_Nullable, FlutterError *_Nullable)';
12181218
}

packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AllDatatypesTest.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ @interface AllDatatypesTest : XCTestCase
1717
@implementation AllDatatypesTest
1818

1919
- (void)testAllNull {
20-
AllNullableTypes *everything = [[AllNullableTypes alloc] init];
20+
FLTAllNullableTypes *everything = [[FLTAllNullableTypes alloc] init];
2121
EchoBinaryMessenger *binaryMessenger =
22-
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
23-
FlutterIntegrationCoreApi *api =
24-
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
22+
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
23+
FLTFlutterIntegrationCoreApi *api =
24+
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
2525
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
2626
[api echoAllNullableTypes:everything
27-
completion:^(AllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
27+
completion:^(FLTAllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
2828
XCTAssertNil(result.aNullableBool);
2929
XCTAssertNil(result.aNullableInt);
3030
XCTAssertNil(result.aNullableDouble);
@@ -41,7 +41,7 @@ - (void)testAllNull {
4141
}
4242

4343
- (void)testAllEquals {
44-
AllNullableTypes *everything = [[AllNullableTypes alloc] init];
44+
FLTAllNullableTypes *everything = [[FLTAllNullableTypes alloc] init];
4545
everything.aNullableBool = @NO;
4646
everything.aNullableInt = @(1);
4747
everything.aNullableDouble = @(2.0);
@@ -58,12 +58,12 @@ - (void)testAllEquals {
5858
everything.aNullableMap = @{@"hello" : @(1234)};
5959
everything.nullableMapWithObject = @{@"hello" : @(1234), @"goodbye" : @"world"};
6060
EchoBinaryMessenger *binaryMessenger =
61-
[[EchoBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
62-
FlutterIntegrationCoreApi *api =
63-
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
61+
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
62+
FLTFlutterIntegrationCoreApi *api =
63+
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
6464
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
6565
[api echoAllNullableTypes:everything
66-
completion:^(AllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
66+
completion:^(FLTAllNullableTypes *_Nonnull result, FlutterError *_Nullable error) {
6767
XCTAssertEqual(result.aNullableBool, everything.aNullableBool);
6868
XCTAssertEqual(result.aNullableInt, everything.aNullableInt);
6969
XCTAssertEqual(result.aNullableDouble, everything.aNullableDouble);

packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/AsyncHandlersTest.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#import "MockBinaryMessenger.h"
1111

1212
///////////////////////////////////////////////////////////////////////////////////////////
13-
@interface MockHostSmallApi : NSObject <HostSmallApi>
13+
@interface MockHostSmallApi : NSObject <FLTHostSmallApi>
1414
@property(nonatomic, copy) NSString *output;
1515
@property(nonatomic, retain) FlutterError *voidVoidError;
1616
@end
@@ -42,11 +42,11 @@ @implementation AsyncHandlersTest
4242

4343
- (void)testAsyncHost2Flutter {
4444
MockBinaryMessenger *binaryMessenger =
45-
[[MockBinaryMessenger alloc] initWithCodec:FlutterIntegrationCoreApiGetCodec()];
45+
[[MockBinaryMessenger alloc] initWithCodec:FLTFlutterIntegrationCoreApiGetCodec()];
4646
NSString *value = @"Test";
4747
binaryMessenger.result = value;
48-
FlutterIntegrationCoreApi *flutterApi =
49-
[[FlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
48+
FLTFlutterIntegrationCoreApi *flutterApi =
49+
[[FLTFlutterIntegrationCoreApi alloc] initWithBinaryMessenger:binaryMessenger];
5050
XCTestExpectation *expectation = [self expectationWithDescription:@"echo callback"];
5151
[flutterApi echoAsyncString:value
5252
completion:^(NSString *_Nonnull output, FlutterError *_Nullable error) {
@@ -58,9 +58,9 @@ - (void)testAsyncHost2Flutter {
5858

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

@@ -75,12 +75,12 @@ - (void)testAsyncFlutter2HostVoidVoid {
7575

7676
- (void)testAsyncFlutter2HostVoidVoidError {
7777
MockBinaryMessenger *binaryMessenger =
78-
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
78+
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
7979
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
8080
mockHostSmallApi.voidVoidError = [FlutterError errorWithCode:@"code"
8181
message:@"message"
8282
details:nil];
83-
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
83+
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
8484
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid";
8585
XCTAssertNotNil(binaryMessenger.handlers[channelName]);
8686

@@ -96,11 +96,11 @@ - (void)testAsyncFlutter2HostVoidVoidError {
9696

9797
- (void)testAsyncFlutter2Host {
9898
MockBinaryMessenger *binaryMessenger =
99-
[[MockBinaryMessenger alloc] initWithCodec:HostSmallApiGetCodec()];
99+
[[MockBinaryMessenger alloc] initWithCodec:FLTHostSmallApiGetCodec()];
100100
MockHostSmallApi *mockHostSmallApi = [[MockHostSmallApi alloc] init];
101101
NSString *value = @"Test";
102102
mockHostSmallApi.output = value;
103-
SetUpHostSmallApi(binaryMessenger, mockHostSmallApi);
103+
SetUpFLTHostSmallApi(binaryMessenger, mockHostSmallApi);
104104
NSString *channelName = @"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo";
105105
XCTAssertNotNil(binaryMessenger.handlers[channelName]);
106106

@@ -117,9 +117,9 @@ - (void)testAsyncFlutter2Host {
117117

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

packages/pigeon/platform_tests/alternate_language_test_plugin/example/ios/RunnerTests/ListTest.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ @interface ListTest : XCTestCase
1717
@implementation ListTest
1818

1919
- (void)testListInList {
20-
TestMessage *top = [[TestMessage alloc] init];
21-
TestMessage *inside = [[TestMessage alloc] init];
20+
FLTTestMessage *top = [[FLTTestMessage alloc] init];
21+
FLTTestMessage *inside = [[FLTTestMessage alloc] init];
2222
inside.testList = @[ @1, @2, @3 ];
2323
top.testList = @[ inside ];
2424
EchoBinaryMessenger *binaryMessenger =
25-
[[EchoBinaryMessenger alloc] initWithCodec:FlutterSmallApiGetCodec()];
26-
FlutterSmallApi *api = [[FlutterSmallApi alloc] initWithBinaryMessenger:binaryMessenger];
25+
[[EchoBinaryMessenger alloc] initWithCodec:FLTFlutterSmallApiGetCodec()];
26+
FLTFlutterSmallApi *api = [[FLTFlutterSmallApi alloc] initWithBinaryMessenger:binaryMessenger];
2727
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
2828
[api echoWrappedList:top
29-
completion:^(TestMessage *_Nonnull result, FlutterError *_Nullable err) {
29+
completion:^(FLTTestMessage *_Nonnull result, FlutterError *_Nullable err) {
3030
XCTAssertEqual(1u, result.testList.count);
31-
XCTAssertTrue([result.testList[0] isKindOfClass:[TestMessage class]]);
31+
XCTAssertTrue([result.testList[0] isKindOfClass:[FLTTestMessage class]]);
3232
XCTAssertEqualObjects(inside.testList, [result.testList[0] testList]);
3333
[expectation fulfill];
3434
}];

packages/pigeon/platform_tests/alternate_language_test_plugin/ios/Classes/AlternateLanguageTestPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66

77
#import "CoreTests.gen.h"
88

9-
@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, HostIntegrationCoreApi>
9+
@interface AlternateLanguageTestPlugin : NSObject <FlutterPlugin, FLTHostIntegrationCoreApi>
1010
@end

0 commit comments

Comments
 (0)