Annotation Processing Tool ( APT )

Started by thiruvasagamani, Sep 01, 2008, 04:30 PM

Previous topic - Next topic

thiruvasagamani

We have just seen the Utility class to handle the annotation processing. The Sun community also provide the annotation processing tool with JDK5.0. APT is a command-line utility for annotation processing. It includes a set of reflective APIs and supporting infrastructure to process program annotations These reflective APIs provide a build-time, source-based, read-only view of program structure. APT first runs annotation processors that can produce new source code and other files. Next, APT can cause compilation of both original and generated source files, thus easing the development cycle.

First, APT determines what annotations are present on the source code being operated on. Next, APT looks for annotation processor factories which user has written. The tool asks the factories what annotations they process. Then APT asks a factory to provide an annotation processor if the factory processes an annotation present in source files being operated on. Next, the annotation processors are run. If the processors have generated new source files, APT will repeat this process until no new source files are generated.

The APT specific options are:


    * -s dir -Specify the directory root under which processor-generated source files will be placed; files are placed in subdirectories based on package namespace

    * -nocompile- Do not compile source files to class files.

    * -print- Print out textual representation of specified types; perform no annotation processing or compilation.


    * -A [ key [ = val ]]- Options to pass to annotation processors -- these are not interpreted by apt directly, but are made available for use by individual processors

    * -factorypath path- Specify where to find annotation processor factories; if this option is used, the classpath is not searched for factories.

    * -factory classname- Name of AnnotationProcessorFactory to use; bypasses default discovery process

    * -d dir- Specify where to place processor and javac generated class files

    * -cp path or -classpath path- Specify where to find user class files and annotation processor factories. If -factorypath is given, the classpath is not searched for factories.


There are a few APT hidden options that may be useful for debugging:


    * -XListAnnotationTypes- List found annotation types

    * -XListDeclarations- List specified and included declarations

    * -XPrintAptRounds- Print information about initial and recursive apt rounds

    * -XPrintFactoryInfo- Print information about which annotations a factory is asked to process [/color]
Thiruvasakamani Karnan