Annotation Processor, trésor caché de la JVM

Preview:

Citation preview

@rbrugier#JavaProcessor

Annotation processor, trésor caché de la JVM

@rbrugier#JavaProcessor

Annotation processor, trésor caché de la JVM

Raphaël Brugier@rbrugier

Développeur chez

Agenda

Nos utilisations

@ ?

Bien débuter

@rbrugier#JavaProcessor

Les @nnotations

@rbrugier#JavaProcessor

Compilation

@ JavacJavac

Validation

Génération

@rbrugier#JavaProcessor

Processors @LesFurets

@rbrugier#JavaProcessor

Processors @LesFurets

@rbrugier#JavaProcessor

Vs Reflection

•Code visible dans l'IDE

•Stack erreurs plus simple

•Performances

JavacJavac

ProcessorsProcessors

@rbrugier#JavaProcessor

Bien débuter

Déclaration

Extraction

Génération

@rbrugier#JavaProcessor

Annotation Processor

+

=

@rbrugier#JavaProcessor

Google @AutoService

github.com/google/auto/tree/master/service

@rbrugier#JavaProcessor

Extraction

@rbrugier#JavaProcessor

Element Un « bloc » de programme

Java.lang.reflect Java.annotation.processing

Java.lang.package PackageElement

java.lang.Class TypeElement

Constructor ExecutableElement

Method ExecutableElement

Field, Parameter VariableElement

Exemple Lister les retours des méthodes

@rbrugier#JavaProcessor

Écrire

@rbrugier#JavaProcessor

JavaPoet github.com/square/javapoet

@rbrugier#JavaProcessor

Test, Test, TEST ! github.com/google/compile-testing

Pour aller plus loin ...

« Annotation Processing Boilerplate Destruction » speakerdeck.com/jakewharton

« Writing Annotation Processors to Aid Your Development Process » 

github.com/irobertson/jpa-annotation-processor

« LesFurets MDL4UI » 

github.com/lesfurets/mdl4ui

et dagger2, AndroidAnnotations, etc

Recommended