Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support explicit API mode for complex map keys #736

Merged
merged 2 commits into from
Aug 3, 2023
Merged

Support explicit API mode for complex map keys #736

merged 2 commits into from
Aug 3, 2023

Conversation

bddckr
Copy link
Contributor

@bddckr bddckr commented Jul 30, 2023

Resolves #735

@CLAassistant
Copy link

CLAassistant commented Jul 30, 2023

CLA assistant check
All committers have signed the CLA.

@bddckr bddckr changed the title Show that complex map keys aren't supported with explicit API mode yet Support explicit API mode for complex map keys Jul 30, 2023
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why this is needed now and not before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tl;dr: Dagger only creates the annotation creator class for the map key when @MapKey(unwrapValue = false) is used.

As seen in that link, when unwrapValue = true, it uses UnwrappedMapKeyGenerator instead, which doesn't use @AutoAnnotation.


Just to clarify:

Without

implementation libs.auto.value.annotations
kapt libs.auto.value.processor

we get

> Task :integration-tests:library:kaptKotlin
C:\Projects\anvil\integration-tests\library\build\tmp\kapt3\stubs\main\com\squareup\anvil\test\WrappedBindingKey.java:6: error: @AutoAnnotation is a necessary dependency if @MapKey(unwrapValue = false). Add a dependency for the annotation, "com.google.auto.value:auto-value-annotations:<current version>", and the annotation processor, "com.google.auto.value:auto-value:<current version>"
public abstract @interface WrappedBindingKey {
                 ^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the extra context 👍

@@ -178,6 +178,7 @@ internal class MapKeyCreatorGenerator : PrivateCodeGenerator() {
className,
properties.entries.map { it.value.callExpression }.joinToCode()
)
.returns(className)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, coincidentally this is also needed for upgrading to newer KotlinPoet versions

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the extra context 👍

@JoelWilcox JoelWilcox merged commit 6538b2c into square:main Aug 3, 2023
19 checks passed
@bddckr bddckr deleted the fix/complex-map-key-explicit-api branch August 3, 2023 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Annotation with @MapKey(unwrapValue = false) ("complex map key") doesn't support explicit API mode
4 participants