Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

When you are writing your annotation in JavaDoc, you need to post-compile your classes in order to parse the sources, retrieve the JavaDoc annotations, process and validate the annotations and finally put them into the bytecode as regular Java 5 RuntimeVisible annotations.

This is done by using the backport175 compiler,

Unknown macro: {AnnotationC}

.

AnnotationC compiler

You can run

either from the command line or using the Ant task.

You invoke the compiler like this:

The last option {-config <property file(s)>} points to the (or several files separated by classpath separator - ; or : depending on you OS) property file which defines annotation aliases (or imports) by mapping the names to the fully qualified class names of the annotation interface.

Note that if you are using the {-dest} option, the anonymous inner classes will not be copied to the destination directory, since the anonymous classes are not taken into account by the annotation compiler. In such a case it is recommended to add the following (if using Ant) just after the call to

Unknown macro: {AnnotationC}

when the {-dest} option is used: (adapt according to the directories you are using)

<copy todir="classes/annotated" overwrite="false">
<fileset dir="classes/regular"/>
</copy>}

Annotation definition file

Since the annotations are written in JavaDoc, there is no way of doing imports of the annotations interfaces.
This leaves us two options:

  • either you
    You need to tell the annotation compiler which annotations you are interested in and map the name of the annotations to the annotation interface implementation.

For untyped annotations you still need to define the name of the annotation but but you can leave out the mapping to a specific interface. That is handled by the compiler and will implicitly be org.codehaus.aspectwerkz.annotation.UntypedAnnotation.

Example of an annotation properties file.

  1. Typed annotations
    Requires = test.expression.RequiresAnnotation
    Serializable = test.expression.SerializableAnnotation
  1. Untyped annotations
    loggable
    readonly

In which for example:

  • Requires is the typed @Requires annotation
  • loggable is the untyped @loggable annotation
  • No labels