-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic SkieVisibility configuration.
- Loading branch information
1 parent
e553fc6
commit 79d42e4
Showing
16 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
Submodule acceptance-tests
updated
from 24a762 to 5d11cd
75 changes: 75 additions & 0 deletions
75
...ations/src/commonMain/kotlin/co/touchlab/skie/configuration/annotations/SkieVisibility.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,75 @@ | ||
package co.touchlab.skie.configuration.annotations | ||
|
||
/** | ||
* Configures visibility of the exported Kotlin declarations in Swift. | ||
* In the future, the visibility will be applied directly to the Obj-C header meaning it will also affect external Obj-C code. | ||
* | ||
* Note: Using multiple visibility annotations on the same declaration results in an undefined behavior, and may result in a compilation crash. | ||
* | ||
* Warning: SKIE does not check whether the configured visibility is correct or not. | ||
* For example, it's possible to create a public interface with internal members. | ||
* Invalid configurations will likely lead to weird issues and compiler crashes. | ||
* In the future, SKIE might introduce explicit checks that will crash the compilation explicitly in those cases. | ||
*/ | ||
@Target | ||
annotation class SkieVisibility { | ||
|
||
/** | ||
* The declaration will be visible from external modules as usual. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) | ||
annotation class Public | ||
|
||
/** | ||
* The declaration will be visible from external modules, but it will be marked as `swift-private`. | ||
* (Xcode will not include it in autocomplete suggestions.) | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) | ||
annotation class PublicButHidden | ||
|
||
/** | ||
* The declaration will be visible from external modules, but it will be: | ||
* - marked as `swift-private` (Xcode will not include it in autocomplete suggestions.), | ||
* - renamed in Swift by adding the `__` prefix (Obj-C name remains the same) | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | ||
annotation class PublicButReplaced | ||
|
||
/** | ||
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE). | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) | ||
annotation class Internal | ||
|
||
/** | ||
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE). | ||
* Additionally, the declaration will be renamed in Swift by adding the `__` prefix (Obj-C name remains the same) | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | ||
annotation class InternalAndReplaced | ||
|
||
/** | ||
* The declaration will either be Public or Internal. | ||
* Which one is chosen depends on whether the declaration is automatically wrapped by SKIE or not. | ||
* | ||
* For example, a top-level function originally exposed as `FileKt.functionName` will be internal, if SKIE generated the global function wrapper for it. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) | ||
annotation class InternalIfWrapped | ||
|
||
/** | ||
* The declaration will not be visible. | ||
* | ||
* Note that this doesn't change whether the declaration is exported by the Kotlin compiler, therefore the compilation overhead from the exported declaration remains unchanged. | ||
*/ | ||
@Retention(AnnotationRetention.BINARY) | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY, AnnotationTarget.CONSTRUCTOR) | ||
annotation class Private | ||
} | ||
|
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
69 changes: 69 additions & 0 deletions
69
...ration/declaration/src/commonMain/kotlin/co/touchlab/skie/configuration/SkieVisibility.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,69 @@ | ||
package co.touchlab.skie.configuration | ||
|
||
import co.touchlab.skie.configuration.annotations.SkieVisibility | ||
import kotlin.reflect.KClass | ||
|
||
/** | ||
* Configures visibility of the exported Kotlin declarations in Swift. | ||
* In the future, the visibility will be applied directly to the Obj-C header meaning it will also affect external Obj-C code. | ||
* | ||
* Warning: SKIE does not check whether the configured visibility is correct or not. | ||
* For example, it's possible to create a public interface with internal members. | ||
* Invalid configurations will likely lead to weird issues and compiler crashes. | ||
* In the future, SKIE might introduce explicit checks that will crash the compilation explicitly in those cases. | ||
*/ | ||
object SkieVisibility : ConfigurationKey.Enum<co.touchlab.skie.configuration.SkieVisibility.Level>, ConfigurationScope.All { | ||
|
||
enum class Level(internal val associatedAnnotation: KClass<out Annotation>) { | ||
/** | ||
* The declaration will be visible from external modules as usual. | ||
*/ | ||
Public(SkieVisibility.Public::class), | ||
|
||
/** | ||
* The declaration will be visible from external modules, but it will be marked as `swift-private`. | ||
* (Xcode will not include it in autocomplete suggestions.) | ||
*/ | ||
PublicButHidden(SkieVisibility.PublicButHidden::class), | ||
|
||
/** | ||
* The declaration will be visible from external modules, but it will be: | ||
* - marked as `swift-private` (Xcode will not include it in autocomplete suggestions.), | ||
* - renamed in Swift by adding the `__` prefix (Obj-C name remains the same); constructors are not affected. | ||
*/ | ||
PublicButReplaced(SkieVisibility.PublicButReplaced::class), | ||
|
||
/** | ||
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE). | ||
*/ | ||
Internal(SkieVisibility.Internal::class), | ||
|
||
/** | ||
* The declaration will be visible only for declarations within the Kotlin module (including custom Swift code bundled by SKIE). | ||
* Additionally, the declaration will be renamed in Swift by adding the `__` prefix (Obj-C name remains the same); constructors are not affected. | ||
*/ | ||
InternalAndReplaced(SkieVisibility.InternalAndReplaced::class), | ||
|
||
/** | ||
* The declaration will either be Public or Internal. | ||
* Which one is chosen depends on whether the declaration is automatically wrapped by SKIE or not. | ||
* | ||
* For example, a top-level function originally exposed as `FileKt.functionName` will be internal, if SKIE generated the global function wrapper for it. | ||
*/ | ||
InternalIfWrapped(SkieVisibility.InternalIfWrapped::class), | ||
|
||
/** | ||
* The declaration will not be visible. | ||
* | ||
* Note that this doesn't change whether the declaration is exported by the Kotlin compiler, therefore the compilation overhead from the exported declaration remains unchanged. | ||
*/ | ||
Private(SkieVisibility.Private::class), | ||
} | ||
|
||
override val defaultValue: Level = Level.Public | ||
|
||
override fun valueOf(value: String): Level = Level.valueOf(value) | ||
|
||
override fun findAnnotationValue(configurationTarget: ConfigurationTarget): Level? = | ||
Level.values().firstOrNull { configurationTarget.hasAnnotation(it.associatedAnnotation) } | ||
} |
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
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
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
15 changes: 15 additions & 0 deletions
15
...ompiler/core/src/commonMain/kotlin/co/touchlab/skie/util/SkieVisibilityToSirVisibility.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,15 @@ | ||
package co.touchlab.skie.util | ||
|
||
import co.touchlab.skie.configuration.SkieVisibility | ||
import co.touchlab.skie.sir.element.SirVisibility | ||
|
||
fun SkieVisibility.Level.toSirVisibility(isWrapped: Boolean = false): SirVisibility = | ||
when (this) { | ||
SkieVisibility.Level.Public -> SirVisibility.Public | ||
SkieVisibility.Level.PublicButHidden -> SirVisibility.PublicButHidden | ||
SkieVisibility.Level.PublicButReplaced -> SirVisibility.PublicButHidden | ||
SkieVisibility.Level.Internal -> SirVisibility.Internal | ||
SkieVisibility.Level.InternalAndReplaced -> SirVisibility.Internal | ||
SkieVisibility.Level.InternalIfWrapped -> if (isWrapped) SirVisibility.Internal else SirVisibility.Public | ||
SkieVisibility.Level.Private -> SirVisibility.Private | ||
} |
Oops, something went wrong.