Skip to content

Commit

Permalink
Support explicit API mode for complex map keys (#736)
Browse files Browse the repository at this point in the history
* Support explicit API mode for complex map keys
  • Loading branch information
bddckr authored Aug 3, 2023
1 parent 81053bc commit 6538b2c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ internal class MapKeyCreatorGenerator : PrivateCodeGenerator() {
className,
properties.entries.map { it.value.callExpression }.joinToCode()
)
.returns(className)
.build()
}
}
Expand Down
4 changes: 4 additions & 0 deletions integration-tests/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ if (libs.versions.config.generateDaggerFactoriesWithAnvil.get().toBoolean()) {

dependencies {
kapt libs.dagger2.compiler

// Necessary because this is what dagger uses when it runs to support instantiating annotations at runtime
implementation libs.auto.value.annotations
kapt libs.auto.value.processor
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ public object MapBinding2 : ParentType
@ContributesMultibinding(AppScope::class)
@BindingKey("3")
public object MapBinding3 : ParentType

@MapKey(unwrapValue = false)
public annotation class WrappedBindingKey(val value: String)

@ContributesMultibinding(AppScope::class, ignoreQualifier = true)
@Named("def")
@WrappedBindingKey("1")
public object WrappedMapBinding1 : ParentType

@ContributesMultibinding(AppScope::class)
@Named("def")
@WrappedBindingKey("2")
public object WrappedMapBinding2 : ParentType

@ContributesMultibinding(AppScope::class)
@WrappedBindingKey("3")
public object WrappedMapBinding3 : ParentType
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ internal class MergeComponentTest {

assertThat(appComponent.mapBindings()).containsExactly("1", MapBinding1, "3", MapBinding3)
assertThat(appComponent.mapBindingsNamed()).containsExactly("2", MapBinding2)
assertThat(appComponent.mapBindingsWrapped()).containsExactly(
WrappedBindingKey("1"),
WrappedMapBinding1,
WrappedBindingKey("3"),
WrappedMapBinding3
)
assertThat(appComponent.mapBindingsWrappedNamed()).containsExactly(
WrappedBindingKey("2"),
WrappedMapBinding2
)
}

@Test fun `the binding with the highest priority is bound`() {
Expand All @@ -75,6 +85,8 @@ internal class MergeComponentTest {
fun parentTypes(): Set<ParentType>
fun mapBindings(): Map<String, ParentType>
@Named("abc") fun mapBindingsNamed(): Map<String, ParentType>
fun mapBindingsWrapped(): Map<WrappedBindingKey, ParentType>
@Named("def") fun mapBindingsWrappedNamed(): Map<WrappedBindingKey, ParentType>
fun priorityBinding(): PriorityBinding
}

Expand Down

0 comments on commit 6538b2c

Please sign in to comment.