Block and Expression Annotations
Ivan Paterno
ivan.paterno.mailinglist at gmail.com
Wed Feb 1 23:04:44 UTC 2017
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