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
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
PDF
Architecture types and enterprise applications.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
STKI Israel Market Study 2025 version august
PDF
project resource management chapter-09.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
Modernising the Digital Integration Hub
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Hybrid model detection and classification of lung cancer
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
1. Introduction to Computer Programming.pptx
TrustArc Webinar - Click, Consent, Trust: Winning the Privacy Game
Architecture types and enterprise applications.pdf
WOOl fibre morphology and structure.pdf for textiles
STKI Israel Market Study 2025 version august
project resource management chapter-09.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Modernising the Digital Integration Hub
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Hybrid model detection and classification of lung cancer
Module 1.ppt Iot fundamentals and Architecture
Zenith AI: Advanced Artificial Intelligence
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Enhancing emotion recognition model for a student engagement use case through...
DP Operators-handbook-extract for the Mautical Institute
2021 HotChips TSMC Packaging Technologies for Chiplets and 3D_0819 publish_pu...
Assigned Numbers - 2025 - Bluetooth® Document
O2C Customer Invoices to Receipt V15A.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
1. Introduction to Computer Programming.pptx

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
 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