SlideShare a Scribd company logo
ANNOTATION PROCESSING
HOW IT WORKS
ANNOTATION PROCESSING
A BIT OF HISTORY
▸ Were first introduced in Java Language with the third
edition of the Java Language Specification (JLS)
▸ And introduced in Java 5
ANNOTATION PROCESSING
WHAT IS?
▸ Annotation processing lets you generate new Java files at
build time.
▸ There is no need to use reflection. Although the generated
Java files can use reflection, if you wish.
▸ Just cause performance degradation on build time.
ANNOTATION PROCESSING
HOW CAN I DO
▸ Android Studio doesn’t have build in support for
annotation processing.
▸ You need to use the android-apt Gradle plugin for your
compile code as build time dependency without including
it in the final apk.
ANNOTATION PROCESSING
▸ First: In your project's build.gradle you should use
▸ Second: Create a module Compiler
▸ Third: App’s build.gradle
ANNOTATION PROCESSING
▸ Finally: The compiler’s build.gradle
▸ plugin java instead plugin android. After all, this code
going to run on the machine. Note on an Android.
ANNOTATION PROCESSING
ABSTRACT PROCESSOR
▸ AbstractProcessor. Let’s have a look at the Processor API.
ANNOTATION PROCESSING
THE PROCESSOR IT SELF
▸ void init (ProcessingEnvironment)
▸ All annotation processor must have a empty constructor!
▸ This is special init() which is invoked by the annotation
processing tool
ANNOTATION PROCESSING
THE PROCESSOR IT SELF
▸ boolean process(Set<? extends TypeElement>
annotations, RoundEnvironment env)
▸ This is kind of main() method of each processor
▸ Here you write code for spanning, processing annotation
and generating java files.
ANNOTATION PROCESSING
LIVE CODE
▸ Let’s generate automatic getter for
our fields.
ANNOTATION PROCESSING
OK, SHOW ME EXEMPLES
MUCH MORE…
ANNOTATION PROCESSING
ABOUT ME
▸ Felipe Theodoro Gonçalves

Android Developer at Elo7



@ftgoncalves

ftgoncalves@gmail.com
▸ Slack

Android Dev BR / Android Study Group
http://brianattwell.com/android-annotation-
processing-pojo-string-generator/
http://hannesdorfmann.com/annotation-
processing/annotationprocessing101
Referências

More Related Content

ODP
Hot Reloading with React - Experiences
PDF
sitMUC 2018 - Speed up abap-unit data creation process
ODP
Gopenflow demo v1 (english)
PDF
The absolute must read book for programmers
PDF
Porting golang development environment developed with golang
PPTX
Live development & tools
PDF
2013-03-07 indie developer toolkit
PDF
Creative Hacking: Delivering React Native App A/B Testing Using CodePush
Hot Reloading with React - Experiences
sitMUC 2018 - Speed up abap-unit data creation process
Gopenflow demo v1 (english)
The absolute must read book for programmers
Porting golang development environment developed with golang
Live development & tools
2013-03-07 indie developer toolkit
Creative Hacking: Delivering React Native App A/B Testing Using CodePush

What's hot (20)

PPTX
Github developing stack
PDF
Benefits of using Flutter
PDF
Coffee script part 2
PDF
Front matter: Next Level Front End Deployments on OpenShift
PPTX
AngularJS to React
PDF
Future of Mobile Automation, Appium Steals it
PDF
20160929 android taipei_tensorflow
PDF
Android Wear Code Lab
PPTX
Git in 10 minutes (WordCamp Europe 2017)
PDF
Node & Express as Workflow Tools
PDF
Embracing the Change: How to Win with Gutenberg
PDF
Design for gutenberg
PDF
Golang Microservices meetup
PDF
React Typescript for beginners: Translator app with Microsoft cognitive services
PPT
Getting Started with Android
PDF
Google IO Extended 2018 Codelabs - Google Developer Philippines
PDF
Owasp Juice Shop: Achieving sustainability for open source projects
PPTX
Cheap ci for javascript devs
PDF
OWASP Juice Shop 5.x and beyond
PDF
GraphQL Codegen - NNG Technical Seminar
Github developing stack
Benefits of using Flutter
Coffee script part 2
Front matter: Next Level Front End Deployments on OpenShift
AngularJS to React
Future of Mobile Automation, Appium Steals it
20160929 android taipei_tensorflow
Android Wear Code Lab
Git in 10 minutes (WordCamp Europe 2017)
Node & Express as Workflow Tools
Embracing the Change: How to Win with Gutenberg
Design for gutenberg
Golang Microservices meetup
React Typescript for beginners: Translator app with Microsoft cognitive services
Getting Started with Android
Google IO Extended 2018 Codelabs - Google Developer Philippines
Owasp Juice Shop: Achieving sustainability for open source projects
Cheap ci for javascript devs
OWASP Juice Shop 5.x and beyond
GraphQL Codegen - NNG Technical Seminar
Ad

Viewers also liked (8)

