-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[KT-48068] Add opt-in support for NSEnum for Kotlin Native iOS via an annotation #5539
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
Open
stefanhaustein
wants to merge
23
commits into
JetBrains:master
Choose a base branch
from
stefanhaustein:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+621
−56
Open
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2ab6493
make 'something' visible end-to-end
stefanhaustein b824f55
End-to-end wireup with test; method body missing
stefanhaustein e180ad4
current state (incomplete)
stefanhaustein 6ab07ae
cleanup
stefanhaustein b925ff2
cleanup
stefanhaustein e7ec42e
cleanup
stefanhaustein 7e4fb66
ordinal should be in KotlinEnum
stefanhaustein b713914
refactored to avoid ObjCMethodForKotlinMethod
stefanhaustein b126cd4
move symbol resolution from ObjCExportCodeSpec to ObjCExportCodeGener…
stefanhaustein f51d934
swift test compiles
stefanhaustein 854371f
remove footgun
stefanhaustein 4013372
objc/switft name distinction / adjustment
stefanhaustein c9de8d8
Merge branch 'JetBrains:master' into master
stefanhaustein 200acce
Merge branch 'JetBrains:master' into master
stefanhaustein 29e8031
first round of review comments / snapshot before changing to property
stefanhaustein de01982
Merge branch 'JetBrains:master' into master
stefanhaustein 0ccc118
Review comments addressed; mostly adding the missing AA impl
stefanhaustein 60cca82
Make the enum entry value / order more explicit / add a clarifying co…
stefanhaustein 8da8bb4
Naming consistency / fixes and test extensions / improvements
stefanhaustein 6a52203
Move ObjCEnum to the auto documentartion exclude list for AA, matchin…
stefanhaustein bfb6921
first part of addressing 2nd round of review comments
stefanhaustein 51cf02b
addressing review comments part 2
stefanhaustein 32645cb
Add a comment about ordering
stefanhaustein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 | ||
|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ | |||
| package kotlin.native | ||||
|
|
||||
| import kotlin.experimental.ExperimentalNativeApi | ||||
| import kotlin.experimental.ExperimentalObjCEnum | ||||
| import kotlin.experimental.ExperimentalObjCName | ||||
| import kotlin.experimental.ExperimentalObjCRefinement | ||||
|
|
||||
|
|
@@ -116,6 +117,19 @@ public actual annotation class CName(actual val externName: String = "", actual | |||
| @SinceKotlin("1.8") | ||||
| public actual annotation class ObjCName(actual val name: String = "", actual val swiftName: String = "", actual val exact: Boolean = false) | ||||
|
|
||||
| /** | ||||
| * Instructs the Kotlin compiler to generate a NS_ENUM typedef for the annotated enum class. The name of the generated type will | ||||
| * be the name of the enum type with "Enum" appended. This name can be overridden with the "name" parameter, which is treated | ||||
| * as an exact name. The enum literals will be prefixed with the type name, as they live in a global namespace. | ||||
| * Swift naming will automatically remove these prefixes. | ||||
| */ | ||||
| @Target(AnnotationTarget.CLASS) | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, we should check that the annotation is not applied to non- Line 24 in 360c000
To avoid stalling this PR, this can be done separately. |
||||
| @Retention(AnnotationRetention.BINARY) | ||||
| @MustBeDocumented | ||||
stefanhaustein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| @ExperimentalObjCEnum | ||||
| @SinceKotlin("2.3") | ||||
stefanhaustein marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| public actual annotation class ObjCEnum(actual val name: String = "") | ||||
|
|
||||
| /** | ||||
| * Meta-annotation that instructs the Kotlin compiler to remove the annotated class, function or property from the public Objective-C API. | ||||
| * | ||||
|
|
||||
This file contains hidden or 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
16 changes: 16 additions & 0 deletions
16
libraries/stdlib/src/kotlin/experimental/ExperimentalObjCEnum.kt
This file contains hidden or 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,16 @@ | ||
| /* | ||
| * Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
stefanhaustein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
| */ | ||
|
|
||
| package kotlin.experimental | ||
|
|
||
| /** | ||
| * This annotation marks the experimental [ObjCEnum][kotlin.native.ObjCEnum] annotation. | ||
| */ | ||
| @RequiresOptIn | ||
| @Target(AnnotationTarget.ANNOTATION_CLASS) | ||
| @Retention(AnnotationRetention.BINARY) | ||
| @MustBeDocumented | ||
| @SinceKotlin("2.2.21") | ||
| public annotation class ExperimentalObjCEnum | ||
This file contains hidden or 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
10 changes: 10 additions & 0 deletions
10
native/native.tests/testData/framework/objcexport/nativeEnum.kt
This file contains hidden or 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,10 @@ | ||
| package nativeEnum | ||
|
|
||
| import kotlin.native.ObjCEnum | ||
| import kotlin.experimental.ExperimentalObjCEnum | ||
|
|
||
| @OptIn(kotlin.experimental.ExperimentalObjCEnum::class) | ||
| @ObjCEnum("OBJCFoo") | ||
| enum class MyKotlinEnum { | ||
| A, B, C | ||
| } |
21 changes: 21 additions & 0 deletions
21
native/native.tests/testData/framework/objcexport/nativeEnum.swift
This file contains hidden or 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,21 @@ | ||
| import Kt | ||
|
|
||
|
|
||
| private func testNativeEnumValues() throws { | ||
| let ktEnum = MyKotlinEnum.a | ||
| let nsEnum = ktEnum.toNSEnum() | ||
|
|
||
| switch(nsEnum) { | ||
| case .a: try assertEquals(actual: nsEnum, expected: ktEnum.toNSEnum()) | ||
| case .b: try fail() | ||
| case .c: try fail() | ||
| } | ||
| } | ||
|
|
||
| class NativeEnumTests : SimpleTestProvider { | ||
| override init() { | ||
| super.init() | ||
|
|
||
| test("TestNativeEnumValues", testNativeEnumValues) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.