-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ObjCExport] Fix class type extension translation
KT-72350
- Loading branch information
Showing
7 changed files
with
108 additions
and
33 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCPropertyGetter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.objcexport | ||
|
||
import org.jetbrains.kotlin.analysis.api.symbols.KaPropertySymbol | ||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getFunctionMethodBridge | ||
|
||
/** | ||
* Getter needs to be defined only for properties with [reservedPropertyNames] | ||
* ```c | ||
* @interface Foo | ||
* @property (getter=bool, setter=setBool) BOOL bool_ | ||
* @end | ||
* ``` | ||
*/ | ||
internal fun ObjCExportContext.getObjCPropertyGetter(symbol: KaPropertySymbol, objCName: String): String? { | ||
|
||
if (!symbol.hasReservedName) return null | ||
|
||
val symbolGetter = symbol.getter | ||
val getterBridge = if (symbolGetter == null) error("KtPropertySymbol.getter is undefined") else getFunctionMethodBridge(symbolGetter) | ||
val getterSelector = getSelector(symbolGetter, getterBridge) | ||
|
||
return if (getterSelector != objCName && getterSelector.isNotBlank()) getterSelector else null | ||
} |
29 changes: 29 additions & 0 deletions
29
...-generator/impl/analysis-api/src/org/jetbrains/kotlin/objcexport/getObjCPropertySetter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.objcexport | ||
|
||
import org.jetbrains.kotlin.analysis.api.symbols.KaPropertySymbol | ||
import org.jetbrains.kotlin.objcexport.analysisApiUtils.getFunctionMethodBridge | ||
|
||
/** | ||
* Setter needs to be defined only for properties with [reservedPropertyNames] | ||
* ```c | ||
* @interface Foo | ||
* @property (getter=bool, setter=setBool) BOOL bool_ | ||
* @end | ||
* ``` | ||
*/ | ||
internal fun ObjCExportContext.getObjCPropertySetter(symbol: KaPropertySymbol, objCName: String): String? { | ||
|
||
if (!symbol.hasReservedName) return null | ||
|
||
val setterName = symbol.setter?.let { | ||
val setterSelector = getSelector(it, getFunctionMethodBridge(it)) | ||
if (setterSelector == objCName.asSetterSelector) null else setterSelector | ||
} | ||
|
||
return if (setterName.isNullOrBlank()) null else setterName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...r-generator/testData/headers/classTypePropertyTranslation/!classTypePropertyTranslation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#import <Foundation/NSArray.h> | ||
#import <Foundation/NSDictionary.h> | ||
#import <Foundation/NSError.h> | ||
#import <Foundation/NSObject.h> | ||
#import <Foundation/NSSet.h> | ||
#import <Foundation/NSString.h> | ||
#import <Foundation/NSValue.h> | ||
|
||
@class Foo; | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
#pragma clang diagnostic push | ||
#pragma clang diagnostic ignored "-Wunknown-warning-option" | ||
#pragma clang diagnostic ignored "-Wincompatible-property-type" | ||
#pragma clang diagnostic ignored "-Wnullability" | ||
|
||
#pragma push_macro("_Nullable_result") | ||
#if !__has_feature(nullability_nullable_result) | ||
#undef _Nullable_result | ||
#define _Nullable_result _Nullable | ||
#endif | ||
|
||
__attribute__((objc_subclassing_restricted)) | ||
@interface Foo : Base | ||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer)); | ||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead"))); | ||
- (int32_t)extensionProperty:(Foo *)receiver __attribute__((swift_name("extensionProperty(_:)"))); | ||
@end | ||
|
||
#pragma pop_macro("_Nullable_result") | ||
#pragma clang diagnostic pop | ||
NS_ASSUME_NONNULL_END |
3 changes: 3 additions & 0 deletions
3
native/objcexport-header-generator/testData/headers/classTypePropertyTranslation/Foo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Foo { | ||
val Foo.extensionProperty: Int get() = 42 | ||
} |