forked from square/anvil
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make annotations-optional a KMP library (#81)
- Loading branch information
1 parent
e003fa9
commit c957242
Showing
11 changed files
with
199 additions
and
10 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
annotations-optional/src/jvmMain/kotlin/com/squareup/anvil/annotations/optional/ForScope.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,39 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import jakarta.inject.Qualifier as JakartaQualifier | ||
import javax.inject.Qualifier as JavaxQualifier | ||
import me.tatarka.inject.annotations.Qualifier as KotlinInjectQualifier | ||
|
||
/** | ||
* A class based [qualifier](Qualifier). | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define qualifier annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @ForScope(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class CommonAuthenticator @Inject constructor() : Authenticator | ||
* | ||
* @ForScope(UserScope::class) | ||
* @ContributesBinding(UserScope::class) | ||
* class UserAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
*/ | ||
@JavaxQualifier | ||
@JakartaQualifier | ||
@KotlinInjectQualifier | ||
@Retention(RUNTIME) | ||
public actual annotation class ForScope( | ||
/** | ||
* The marker that identifies the component in which the annotated object is | ||
* provided or bound in. | ||
*/ | ||
actual val scope: KClass<*>, | ||
) |
44 changes: 44 additions & 0 deletions
44
annotations-optional/src/jvmMain/kotlin/com/squareup/anvil/annotations/optional/SingleIn.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,44 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import jakarta.inject.Scope as JakartaScope | ||
import javax.inject.Scope as JavaxScope | ||
import me.tatarka.inject.annotations.Scope as KotlinInjectScope | ||
|
||
/** | ||
* Identifies a type that the injector only instantiates once for the given | ||
* [scope] marker. | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define scope annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Component example: | ||
* ``` | ||
* @SingleIn(AppScope::class) | ||
* @MergeComponent(AppScope::class) | ||
* interface AppComponent | ||
* ``` | ||
* | ||
* Contribution example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @SingleIn(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class RealAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
* | ||
* See Also: [@Scope](Scope) | ||
*/ | ||
@JavaxScope | ||
@JakartaScope | ||
@KotlinInjectScope | ||
@Retention(RUNTIME) | ||
public actual annotation class SingleIn( | ||
/** | ||
* The marker that identifies this scope. | ||
*/ | ||
actual val scope: KClass<*>, | ||
) |
35 changes: 35 additions & 0 deletions
35
...ations-optional/src/nonJvmMain/kotlin/com/squareup/anvil/annotations/optional/ForScope.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,35 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import me.tatarka.inject.annotations.Qualifier as KotlinInjectQualifier | ||
|
||
/** | ||
* A class based [qualifier](Qualifier). | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define qualifier annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @ForScope(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class CommonAuthenticator @Inject constructor() : Authenticator | ||
* | ||
* @ForScope(UserScope::class) | ||
* @ContributesBinding(UserScope::class) | ||
* class UserAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
*/ | ||
@KotlinInjectQualifier | ||
@Retention(RUNTIME) | ||
public actual annotation class ForScope( | ||
/** | ||
* The marker that identifies the component in which the annotated object is | ||
* provided or bound in. | ||
*/ | ||
actual val scope: KClass<*>, | ||
) |
40 changes: 40 additions & 0 deletions
40
...ations-optional/src/nonJvmMain/kotlin/com/squareup/anvil/annotations/optional/SingleIn.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,40 @@ | ||
package com.squareup.anvil.annotations.optional | ||
|
||
import kotlin.annotation.AnnotationRetention.RUNTIME | ||
import kotlin.reflect.KClass | ||
import me.tatarka.inject.annotations.Scope as KotlinInjectScope | ||
|
||
/** | ||
* Identifies a type that the injector only instantiates once for the given | ||
* [scope] marker. | ||
* | ||
* This can be used in combination with other Anvil annotations to avoid having | ||
* to manually define scope annotations for each component and to maintain | ||
* consistency. | ||
* | ||
* Component example: | ||
* ``` | ||
* @SingleIn(AppScope::class) | ||
* @MergeComponent(AppScope::class) | ||
* interface AppComponent | ||
* ``` | ||
* | ||
* Contribution example: | ||
* ``` | ||
* interface Authenticator | ||
* | ||
* @SingleIn(AppScope::class) | ||
* @ContributesBinding(AppScope::class) | ||
* class RealAuthenticator @Inject constructor() : Authenticator | ||
* ``` | ||
* | ||
* See Also: [@Scope](Scope) | ||
*/ | ||
@KotlinInjectScope | ||
@Retention(RUNTIME) | ||
public actual annotation class SingleIn( | ||
/** | ||
* The marker that identifies this scope. | ||
*/ | ||
actual val scope: KClass<*>, | ||
) |
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