[Native] Add HiddenFromObjC and ShouldRefineInSwift annotations
This commit is contained in:
committed by
SvyatoslavScherbina
parent
a65cb947d6
commit
6ae517a2df
@@ -1418,6 +1418,40 @@ __attribute__((swift_name("OverrideMethodsOfAnyKt")))
|
||||
+ (BOOL)testObj:(id)obj other:(id)other swift:(BOOL)swift error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test(obj:other:swift:)")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("RefinedClassA")))
|
||||
@interface KtRefinedClassA : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedClassB")))
|
||||
@interface KtRefinedClassB : KtRefinedClassA
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedKt")))
|
||||
@interface KtRefinedKt : KtBase
|
||||
+ (NSString *)fooRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
+ (NSString *)myFooRefined __attribute__((swift_private));
|
||||
@property (class, readonly) NSString *barRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
@property (class, readonly) NSString *myBarRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("Person")))
|
||||
@interface KtPerson : KtBase
|
||||
@end
|
||||
|
||||
@@ -1353,6 +1353,40 @@ __attribute__((swift_name("OverrideMethodsOfAnyKt")))
|
||||
+ (BOOL)testObj:(id)obj other:(id)other swift:(BOOL)swift error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test(obj:other:swift:)")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("RefinedClassA")))
|
||||
@interface KtRefinedClassA : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedClassB")))
|
||||
@interface KtRefinedClassB : KtRefinedClassA
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedKt")))
|
||||
@interface KtRefinedKt : KtBase
|
||||
+ (NSString *)fooRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
+ (NSString *)myFooRefined __attribute__((swift_private));
|
||||
@property (class, readonly) NSString *barRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
@property (class, readonly) NSString *myBarRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("Person")))
|
||||
@interface KtPerson : KtBase
|
||||
@end
|
||||
|
||||
@@ -1353,6 +1353,40 @@ __attribute__((swift_name("OverrideMethodsOfAnyKt")))
|
||||
+ (BOOL)testObj:(id)obj other:(id)other swift:(BOOL)swift error:(NSError * _Nullable * _Nullable)error __attribute__((swift_name("test(obj:other:swift:)")));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("RefinedClassA")))
|
||||
@interface KtRefinedClassA : KtBase
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedClassB")))
|
||||
@interface KtRefinedClassB : KtRefinedClassA
|
||||
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
|
||||
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
|
||||
- (NSString *)fooRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((objc_subclassing_restricted))
|
||||
__attribute__((swift_name("RefinedKt")))
|
||||
@interface KtRefinedKt : KtBase
|
||||
+ (NSString *)fooRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
+ (NSString *)myFooRefined __attribute__((swift_private));
|
||||
@property (class, readonly) NSString *barRefined __attribute__((swift_private));
|
||||
|
||||
/**
|
||||
* @note annotations
|
||||
* refined.MyShouldRefineInSwift
|
||||
*/
|
||||
@property (class, readonly) NSString *myBarRefined __attribute__((swift_private));
|
||||
@end
|
||||
|
||||
__attribute__((swift_name("Person")))
|
||||
@interface KtPerson : KtBase
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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 refined
|
||||
|
||||
import kotlin.experimental.ExperimentalObjCRefinement
|
||||
|
||||
@ExperimentalObjCRefinement
|
||||
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@MustBeDocumented
|
||||
@HidesFromObjC
|
||||
annotation class MyHiddenFromObjC
|
||||
|
||||
@ExperimentalObjCRefinement
|
||||
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@MustBeDocumented
|
||||
@RefinesInSwift
|
||||
annotation class MyShouldRefineInSwift
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
fun foo(): Int = 1
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@ShouldRefineInSwift
|
||||
fun fooRefined(): String = foo().toString()
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@MyHiddenFromObjC
|
||||
fun myFoo(): Int = 2
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@MyShouldRefineInSwift
|
||||
fun myFooRefined(): String = myFoo().toString()
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
val bar: Int = 3
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@ShouldRefineInSwift
|
||||
val barRefined: String get() = bar.toString()
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@MyHiddenFromObjC
|
||||
val myBar: Int = 4
|
||||
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@MyShouldRefineInSwift
|
||||
val myBarRefined: String get() = myBar.toString()
|
||||
|
||||
open class RefinedClassA {
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@HiddenFromObjC
|
||||
open fun foo(): Int = 1
|
||||
@OptIn(ExperimentalObjCRefinement::class)
|
||||
@ShouldRefineInSwift
|
||||
open fun fooRefined(): String = foo().toString()
|
||||
}
|
||||
|
||||
class RefinedClassB: RefinedClassA() {
|
||||
override fun foo(): Int = 2
|
||||
override fun fooRefined(): String {
|
||||
val foo = foo()
|
||||
return "$foo$foo"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import Kt
|
||||
|
||||
extension RefinedKt {
|
||||
static func foo() -> Int {
|
||||
return Int(RefinedKt.__fooRefined())! * 2
|
||||
}
|
||||
|
||||
static func myFoo() -> Int {
|
||||
return Int(RefinedKt.__myFooRefined())! * 2
|
||||
}
|
||||
|
||||
static var bar: Int {
|
||||
return Int(RefinedKt.__barRefined)! * 2
|
||||
}
|
||||
|
||||
static var myBar: Int {
|
||||
return Int(RefinedKt.__myBarRefined)! * 2
|
||||
}
|
||||
}
|
||||
|
||||
extension RefinedClassA {
|
||||
func foo() -> Int {
|
||||
return Int(__fooRefined())! * 2
|
||||
}
|
||||
}
|
||||
|
||||
private func testSwiftRefinements() throws {
|
||||
try assertEquals(actual: RefinedKt.foo(), expected: 2)
|
||||
try assertEquals(actual: RefinedKt.bar, expected: 6)
|
||||
}
|
||||
|
||||
private func testMySwiftRefinements() throws {
|
||||
try assertEquals(actual: RefinedKt.myFoo(), expected: 4)
|
||||
try assertEquals(actual: RefinedKt.myBar, expected: 8)
|
||||
}
|
||||
|
||||
private func testInheritedRefinements() throws {
|
||||
try assertEquals(actual: RefinedClassA().foo(), expected: 2)
|
||||
try assertEquals(actual: RefinedClassB().foo(), expected: 44)
|
||||
}
|
||||
|
||||
class RefinedTests : SimpleTestProvider {
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
test("TestSwiftRefinements", testSwiftRefinements)
|
||||
test("TestMySwiftRefinements", testMySwiftRefinements)
|
||||
test("TestInheritedRefinements", testInheritedRefinements)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user