Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CUSTOM ANNOTATION PROCESSORS FOR YOUR PRODUCTION CODE

CUSTOM ANNOTATION PROCESSORS FOR YOUR PRODUCTION CODE

The annotation processing tool (APT) was released into the JDK 5, but we did not put enough attention to it in order to exploit its potential. Today, annotation processors are part of many well known libraries that we use everyday in our professional code. On this talk we will learn how to code our custom annotation processor and to start looking at it as a very useful tool to reduce overhead in our production code. Because many recurrent problems could get solved using annotation processors!

Jorge Castillo

October 22, 2016
Tweet

More Decks by Jorge Castillo

Other Decks in Programming

Transcript

  1. Added in JDK 5 APT and Rich public API on

    JDK 6 Standardized through JSR 269
  2. Reflective APIs: 1. Standard (Java Reflection API) 2. Mirror based

    ones (Java Mirror API) ObjectMirror carMirror = Reflection.reflect(myCar);
  3. 1. divide your library in separate modules (compiler, public api)

    2. include other libraries just for compile time (provided) 3. war plugin for pure java modules public final recommendations {
  4. • AutoService https://github.com/google/auto/tree/master/service • Truth https://github.com/google/truth • Compile-Testing https://github.com/google/compile-testing •

    JavaPoet https://github.com/square/javapoet • Great threads about creating your custom processor http://hannesdorfmann.com/annotation-processing/annotationprocessing101 • https://deors.wordpress.com/2011/09/26/annotation-types/ https://deors.wordpress.com/2011/10/08/annotation-processors/ https://deors.wordpress.com/2011/10/31/annotation-generators/ • Some official (SUN) info about both types of reflective APIs http://bracha.org/mirrors.pdf Resources and recommended reads