vendredi 30 janvier 2015

Pattern for processing custom Java annotations

I have read a lot of tutorials about Java annotations lately and I like the idea of creating a custom one. Most articles cover the very basic idea and fairly simple implementations. I'm missing a proper pattern to process my annotation, though.


Lets say I have a custom annotation @Foobar to initialize fields. I need to pass all classes that use this annotation to my processor, let's call it FoobarProcessor:



public class AnnotatedClass {
@Foobar
private String test = "";

static {
FoobarProcessor.process(AnnotatedClass.class);
}
}


Is there any approach to overcome this drawback? Is there any single point that all classes pass, where I can easily apply my annotation processor?


Aucun commentaire:

Enregistrer un commentaire