Submit Search
Upload
Annotations Processor Tools (APT)
•
4 likes
•
1,508 views
Txus Ballesteros Martín
Follow
My presentation about Annotations Processor Tool on Droidcon Spain 2015.
Read less
Read more
Technology
Report
Share
Report
Share
1 of 29
Download now
Download to read offline
Recommended
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
Rakesh Waghela
Java Annotations
Java Annotations
Serhii Kartashov
On Parameterised Types and Java Generics
On Parameterised Types and Java Generics
Yann-Gaël Guéhéneuc
Java Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
C# Generics
C# Generics
Rohit Vipin Mathews
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio
Scoping Tips and Tricks
Scoping Tips and Tricks
Sebastian Zarnekow
Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
Recommended
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
Rakesh Waghela
Java Annotations
Java Annotations
Serhii Kartashov
On Parameterised Types and Java Generics
On Parameterised Types and Java Generics
Yann-Gaël Guéhéneuc
Java Generics - by Example
Java Generics - by Example
Ganesh Samarthyam
C# Generics
C# Generics
Rohit Vipin Mathews
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 3)
Binary Studio
Scoping Tips and Tricks
Scoping Tips and Tricks
Sebastian Zarnekow
Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
Generics collections
Generics collections
Yaswanth Babu Gummadivelli
Test-Driven Development of Xtext DSLs
Test-Driven Development of Xtext DSLs
meysholdt
Java best practices
Java best practices
Ray Toal
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
dschaefer
Prospector Osq 2004 Final
Prospector Osq 2004 Final
kurniawan.kuga
Introduction to Intermediate Java
Introduction to Intermediate Java
Philip Johnson
Java Tut1
Java Tut1
guest5c8bd1
Oop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
Javascript basic course
Javascript basic course
Tran Khoa
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
Java 8 features
Java 8 features
NexThoughts Technologies
Modern C++
Modern C++
Richard Thomson
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
university of education,Lahore
Annotation processing
Annotation processing
Florent Champigny
Aspect oriented programming_with_spring
Aspect oriented programming_with_spring
Guo Albert
Annotation Processing in Android
Annotation Processing in Android
emanuelez
Java Annotation
Java Annotation
karthik.tech123
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
Aspect oriented programming with spring
Aspect oriented programming with spring
Sreenivas Kappala
More Related Content
What's hot
Generics collections
Generics collections
Yaswanth Babu Gummadivelli
Test-Driven Development of Xtext DSLs
Test-Driven Development of Xtext DSLs
meysholdt
Java best practices
Java best practices
Ray Toal
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
dschaefer
Prospector Osq 2004 Final
Prospector Osq 2004 Final
kurniawan.kuga
Introduction to Intermediate Java
Introduction to Intermediate Java
Philip Johnson
Java Tut1
Java Tut1
guest5c8bd1
Oop2011 actor presentation_stal
Oop2011 actor presentation_stal
Michael Stal
Javascript basic course
Javascript basic course
Tran Khoa
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Michael Stal
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Michael Stal
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
Raffi Khatchadourian
Java 8 features
Java 8 features
NexThoughts Technologies
Modern C++
Modern C++
Richard Thomson
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
university of education,Lahore
What's hot
(16)
Generics collections
Generics collections
Test-Driven Development of Xtext DSLs
Test-Driven Development of Xtext DSLs
Java best practices
Java best practices
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Binary Studio Academy PRO: ANTLR course by Alexander Vasiltsov (lesson 4)
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
Prospector Osq 2004 Final
Prospector Osq 2004 Final
Introduction to Intermediate Java
Introduction to Intermediate Java
Java Tut1
Java Tut1
Oop2011 actor presentation_stal
Oop2011 actor presentation_stal
Javascript basic course
Javascript basic course
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
Qcon2011 functions rockpresentation_f_sharp
Qcon2011 functions rockpresentation_f_sharp
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
Java 8 features
Java 8 features
Modern C++
Modern C++
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
Similar to Annotations Processor Tools (APT)
Annotation processing
Annotation processing
Florent Champigny
Aspect oriented programming_with_spring
Aspect oriented programming_with_spring
Guo Albert
Annotation Processing in Android
Annotation Processing in Android
emanuelez
Java Annotation
Java Annotation
karthik.tech123
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Ian Robertson
Aspect oriented programming with spring
Aspect oriented programming with spring
Sreenivas Kappala
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
Mahfuz Islam Bhuiyan
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
Martijn Blankestijn
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
deepakazad
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
DroidConTLV
Write code that writes code!
Write code that writes code!
Jason Feinstein
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
Guilherme Blanco
Ejb3 Dan Hinojosa
Ejb3 Dan Hinojosa
Dan Hinojosa
Introducing Struts 2
Introducing Struts 2
wiradikusuma
Cloud native programming model comparison
Cloud native programming model comparison
Emily Jiang
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
CODE WHITE GmbH
Java 8 Feature Preview
Java 8 Feature Preview
Jim Bethancourt
S313937 cdi dochez
S313937 cdi dochez
Jerome Dochez
比XML更好用的Java Annotation
比XML更好用的Java Annotation
javatwo2011
Annotation processing in android
Annotation processing in android
Zhe-Hao Hu
Similar to Annotations Processor Tools (APT)
(20)
Annotation processing
Annotation processing
Aspect oriented programming_with_spring
Aspect oriented programming_with_spring
Annotation Processing in Android
Annotation Processing in Android
Java Annotation
Java Annotation
Lambda Chops - Recipes for Simpler, More Expressive Code
Lambda Chops - Recipes for Simpler, More Expressive Code
Aspect oriented programming with spring
Aspect oriented programming with spring
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
NLJUG University Sessie: Java Reborn, Powered by Ordina
NLJUG University Sessie: Java Reborn, Powered by Ordina
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code!
Write code that writes code!
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
IPC2010SE Doctrine2 Enterprise Persistence Layer for PHP
Ejb3 Dan Hinojosa
Ejb3 Dan Hinojosa
Introducing Struts 2
Introducing Struts 2
Cloud native programming model comparison
Cloud native programming model comparison
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java Deserialization Vulnerabilities - The Forgotten Bug Class (RuhrSec Edition)
Java 8 Feature Preview
Java 8 Feature Preview
S313937 cdi dochez
S313937 cdi dochez
比XML更好用的Java Annotation
比XML更好用的Java Annotation
Annotation processing in android
Annotation processing in android
Recently uploaded
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Rafal Los
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Neo4j
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
RTylerCroy
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Product Anonymous
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
hans926745
Evaluating the top large language models.pdf
Evaluating the top large language models.pdf
ChristopherTHyatt
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
HampshireHUG
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Safe Software
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Drew Madelung
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
sudhanshuwaghmare1
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Martijn de Jong
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Maria Levchenko
Recently uploaded
(20)
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
🐬 The future of MySQL is Postgres 🐘
🐬 The future of MySQL is Postgres 🐘
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
Evaluating the top large language models.pdf
Evaluating the top large language models.pdf
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Annotations Processor Tools (APT)
1.
Annotation Processing Tools 101
2.
Txus Ballesteros @txusballesteros Rubén Serrano @akelael
3.
Agenda 1. Annotation Processing
Tool 2. Discusión 3. Caso práctico
4.
¿Qué es eso
de APT?
5.
public @interface DummyAnnotiation
{} Anotación
6.
Retención • Constructor • Atributo •
Variable • Método • Parámetro • Etc. • Source • Class • Runtime Objetivo
7.
Anotación @Retention(CLASS) @Target(FIELD) public @interface
InjectView { int value(); }
8.
Runtime Class tiene la
magia: • getAnnotation(Class<T> annotationType) • getAnnotations() • getDeclaredAnnotations() • isAnnotationPresent(Class<T> annotationType)
9.
Mirror API http://docs.oracle.com/javase/1.5.0/docs/guide/apt/mirror/overview-summary.html
10.
Discusión
11.
Caso Práctico
12.
Android Transformer https://github.com/txusballesteros/android-transformer
13.
Creando Anotaciones @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public @interface
Mappable { Class<?> with(); }
14.
Creando Anotaciones @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public @interface
Mappable { Class<?> with(); }
15.
Configurando las Anotaciones @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public
@interface Mappable { Class<?> with(); }
16.
Configurando las Anotaciones @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) public
@interface Mappable { Class<?> with(); }
17.
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedAnnotationTypes({ "com.mobandme.android.transformer.compiler.Mapping", "com.mobandme.android.transformer.compiler.Mappable", "com.mobandme.android.transformer.compiler.Parse" }) public class AnnotationsProcessor
extends AbstractProcessor { RoundEnvironment roundEnvironment; Map<String, MapperInfo> mappersList; @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return true; } Creando el Procesador
18.
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedAnnotationTypes({ "com.mobandme.android.transformer.compiler.Mapping", "com.mobandme.android.transformer.compiler.Mappable", "com.mobandme.android.transformer.compiler.Parse" }) public class AnnotationsProcessor
extends AbstractProcessor { RoundEnvironment roundEnvironment; Map<String, MapperInfo> mappersList; @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return true; } Creando el Procesador
19.
@SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedAnnotationTypes({ "com.mobandme.android.transformer.compiler.Mapping", "com.mobandme.android.transformer.compiler.Mappable", "com.mobandme.android.transformer.compiler.Parse" }) public class AnnotationsProcessor
extends AbstractProcessor { RoundEnvironment roundEnvironment; Map<String, MapperInfo> mappersList; @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return true; } Configurando el Procesador
20.
Implementando el Procesador @SupportedSourceVersion(SourceVersion.RELEASE_7) @SupportedAnnotationTypes({ "com.mobandme.android.transformer.compiler.Mapping", "com.mobandme.android.transformer.compiler.Mappable", "com.mobandme.android.transformer.compiler.Parse" }) public
class AnnotationsProcessor extends AbstractProcessor { RoundEnvironment roundEnvironment; Map<String, MapperInfo> mappersList; @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { return true; }
21.
Implementando el Procesador private
void processMappedAnnotationElements() { Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Mapped.class); for (Element mappedElement : elements) { if (mappedElement.getKind() == ElementKind.FIELD) { Mapped mappedAnnotation = mappedElement.getAnnotation(Mapped.class); String toFieldName = mappedAnnotation.toField(); } } }
22.
Implementando el Procesador private
void processMappedAnnotationElements() { Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Mapped.class); for (Element mappedElement : elements) { if (mappedElement.getKind() == ElementKind.FIELD) { Mapped mappedAnnotation = mappedElement.getAnnotation(Mapped.class); String toFieldName = mappedAnnotation.toField(); } } }
23.
Implementando el Procesador private
void processMappedAnnotationElements() { Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Mapped.class); for (Element mappedElement : elements) { if (mappedElement.getKind() == ElementKind.FIELD) { Mapped mappedAnnotation = mappedElement.getAnnotation(Mapped.class); String toFieldName = mappedAnnotation.toField(); } } }
24.
Implementando el Procesador private
void processMappedAnnotationElements() { Set<? extends Element> elements = roundEnvironment.getElementsAnnotatedWith(Mapped.class); for (Element mappedElement : elements) { if (mappedElement.getKind() == ElementKind.FIELD) { Mapped mappedAnnotation = mappedElement.getAnnotation(Mapped.class); String toFieldName = mappedAnnotation.toField(); } } }
25.
Generando el Código JavaFileObject
file = processingEnv.getFiler().createSourceFile(name); BufferedWriter buffer = new BufferedWriter(file.openWriter()); //… buffer.close();
26.
Configurando el Entorno com.mobandme.android.transformer.compiler.internal.AnnotationsProcessor
27.
Configuración de Gradle
para el Compilador buildscript { repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } jcenter() } dependencies { classpath 'com.jimdo.gradle:gradle-apt-plugin:0.5-SNAPSHOT' } } apply plugin: 'java' apply plugin: 'apt'
28.
El resultado final
29.
¿Preguntas?
Download now