[ObjCExport] Add companion object translation

KT-64953: Required part for enum translation
This commit is contained in:
eugene.levenetc
2024-02-13 14:35:09 +01:00
committed by Space Team
parent acf2296590
commit 97f585dd25
12 changed files with 248 additions and 27 deletions
@@ -0,0 +1,81 @@
#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 Foo1Companion, Foo2Companion, Foo3Companion;
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 Foo1 : Base
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@property (class, readonly, getter=companion) Foo1Companion *companion __attribute__((swift_name("companion")));
@end
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Foo1.Companion")))
@interface Foo1Companion : Base
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)companion __attribute__((swift_name("init()")));
@property (class, readonly, getter=shared) Foo1Companion *shared __attribute__((swift_name("shared")));
- (void)publicFoo __attribute__((swift_name("publicFoo()")));
@property (readonly) int32_t constant __attribute__((swift_name("constant")));
@property (readonly) Foo2Companion *refToFoo2 __attribute__((swift_name("refToFoo2")));
@property (readonly) Foo1Companion *refToItself __attribute__((swift_name("refToItself")));
@end
__attribute__((objc_subclassing_restricted))
@interface Foo2 : Base
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@property (class, readonly, getter=companion) Foo2Companion *companion __attribute__((swift_name("companion")));
@end
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Foo2.Companion")))
@interface Foo2Companion : Base
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)companion __attribute__((swift_name("init()")));
@property (class, readonly, getter=shared) Foo2Companion *shared __attribute__((swift_name("shared")));
- (void)publicFoo __attribute__((swift_name("publicFoo()")));
@property (readonly) int32_t constant __attribute__((swift_name("constant")));
@property (readonly) Foo1Companion *refToFoo1 __attribute__((swift_name("refToFoo1")));
@property (readonly) Foo2Companion *refToItself __attribute__((swift_name("refToItself")));
@end
__attribute__((objc_subclassing_restricted))
@interface Foo3 : Base
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@property (class, readonly, getter=companion) Foo3Companion *companion __attribute__((swift_name("companion")));
@end
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("Foo3.Companion")))
@interface Foo3Companion : Base
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)companion __attribute__((swift_name("init()")));
@property (class, readonly, getter=shared) Foo3Companion *shared __attribute__((swift_name("shared")));
@end
#pragma pop_macro("_Nullable_result")
#pragma clang diagnostic pop
NS_ASSUME_NONNULL_END
@@ -0,0 +1,23 @@
class Foo2 {
companion object {
const val constant = 42
val refToItself = Foo2
val refToFoo1 = Foo1
fun publicFoo() {}
}
}
class Foo3 {
companion object {
}
}
class Foo1 {
companion object {
const val constant = 42
val refToItself = Foo1
val refToFoo2 = Foo2
fun publicFoo() {}
}
}