Skip to content

Conversation

@RBusarow
Copy link
Contributor

@RBusarow RBusarow commented Mar 27, 2024

We have a good deal of logic around parsing out the primitive values of const parameters, but that logic is not recursive. So, if a const references another const in its initializer, we wound up just copying the text of that initializer into the generated annotations, as though it's just a String. This problem was isolated to the PSI side of parsing, since the Descriptor APIs are able to parse out the final, primitive value. Our type resolution logic always defaults to the PSI models.

Now, when we need to parse out the primitive values from a PropertyReference, we first try to resolve the Descriptor version with a PropertyDescriptor. That isn't possible if the annotation is referencing a const property that was generated in the same round of compilation. In that event, the parsing will fall back to the PSI models. Anvil doesn't actually generate a const and then use it in an annotation, so this seems like a reasonable compromise.

fixes #938

@RBusarow RBusarow force-pushed the rick/annotation-const-refs branch from 14656bc to 53093dd Compare March 27, 2024 21:46
@RBusarow RBusarow force-pushed the rick/annotation-const-refs branch from 53093dd to 1d7207e Compare March 27, 2024 22:01
@RBusarow RBusarow marked this pull request as ready for review March 27, 2024 22:17
@RBusarow RBusarow enabled auto-merge March 28, 2024 13:02
…arguments

We have a good deal of logic around parsing out the primitive values of `const`
parameters, but that logic is not recursive.
So, if a `const` references another `const` in its initializer, we wound up
just copying the text of that initializer into the generated annotations,
as though it's just a String.
This problem was isolated to the PSI side of parsing,
since the Descriptor APIs are able to parse out the final, primitive value.
Our type resolution logic always defaults to the PSI models.

Now, when we need to parse out the primitive values from a `PropertyReference`,
we first try to resolve the Descriptor version with a `PropertyDescriptor`.
That isn't possible if the annotation is referencing a `const`
property that was generated in the same round of compilation.
In that event, the parsing will fall back to the PSI models.
Anvil doesn't actually generate a `const`
and then use it in an annotation, so this seems like a reasonable compromise.

fixes #938
@RBusarow RBusarow force-pushed the rick/annotation-const-refs branch from 1d7207e to 1741c56 Compare March 28, 2024 13:02
@RBusarow RBusarow merged commit 97e2cc0 into main Mar 28, 2024
@RBusarow RBusarow deleted the rick/annotation-const-refs branch March 28, 2024 13:17
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.

@ContributesMultibinding codegen missing imports for synthesized annotation constants

3 participants