In this article we are going to see the apt commands.

What is apt?

apt is a java annotation processor which are used in the source file using reflective API. APT stands for annotation processing tool.

This provides a build time , source based, read only view of programs structure that follows java generics.

First apt determines used annotations, then look annotation processing factories and get what annotations they process , then ask a factory to provide an annotation processor .

That creates new source code/other files. If the processors have generated new source files, apt will repeat this process until no new source files are generated.

Syntax

apt [options] [source file

apt Options :

apt accepts all javac options. Following are apt specific options.

  • s (dir) : Set root directory for generated source(sub-directories are created based on package) -nocompile : Do not compile source to class .
  • print : Prints (as text) specified types and performs no annotation processing or compilation.
  • A(key(=val)) : Key and value passing to annotation processor(Not interpreted by apt , but set for individual processors)
  • factorypath (path): Set path to find annotation processor factories(classpath is not searched for factories)
  • factory (classname) : Used Annotation Processor Factory Name

Debugging apt options :

  • XListAnnotationTypes : Shows found annotation types
  • XListDeclarations : Shows declarations
  • XPrintAptRounds : Prints initial and recursive apt rounds
  • XPrintFactoryInfo : Prints about annotations that asked a factory to process

Shared javac’s options:

  • d (dir) : Set location to place processor and javac generated classes.
  • cp/-classpath (path) : Specify where to find class files and annotation processor factories.

Use of annotation and processing :

  1. Framework implementation(annotations in a framework perform some task depend on annotations. Ex-spring, hibernate or others.)
  2. Reporting(making reports function results like Unit Test results, program output, application/function states) with different type of files.
  3. Debugging(to see inner states of the functions with annotations)
  4. Run time processing
  5. Compile time and Deploy time processing
  6. Compiler state information.

Thanks…:)