Annotation processors

Joseph D. Darcy Joe.Darcy at Sun.COM
Fri Apr 3 10:07:37 PDT 2009


Mark Thornton wrote:
> These have come up several times on this list. I suspect many people 
> have only a vague idea of what they can do. Is there any good 
> documentation or introductory material available?
>
> Mark Thornton
>
>   

The annotation processing in javac provides immutable data structures 
modeling the types in question.  However, much of the power of providing 
mutable source files can be had by either using an annotation processor 
to generate subclasses of a class or the *superclass* of a class.  Those 
capabilities are mandated for JSR 269 annotation processing frameworks, 
as implemented in javac and Eclipse.

For example, @MakeMeAPropertyInMySuperclass annotations could be used to 
automatically generate at build time the desired property structure that 
could be inherited.  It is technically possible (a small matter of 
programming ;-) to run

@MakeMeAPropertyInMySuperclass(name="foo",type=Type.class)
class Foo extends ToBeGenerated {}

into something like

class ToBeGenerated {
    private Type foo;
    Type getFoo() {
       return foo;
    }

    Type setFoo(Type type) {
       this.type = type;
       return this.type;
    }
}

Bruce Chapman has written interesting annotation processors as part of 
his rapt and hickory projects:

https://rapt.dev.java.net/
https://hickory.dev.java.net/

-Joe




More information about the coin-dev mailing list