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

« Previous Version 7 Next »

Introduction

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, AnnotationC.

AnnotationC compiler

You can run AnnotationC 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 AnnotationC when the -dest option is used: (adapt according to the directories you are using)

Annotation definition file

Since the annotations are written in JavaDoc, there is no way of doing imports of the annotations interfaces.

This leaves you two options:

  • either you use the fully qualified name of the annotation interface when writing the the annotations, e.g.:
    which can be a bit verbose and cumbersome in the long run.
  • or you define aliases (shortcuts/abbreviations), for the annotations and map these to the fully qualified class names for the annotation interfaces. This is done using the annotations.properties file.
    Example:
    If we now feed this property file to the compiler we are able to write the annotations like this instead:

The choice is yours, we are just providing an option to the FQN way of writing.

  • No labels