Enviar búsqueda
Cargar
Annotations Processor Tools (APT)
•
4 recomendaciones
•
1,508 vistas
Txus Ballesteros Martín
Seguir
My presentation about Annotations Processor Tool on Droidcon Spain 2015.
Leer menos
Leer más
Tecnología
Denunciar
Compartir
Denunciar
Compartir
1 de 29
Descargar ahora
Descargar para leer sin conexión
Recomendados
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
Recomendados
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
Más contenido relacionado
La actualidad más candente
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
La actualidad más candente
(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 a 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 a 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
Último
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
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
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
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Khem
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
The Digital Insurer
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
Anna Loughnan Colquhoun
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Enterprise Knowledge
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
wesley chun
Último
(20)
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 🐘
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
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
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?
Descargar ahora