Skip to content

Commit

Permalink
Add experimental annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
arkivanov committed Jul 8, 2024
1 parent e8bbceb commit ae49024
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 17 deletions.
3 changes: 3 additions & 0 deletions instance-keeper/api/android/instance-keeper.api
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public final class com/arkivanov/essenty/instancekeeper/AndroidExtKt {
public static synthetic fun instanceKeeper$default (Landroidx/lifecycle/ViewModelStoreOwner;ZILjava/lang/Object;)Lcom/arkivanov/essenty/instancekeeper/InstanceKeeper;
}

public abstract interface annotation class com/arkivanov/essenty/instancekeeper/ExperimentalInstanceKeeperApi : java/lang/annotation/Annotation {
}

public abstract interface class com/arkivanov/essenty/instancekeeper/InstanceKeeper {
public abstract fun get (Ljava/lang/Object;)Lcom/arkivanov/essenty/instancekeeper/InstanceKeeper$Instance;
public abstract fun put (Ljava/lang/Object;Lcom/arkivanov/essenty/instancekeeper/InstanceKeeper$Instance;)V
Expand Down
3 changes: 3 additions & 0 deletions instance-keeper/api/instance-keeper.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ final inline fun <#A: reified com.arkivanov.essenty.instancekeeper/InstanceKeepe
final inline fun <#A: reified kotlin/Any?> (com.arkivanov.essenty.instancekeeper/InstanceKeeper).com.arkivanov.essenty.instancekeeper/getOrCreateSimple(kotlin/Function0<#A>): #A // com.arkivanov.essenty.instancekeeper/getOrCreateSimple|getOrCreateSimple@com.arkivanov.essenty.instancekeeper.InstanceKeeper(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
final inline fun <#A: reified kotlin/Any?> (com.arkivanov.essenty.instancekeeper/InstanceKeeperOwner).com.arkivanov.essenty.instancekeeper/retainedSimpleInstance(kotlin/Any, kotlin/Function0<#A>): #A // com.arkivanov.essenty.instancekeeper/retainedSimpleInstance|retainedSimpleInstance@com.arkivanov.essenty.instancekeeper.InstanceKeeperOwner(kotlin.Any;kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
final inline fun <#A: reified kotlin/Any?> (com.arkivanov.essenty.instancekeeper/InstanceKeeperOwner).com.arkivanov.essenty.instancekeeper/retainedSimpleInstance(kotlin/Function0<#A>): #A // com.arkivanov.essenty.instancekeeper/retainedSimpleInstance|retainedSimpleInstance@com.arkivanov.essenty.instancekeeper.InstanceKeeperOwner(kotlin.Function0<0:0>){0§<kotlin.Any?>}[0]
open annotation class com.arkivanov.essenty.instancekeeper/ExperimentalInstanceKeeperApi : kotlin/Annotation { // com.arkivanov.essenty.instancekeeper/ExperimentalInstanceKeeperApi|null[0]
constructor <init>() // com.arkivanov.essenty.instancekeeper/ExperimentalInstanceKeeperApi.<init>|<init>(){}[0]
}
3 changes: 3 additions & 0 deletions instance-keeper/api/jvm/instance-keeper.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
public abstract interface annotation class com/arkivanov/essenty/instancekeeper/ExperimentalInstanceKeeperApi : java/lang/annotation/Annotation {
}

public abstract interface class com/arkivanov/essenty/instancekeeper/InstanceKeeper {
public abstract fun get (Ljava/lang/Object;)Lcom/arkivanov/essenty/instancekeeper/InstanceKeeper$Instance;
public abstract fun put (Ljava/lang/Object;Lcom/arkivanov/essenty/instancekeeper/InstanceKeeper$Instance;)V
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arkivanov.essenty.instancekeeper

/**
* Marks experimental API in Essenty. An experimental API can be changed or removed at any time.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class ExperimentalInstanceKeeperApi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.arkivanov.essenty.instancekeeper

import com.arkivanov.essenty.instancekeeper.InstanceKeeper.SimpleInstance
import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlin.reflect.typeOf

/**
Expand Down Expand Up @@ -29,14 +28,14 @@ inline fun <reified T : InstanceKeeper.Instance> InstanceKeeper.getOrCreate(fact
/**
* A convenience function for [InstanceKeeper.getOrCreate].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T : InstanceKeeper.Instance> InstanceKeeperOwner.retainedInstance(key: Any, factory: () -> T): T =
instanceKeeper.getOrCreate(key = key, factory = factory)

/**
* A convenience function for [InstanceKeeper.getOrCreate].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T : InstanceKeeper.Instance> InstanceKeeperOwner.retainedInstance(factory: () -> T): T =
instanceKeeper.getOrCreate(factory = factory)

Expand All @@ -62,13 +61,13 @@ inline fun <reified T> InstanceKeeper.getOrCreateSimple(factory: () -> T): T =
/**
* A convenience function for [InstanceKeeper.getOrCreateSimple].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T> InstanceKeeperOwner.retainedSimpleInstance(key: Any, factory: () -> T): T =
instanceKeeper.getOrCreateSimple(key = key, factory = factory)

/**
* A convenience function for [InstanceKeeper.getOrCreateSimple].
*/
@ExperimentalEssentyApi
@ExperimentalInstanceKeeperApi
inline fun <reified T> InstanceKeeperOwner.retainedSimpleInstance(factory: () -> T): T =
instanceKeeper.getOrCreateSimple(factory = factory)
3 changes: 3 additions & 0 deletions state-keeper/api/android/state-keeper.api
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public final class com/arkivanov/essenty/statekeeper/BundleExtKt {
public static final fun putSerializableContainer (Landroid/os/Bundle;Ljava/lang/String;Lcom/arkivanov/essenty/statekeeper/SerializableContainer;)V
}

public abstract interface annotation class com/arkivanov/essenty/statekeeper/ExperimentalStateKeeperApi : java/lang/annotation/Annotation {
}

public final class com/arkivanov/essenty/statekeeper/PolymorphicSerializerKt {
public static final fun polymorphicSerializer (Lkotlin/reflect/KClass;Lkotlinx/serialization/modules/SerializersModule;)Lkotlinx/serialization/KSerializer;
}
Expand Down
3 changes: 3 additions & 0 deletions state-keeper/api/jvm/state-keeper.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
public abstract interface annotation class com/arkivanov/essenty/statekeeper/ExperimentalStateKeeperApi : java/lang/annotation/Annotation {
}

public final class com/arkivanov/essenty/statekeeper/PolymorphicSerializerKt {
public static final fun polymorphicSerializer (Lkotlin/reflect/KClass;Lkotlinx/serialization/modules/SerializersModule;)Lkotlinx/serialization/KSerializer;
}
Expand Down
3 changes: 3 additions & 0 deletions state-keeper/api/state-keeper.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ final inline fun <#A: kotlin/Any> (com.arkivanov.essenty.statekeeper/StateKeeper
final inline fun <#A: kotlin/Any?, #B: kotlin/Any> (com.arkivanov.essenty.statekeeper/StateKeeper).com.arkivanov.essenty.statekeeper/saveable(kotlinx.serialization/KSerializer<#B>, crossinline kotlin/Function1<#A, #B>, kotlin/String? = ..., crossinline kotlin/Function1<#B?, #A>): kotlin.properties/PropertyDelegateProvider<kotlin/Any?, kotlin.properties/ReadOnlyProperty<kotlin/Any?, #A>> // com.arkivanov.essenty.statekeeper/saveable|[email protected](kotlinx.serialization.KSerializer<0:1>;kotlin.Function1<0:0,0:1>;kotlin.String?;kotlin.Function1<0:1?,0:0>){0§<kotlin.Any?>;1§<kotlin.Any>}[0]
final inline fun <#A: kotlin/Any?, #B: kotlin/Any> (com.arkivanov.essenty.statekeeper/StateKeeperOwner).com.arkivanov.essenty.statekeeper/saveable(kotlinx.serialization/KSerializer<#B>, crossinline kotlin/Function1<#A, #B>, kotlin/String? = ..., crossinline kotlin/Function1<#B?, #A>): kotlin.properties/PropertyDelegateProvider<kotlin/Any?, kotlin.properties/ReadOnlyProperty<kotlin/Any?, #A>> // com.arkivanov.essenty.statekeeper/saveable|[email protected](kotlinx.serialization.KSerializer<0:1>;kotlin.Function1<0:0,0:1>;kotlin.String?;kotlin.Function1<0:1?,0:0>){0§<kotlin.Any?>;1§<kotlin.Any>}[0]
final inline fun <#A: reified kotlin/Any> com.arkivanov.essenty.statekeeper/polymorphicSerializer(kotlinx.serialization.modules/SerializersModule): kotlinx.serialization/KSerializer<#A> // com.arkivanov.essenty.statekeeper/polymorphicSerializer|polymorphicSerializer(kotlinx.serialization.modules.SerializersModule){0§<kotlin.Any>}[0]
open annotation class com.arkivanov.essenty.statekeeper/ExperimentalStateKeeperApi : kotlin/Annotation { // com.arkivanov.essenty.statekeeper/ExperimentalStateKeeperApi|null[0]
constructor <init>() // com.arkivanov.essenty.statekeeper/ExperimentalStateKeeperApi.<init>|<init>(){}[0]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.arkivanov.essenty.statekeeper

/**
* Marks experimental API in Essenty. An experimental API can be changed or removed at any time.
*/
@RequiresOptIn(level = RequiresOptIn.Level.WARNING)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class ExperimentalStateKeeperApi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
Expand All @@ -18,15 +17,15 @@ import kotlin.reflect.KClass
/**
* Creates a polymorphic [KSerializer] for the specified class of type [T] using the specified [module].
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
@ExperimentalSerializationApi
inline fun <reified T : Any> polymorphicSerializer(module: SerializersModule): KSerializer<T> =
polymorphicSerializer(baseClass = T::class, module = module)

/**
* Creates a polymorphic [KSerializer] for the specified [baseClass] class using the specified [module].
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
@ExperimentalSerializationApi
fun <T : Any> polymorphicSerializer(baseClass: KClass<T>, module: SerializersModule): KSerializer<T> =
PolymorphicSerializer(baseClass = baseClass, module = module)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.KSerializer
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty
Expand All @@ -21,7 +20,7 @@ import kotlin.reflect.KProperty
* returns an object of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T, S : Any> StateKeeper.saveable(
serializer: KSerializer<S>,
crossinline state: (T) -> S,
Expand Down Expand Up @@ -49,7 +48,7 @@ inline fun <T, S : Any> StateKeeper.saveable(
* returns an object of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T, S : Any> StateKeeperOwner.saveable(
serializer: KSerializer<S>,
crossinline state: (T) -> S,
Expand All @@ -74,7 +73,7 @@ inline fun <T, S : Any> StateKeeperOwner.saveable(
* @param init a function returning the initial value of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T : Any> StateKeeper.saveable(
serializer: KSerializer<T>,
key: String? = null,
Expand Down Expand Up @@ -106,7 +105,7 @@ inline fun <T : Any> StateKeeper.saveable(
* @param init a function returning the initial value of type [T].
* @return [PropertyDelegateProvider] of type [T], typically used to define a delegated property.
*/
@ExperimentalEssentyApi
@ExperimentalStateKeeperApi
inline fun <T : Any> StateKeeperOwner.saveable(
serializer: KSerializer<T>,
key: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -30,7 +29,7 @@ class PolymorphicSerializerTest {
@Serializable
private data class Some2(val data: SerializableData) : Some

@OptIn(ExperimentalEssentyApi::class, ExperimentalSerializationApi::class)
@OptIn(ExperimentalStateKeeperApi::class, ExperimentalSerializationApi::class)
private object SomeSerializer : KSerializer<Some> by polymorphicSerializer(
SerializersModule {
polymorphic(Some::class) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.arkivanov.essenty.statekeeper

import com.arkivanov.essenty.utils.internal.ExperimentalEssentyApi
import kotlinx.serialization.builtins.serializer
import kotlin.test.Test
import kotlin.test.assertEquals

@OptIn(ExperimentalEssentyApi::class)
@OptIn(ExperimentalStateKeeperApi::class)
class StateKeeperExtTest {

@Test
Expand Down

0 comments on commit ae49024

Please sign in to comment.