PDF
Java Annotation Processing: A Beginner Walkthrough
PDF
RxJava - Programação assíncrona para Android.
PDF
Don't reinvent the wheel, use libraries
PPTX
Евгений Сатуров. Firebase в Android-разработке: основные возможности. РИФ-Вор...
PDF
ButterKnife
PPTX
Annotation processing
PDF
Annotation Processing in Android
PDF
Annotation processing in android
Java Annotation Processing: A Beginner Walkthrough
RxJava - Programação assíncrona para Android.
Don't reinvent the wheel, use libraries
Евгений Сатуров. Firebase в Android-разработке: основные возможности. РИФ-Вор...
ButterKnife
Annotation processing
Annotation Processing in Android
Annotation processing in android
Ad

Similar to Annotation processing (20)

PPTX
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
PDF
Gwt and JSR 269's Pluggable Annotation Processing API
PPTX
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
PDF
Infinum Android Talks #02 - How to write an annotation processor in Android
PPTX
Dive in Annotation Processor
PPTX
Annotation processor and compiler plugin
PDF
Android: Dive in KAPT
PDF
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
PDF
Write code that writes code!
PDF
Annotation Processing
PDF
On Processors, Compilers and @Configurations
PPTX
Java Custom Annotations- Part1
PDF
Daggerate your code - Write your own annotation processor
PDF
Custom Annotations in Java with Project Lombok
PPTX
Java Annotations
KEY
Xtend - A Language Made for Java Developers
PPSX
Java annotations
PDF
Writing Android Libraries
PDF
Jvm internals
PPTX
Java annotations
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
Gwt and JSR 269's Pluggable Annotation Processing API
JavaOne 2014 - CON2013 - Code Generation in the Java Compiler: Annotation Pro...
Infinum Android Talks #02 - How to write an annotation processor in Android
Dive in Annotation Processor
Annotation processor and compiler plugin
Android: Dive in KAPT
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code!
Annotation Processing
On Processors, Compilers and @Configurations
Java Custom Annotations- Part1
Daggerate your code - Write your own annotation processor
Custom Annotations in Java with Project Lombok
Java Annotations
Xtend - A Language Made for Java Developers
Java annotations
Writing Android Libraries
Jvm internals
Java annotations

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mushroom cultivation and it's methods.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
cloud_computing_Infrastucture_as_cloud_p
Building Integrated photovoltaic BIPV_UPV.pdf
Approach and Philosophy of On baking technology
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mushroom cultivation and it's methods.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Tartificialntelligence_presentation.pptx
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25-Week II
Assigned Numbers - 2025 - Bluetooth® Document
Empathic Computing: Creating Shared Understanding
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Advanced methodologies resolving dimensionality complications for autism neur...
cloud_computing_Infrastucture_as_cloud_p

Annotation processing

  • 2. ANNOTATION PROCESSING A BIT OF HISTORY ▸ Were first introduced in Java Language with the third edition of the Java Language Specification (JLS) ▸ And introduced in Java 5
  • 3. ANNOTATION PROCESSING WHAT IS? ▸ Annotation processing lets you generate new Java files at build time. ▸ There is no need to use reflection. Although the generated Java files can use reflection, if you wish. ▸ Just cause performance degradation on build time.
  • 4. ANNOTATION PROCESSING HOW CAN I DO ▸ Android Studio doesn’t have build in support for annotation processing. ▸ You need to use the android-apt Gradle plugin for your compile code as build time dependency without including it in the final apk.
  • 5. ANNOTATION PROCESSING ▸ First: In your project's build.gradle you should use ▸ Second: Create a module Compiler ▸ Third: App’s build.gradle
  • 6. ANNOTATION PROCESSING ▸ Finally: The compiler’s build.gradle ▸ plugin java instead plugin android. After all, this code going to run on the machine. Note on an Android.
  • 7. ANNOTATION PROCESSING ABSTRACT PROCESSOR ▸ AbstractProcessor. Let’s have a look at the Processor API.
  • 8. ANNOTATION PROCESSING THE PROCESSOR IT SELF ▸ void init (ProcessingEnvironment) ▸ All annotation processor must have a empty constructor! ▸ This is special init() which is invoked by the annotation processing tool
  • 9. ANNOTATION PROCESSING THE PROCESSOR IT SELF ▸ boolean process(Set<? extends TypeElement> annotations, RoundEnvironment env) ▸ This is kind of main() method of each processor ▸ Here you write code for spanning, processing annotation and generating java files.
  • 10. ANNOTATION PROCESSING LIVE CODE ▸ Let’s generate automatic getter for our fields.
  • 11. ANNOTATION PROCESSING OK, SHOW ME EXEMPLES MUCH MORE…
  • 12. ANNOTATION PROCESSING ABOUT ME ▸ Felipe Theodoro Gonçalves
 Android Developer at Elo7
 
 @ftgoncalves
 [email protected] ▸ Slack
 Android Dev BR / Android Study Group http://brianattwell.com/android-annotation- processing-pojo-string-generator/ http://hannesdorfmann.com/annotation- processing/annotationprocessing101 Referências