Uses directive not visible in annotation processor when provider class not existing (yet)
Michał Kłeczek
michal at kleczek.org
Thu Dec 1 16:42:35 UTC 2022
Hi Jan,
Thanks for a quick response.
I am afraid I am not knowledgeable enough to tell how it might be implemented but the common pattern in annotation processors is to generate non-existing classes that are already used in the source code, ex:
@Immutable.Value
Interface MyImmutable extends WithMyImmutable { //WithMyImmutable is generated by annotation processor
}
I understand the difference is that in this case annotation processor doesn’t actually need to get the extended interface name but assumes the programmer follows a certain naming convention.
In my case I could extend the module annotation with an attribute containing some metadata used to generate classes. But that would require specifying them twice: in the annotation and in the actual provides directive.
From what I understand it is not easy to achieve without major API change. Will need to find a workaround then :)
Thanks,
Michal
> On 1 Dec 2022, at 16:45, Jan Lahoda <jan.lahoda at oracle.com> wrote:
>
> Hi Michal,
>
>
>
> The provides directive returns TypeElement as the service and a list of TypeElements as the implementations, and I don't think we can reasonably model non-existing types as TypeElements (normally missing types are modeled as erroneous TypeMirrors, I believe). So, having the non-existent implementation listed in the directive is probably difficult. Currently, when there are no implementations, the directive is skipped altogether - it might be possible to change that, although I am not sure if that would be helpful (as the non-existent type would not be in the directive anyway).
>
>
>
> Overall, I wonder how exactly is this meant to work. Using the (javac-specific) AST, one could get the (qualified) name that refers to the type that does not exist, but that may be a simple name, and depend on an import, so the correct FQN must be inferable somehow?
>
>
>
> Thanks,
>
> Jan
>
>
>
> On 01. 12. 22 9:24, Michał Kłeczek wrote:
>> Hi,
>>
>> I am implementing an annotation processor that (among other things) is supposed to generate service provider classes that delegate calls to beans from a Spring application context.
>>
>> The idea is to mark a module in module-info with an annotation and add “provides Service with Implementation” where Implementation is not existent (yet).
>> Unfortunately it seems ModuleElement.getDirectives() does not return such a provides directive.
>>
>> Is it a bug or I am missing something?
>>
>> Thanks,
>> Michal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20221201/0ad768c8/attachment-0002.htm>
More information about the compiler-dev
mailing list