More precise annotation targets

Brian Goetz brian.goetz at oracle.com
Thu Oct 11 21:00:19 UTC 2018


That's a completely separate feature from what Arjan was proposing.

Annotations on statements is something that was considered in the 
original design of annotations, but if you think about it for a bit, 
you'll see where it runs off the road.  Where most of the pain in this 
is: how on earth would you _find_ these annotations at run time?  
Reflection only goes down to the member level.  So tied to this idea, is 
a significant upgrade to the classfile format (the VM has no concept of 
"for loop", so these language-level concepts would need to be described 
more directly in the class file, and then we'd need ways to describe 
annotations on each of them), and then a significant upgrade to 
reflection (being able to reflect over the structure of the bytecode).  
And then a way to get your hands on the actual bytecode, so that you can 
spin new bytecode / generate native code for your parallel loops.




On 10/11/2018 4:32 PM, LaMothe, Ryan R wrote:
> While I agree with Brian's comments later in this thread on the below question, I'd like to expand on the question just a little: We've always wished we could annotate for loops, while loops, etc. so that we can handle them with custom back-end code/processing (e.g. parallelism, GPU, cluster queue, etc.). Has that already been attempted/proposed or is that something we would need to propose new?
>
> ____________________________________________
> Ryan LaMothe
>
> -----Original Message-----
> From: discuss [mailto:discuss-bounces at openjdk.java.net] On Behalf Of arjan tijms
> Sent: Thursday, October 11, 2018 6:19 AM
> To: discuss <discuss at openjdk.java.net>
> Subject: More precise annotation targets
>
> Hi,
>
> I wonder if the following would make sense to consider for a Java language
> enhancement:
>
> Annotations can currently be targeted
> to TYPE, FIELD, METHOD, TYPE_PARAMETER etc.
>
> For lots of cases this is fine, but in other case you need a bit more detail. For instance, consider an @ActionEvent annotation that targets METHOD, but actually can only be applied on methods with a specific signature such as void method(Action); and void method();
>
> You might want to have correct placement of the annotation expressed in a little more exact way, like e.g.
>
> @Target(METHOD)
> @TargetMethods( {ActionInterface.class, ActionInterface2.class})
> @Retention(RUNTIME)
> public @interface ActionEvent {}
>
>
> With ActionInterface.class and ActionInterface2.class both functional classes.
>
> Alternatively:
>
> @Target(METHOD)
> @TargetMethods( {
>      @MethodSignature(
>          return=Void.class, arguments=Action.class),
>       @MethodSignature(
>          return=Void.class)}
> }
> @Retention(RUNTIME)
> public @interface ActionEvent {}
>
> The syntax used is just illustrative of the idea.
>
> Thoughts?
>
> Kind regards,
> Arjan



More information about the discuss mailing list