-
Notifications
You must be signed in to change notification settings - Fork 9
Qualifier Annotation Fix #513
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
Qualifier Annotation Fix #513
Conversation
| } | ||
|
|
||
| when (val value = arg.value<Any>()) { | ||
| is KClassValue -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that we are matchin on KClassValue and EnumValue here, it seems like arg.value<Any>() won't ever return them, instead opting for giving us ClassReference and FqName.
|
I've also opened an issue for the string templates here UpdateWas fixed in square/anvil#632, so the workaround can be removed after the next Anvil release. |
- Parameterized qualifiers keep arguments - Fails to compile if no qualified value is bound.
- Use Resolved names for parameters, instead of `name` The `name` field is null if the use site did not use named arguements, causing code to be generated like ```kotlin @provides fun provides_Target( @SomeQualifier(null = "A") qualified: Provider<String> ): Target ``` - Re-escape strings and chars Literal values are given to you as the runtime value, causing the following ```kotlin class Target @VMInject(@SomeQualifier("A") qualified: String) : ViewModel() ``` to have the following generated ```kotlin @provides fun provides_Target( @SomeQualifier(value = A) qualified: Provider<String> ): Target ``` without any `A` in scope.
Anvil's PSI Parsing for AnnotationArgumentReference.Psi currently does
not fold constants within string templates correctly, instead always
taking only the first leaf node. This causes an annotation like
`@MyQualifier("Hello, $world")` to generate `@MyQualifier("Hello, ")`,
which is obviously incorrect. This could be resolved here (in a separate
PR) if desired, but it would be better to upstream the change.
See: https://github.com/square/anvil/blob/main/compiler-utils/src/main/java/com/squareup/anvil/compiler/internal/reference/AnnotationArgumentReference.kt#L267
f5617d7 to
938fd99
Compare
Currently, qualifier annotations on injected constructor params are not propagated to generated code at all.
Proposed Changes
ViewModels have this done inViewModelTangleScopeModuleGeneratorFragments have this done inContributesFragmentGeneratorandFragmentInject_ModuleGeneratorFragment_Factory_Generatoras it was being applied in a non-InjectclassWorkers have this done inAssistedWorkerFactoryGeneratorqualifierAnnotationSpecsuse the annotation reference itself to generate the annotation spec, instead of the@Qualifierit is annotated with.qualifierAnnotationSpecuseresolvedNameinstead ofnamefor argument names, asnameis null when the param is passed positionally.qualifierAnnotationSpecwrap string and char values, so that they are correctly propogatedqualifierAnnotationSpeccheck whether an argument is an interpolated string, if so kill the compilation nicely.This has to be done for now due to an oversight made in Anvil's
AnnotationArgumentReference.Psi. I left a longercomment inline, but it should be technically feasible to do the constant folding required to make templates work on
(at least) the happy path if that would be desirable. I am personally of the opinion that that kind of change should be
upstreamed to anvil though.