Actually I'm using a self written annotations processor in a big J2EE project. Besides others I found following annotations usefull enough to be defined as standard ones:
- First: The counterpart to java.lang.Override.
This annotation takes no value.
Annotating a class by First results in a compiletime error for each
method which overrides a non-abstract superclass method if the overwriting
method is not annotated by java.lang.Override. Interfaces are not
allowed to be annotated by First.
This is usefull to ensure not to accidently overwrite a superclass method
without having thought about. E.g. one team member edits the superclass,
the other the subclass.
- Implement: Annotation to mark methods that they have
to be the implementation of a method of an interface implemented
by the declaring class or of an interface implemented by one of its
superclasses. This annotation takes no parameters.
This is usefull especially on application level to locate methods which have
become obsolete. The Implement annotation is similar to
java.lang.Override with the difference it supports interface methods.
- MandatoryConstructor: Annotation to mark classes that
their non-abstract subclasses must declare a specific constructor. This
annotation takes an array of classes as parameters to describe the
constructor's parameter types.
This is usefull for conventions relying on Java reflection.
- A quiet complex package allows development of MBeans using runtime
processed annotations. The annotations allow to define descriptions for
MBean attributes and operation parameters, as well as a default JNDI name
and some other stuff.
A compile time processor ensures the annotations are used correctly. A
runtime processor produces the DynamicMBean info.
The MBeanInfo could theoretically also be generated at compilation time, but
currently I've not found a way to manipulate source code without to tamper
the information about source code position in stacktraces of exceptions. I am
not willing to loose this debug info.
I also have no control over the classloader, thus I can not use bytecode
instrumentation.
The feature I'm missing most in Apt is to process annotations of local variables. More precisely I would like to process every item of source files, such that I could not only process annotations but collect any information I want to. E.g. to check code conventions.
I also miss a way to generate code without having to write the whole file. Java should have a standard API to manipulate the AST tree.
Posted by: joergwassmer on March 29, 2005 at 08:31 AM