Question regarding type use annotation on method parameter type

Laird Nelson ljnelson at gmail.com
Thu Feb 16 00:37:41 UTC 2023


I hope this is the right list for this sort of thing and that I, a
non-compiler guy, am not wasting anyone's time. My question relates to the
javax.lang.model.* classes and the way they (do not) represent a particular
kind of type use annotation.

Consider the following contrived example, which compiles (if I've typed it
right):

@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE_USE }) // note: deliberately not PARAMETER
public @interface A {}

public final class B {
    public static final void c(@A String s) {}
}


As far as I can tell, a representation of @A does not appear in any list of
AnnotationMirrors "reachable" from an ExecutableElement, including its
backing ExecutableType and the TypeMirrors representing the parameter type
usages and so on, representing B#c(String). Should it?

A representation of @A does appear in reflection, and it seems to in
MethodSymbol, and tools like Jandex also report it in what seems to be the
proper place. See
https://stackoverflow.com/questions/75454080/where-in-the-javax-lang-model-hierarchy-is-this-type-use-annotation-recorded
for a longer writeup if that's helpful.

I am happy to provide more details but if I'm in the wrong place or missed
something obvious I wanted to keep this short.

Thanks,
Laird
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230215/da97d7fa/attachment-0001.htm>


More information about the compiler-dev mailing list