commonMain.com.r0adkll.kimchi.annotations.MapKey.kt Maven / Gradle / Ivy
// Copyright (C) 2024 r0adkll
// SPDX-License-Identifier: Apache-2.0
package com.r0adkll.kimchi.annotations
import kotlin.reflect.KClass
/**
* Defines a key that can be used for contributing multibinding elements to a map. Annotations
* annotated with [MapKey] should have a single parameter of any type. Kimchi will then use this
* parameter type to key the map that elements annotated with [ContributesMultibinding] will be
* added to.
*
* Take this example:
* ```
* @MapKey
* annotation class ClassKey(val clazz: KClass<*>)
*
* @ClassKey(FeatureScreen::class)
* @ContributesMultibinding(AppScope::class)
* @Inject
* class FeatureInjector : Injector
*
* // Will generate this binding
* @Provides
* @IntoMap
* public fun provideFeatureInjector_FeatureScreen(
* `value`: FeatureInjector
* ): Pair, Injector> = (FeatureScreen::class to `value`)
* ```
*/
@Target(AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class MapKey
@MapKey
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class StringKey(
val value: String,
)
@MapKey
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class IntKey(
val value: Int,
)
@MapKey
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class LongKey(
val value: Long,
)
@MapKey
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
annotation class ClassKey(
val value: KClass<*>,
)