Block and Expression Annotations

joe darcy joe.darcy at oracle.com
Wed Feb 1 23:30:23 UTC 2017


Note that this kind of change, adding annotations to expressions and 
blocks, was explicitly considered and rejected as part of JSR 308: 
"Annotations on Java Types" https://jcp.org/en/jsr/detail?id=308.

The people involved in the JSR were aware of the use-cases where such 
annotations are useful.

Cheers,

-Joe


On 2/1/2017 3:04 PM, Ivan Paterno wrote:
>
> Hi all,
>
> I'm working on a change to the compiler/reflection library to handle 
> Annotation on two new ElementType: EXPRESSION and BLOCK.
>
> Here are some basic examples to explain what i mean:
>
> First on EXPRESSION annotation
>
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Target;
>
> @Target(ElementType.EXPRESSION)
> @interface Test {}
>
> public class SimpleExpression {
>
>     private int field1;
>     private static int field2;
>     private int field3 = 0;
>
>     public SimpleExpression() {
>         this.field1 = @Test() {1};
>         field2 = this.field1 + @Test() {2};
>         this.field3 = @Test() {this.field1 + @Test() {field2}};
>     }
>
> }
>
> And on BLOCK:
>
> import java.lang.annotation.ElementType;
> import java.lang.annotation.Target;
>
> @Target(ElementType.BLOCK)
> @interface Test {
>
>     String someValue() default "";
>
> }
>
> public class WhileLoop {
>
>     private int a;
>
>     public WhileLoop(int c) {
>         @Test() {
>             while (c != 0) {
>                 this.a += c;
>                 c--;
>             }
>         }
>     }
> }
>
>
> There are very basic example but i have a lot of tests added to my 
> local repository. Obviusly i need to create many others to cover the 
> various possibilities.
>
> Anybody want to help me make these tests?
>
> If someone is interested in the paper about this features, this is the 
> link:
>
> Walter Cazzola and Edoardo Vacchi, @Java: Annotations in Freedom, in 
> Proceedings of 28th Annual ACM Symposium on Applied Computing 
> (SAC'13), Coimbra, Portugal, March 2013, ACM Press
>
>
> Thanks,
>
> Ivan Paterno
>



More information about the jdk9-dev mailing list