Blaze CBAV (independent evaluation of constraint-based annotations) is still under development, but is already capable of some fake compile-time checking. Basically, you can use this library to add meta information to your annotations to generate compiler errors based on your own conditions.
There are several useful predefined default constraints, but you can also define your own by implementing a validator and linking it using the constraint annotation to your own constraint. The implementation of the validators must be present in compiled form inside your classpath if you want to use your own constraint, so you might want to pack it separately. Try and explore the possibilities;)
For example, you can verify that a given annotation value occurs only once within a class:
public @interface MyAnnotation{ @UniqueValueConstraint(scope=ConstraintScope.CLASS, errorMessage="This value must be unique within class level!") String value(); } public class MyClass{ @MyAnnotation("test") void test1(){} @MyAnnotation("test") void test2(){}
You can find the project on Github: https://github.com/Blazebit/blaze-cbav
Christian beikov
source share