SlideShare a Scribd company logo
PLUGGABLE ANNOTATION
PROCESSING API
GWT CON - 2015 - LTE CONSULTING
ARNAUD TOURNIER
Passionnate developper, trainer and architect at LTE
Consulting.
Speaker at Devoxx, GWT.create, Paris/Toulouse JUG, etc...
Email : ltearno@gmail.com
Twitter : @ltearno
Website : www.lteconsulting.fr
Full stack (x86_64 to JavaScript)
PRESENTATION AVAILABLE ON
lteconsulting.fr/annotation-processing
And the demo project is available at
github.com/ltearno/gwtcon-jsr269
GWT 3 WILL DROP GENERATORS !
JSR 269 TO THE
RESCUE???
PLUGGABLE ANNOTATION PROCESSING API
Code generation in Java (source, byte-code and resource).
Integrated with the Java compiler.
Based on annotations. The developer's annotation processor
receives most of the program's AST.
USED FOR ?
RPC stubs,
Reflection stubs,
UI generation,
Configuration file generation,
Code checkers, Build breakers,
Dependency injection,
Glue code generation,
Your own needs !
IN THE GWT CONTEXT
GWT 3 will abandon generators because the functionality
exists in standard Java : JSR 269.
Even with GWT 2.8 it makes sense to use it.
Causes migration problems, with most of the time quick
resolution.
GOOD POINTS
API is easy to use.
Generated code is visible and debuggable,
Generated code is known before compilation so you can
reference it directly (no GWT.create).
No overhead at runtime.
Does not depend on byte code : GWT compatible
BAD POINTS
Only annotated elements trigger processing. API makes it
difficult to coordinate processing of multiple classes over
multiple rounds (bad for incremental compilation).
Dependency to external resource is not managed either.
A BRIEF HISTORY
JAVADOC COMMENTS
XDoclet (2002)
APT
Introduced in JDK 5, was
removed with Java 7 because it support new language
elements.
Annotation Processing Tool
can't
Runs outside of .
API includes packages.
PLUGGABLE ANNOTATION PROCESSING API
Fixes the sins of the past.
has been included since Java 6 (2006).JSR-269
Runs inside of .
API is able to welcome new language features.
HOW IT WORKS
Annotation processors must be registered.
Java source files are compiled during rounds.
Each round, processors are activated and receive the
program's AST.
They can then generate files which will be part of the next
round.
When no file is generated during a round, real compilation
happens.
A SAMPLE
Let's say we want to develop a tool that automatically
generates UIs from any POJO...
DEMO'S PLAN
WE WILL HAVE TO
Write an annotation,
Write an annotation processor,
Register our processor through SPI,
Package and use our library.
ANNOTATION CREATION
This is the annotation we use to trigger the custom
annotation processing :
ANNOTATION PROCESSOR IMPLEMENTATION
REGISTERING THROUGH SPI
Java compiler searches annotation processors through SPI.
Add a file named META-
INF/services/javax.annotation.processing.Processor containing
the annotation processors' fqn list :
Other ways to register : has special flags. The
also has methods to set the processors to be
used.
PACKAGING
The simplest way is to have the annotation and its processor
in the same package.
Maven tip: dont forget to use the<compilerArgument>-
proc:none</compilerArgument> options
USING THE PROCESSOR
In a project with the processor's jar in the classpath, we can
use the annotation...
Eclipse tips :
Eclipse uses its own java compiler, JDT. Use m2e-apt to
configure your project if you work with maven.
Don't forget to close the processor project to have it activated.
THE POJO CLASS
THE GENERATED CLASS
USING THE GENERATED CLASS
HOW IS IT POSSIBLE ?
Using the not yet generated file is possible because the java
compiler deffers processing of the
NotFoundSymbolException.
The error is raised at the end of the parsing and annotation
processing process if the symbol has not been generated.
THE API : A BRIEF
INTRODUCTION
API OVERVIEW
Filer class : generate files (source, byte-code, resource)
Language Model classes : browse the program's structure,
Messager class : to communicate with the user,
Other tools : element and type tools
see javadoc of the javax.annotation.processing and
javax.lang.model packages.
API : JAVA SOURCE REPRESENTATION
Element : representation of a language construct (class
declarations, methods, ...). Ex: , ...
Supports all the language structures through the
and methods.
Hierarchical structure : ,
.
TypeMirror : Type representation, almost like Class<?>
API : ACCESSING ELEMENTS
Elements are given as parameters in the
method of the generator. Annotated elements are retrieved
like this :
.
All the classes parsed during the current round can be
obtained with :
.
Elements can also be retrieved with the utility methods :
,
and .
API : FILER
Creating a new Java source
API : MESSAGER
Outputs messages to the user.
Can also generate errors and break the build. Very handy to
assert things on the code.
IDE integration : hints on the API for the user.
API : TOOLS
Many tools can be retrieved from the
field of the
Other static methods and classes are helpful :
UNIT TESTS
TESTING A COMPILATION
COMPILE-TESTING
github.com/google/compile-testing
Annotation Processor testing library developped by Google
to help developping of the and projects.Auto Dagger
POSITIVE TESTS
AND NEGATIVE ONES
MISCELLANOUS
LIMITATIONS
Not a full access to the code's AST (instructions).
Processors cannot depend one on the other.
Incremental compilation is difficult when having
dependencies to more than one element or to external files.
on Eclipse : , on maven : have to disable incremental
compilation.
Most of the time those limitations are not embarassing.
HACKING
: based on JSR 269 and hacking both javac and jdt
in order to acces to internal implementations and mutate
the class AST.
Technical explanations in
Lombok
The Hacker's guide to JavaC
NOTE ON USING TEMPLATES
Try to generate the minimal amount of code, and base it on
generic implementations. This will ease debugging.
Tools :
Velocity, ...
Java Poet, ...
String.replaceAll()
LIBRARIES KNOWN USING JSR-269
JPA meta-model generation (JSR-317),
Dagger,
Google Auto,
Immutables,
Lombok,
GWT (RequestFactory),
Hexa Binding...
LINKS
,
, , , ,
, , ,
, ,
,
javadoc for annotation processing javadoc for Java Language
Model Hibernate Validation Lombok How Lombok works ?
Lombok again... Hacking JavaC Coders Breakfast Angelika
Langer presentation Dr. Macphail's trance Annotation
processing history Save method parameter names
THAT'S ALL, THANKS !
SEE YOU !
Slides : lteconsulting.fr/annotation-processing
Demo project : github.com/ltearno/gwtcon-jsr269
Twitter :
LTE Consulting : lteconsulting.fr
LinkedIn : fr.linkedin.com/in/lteconsulting

More Related Content

What's hot

Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
mahir jain
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
sshhzap
 
Discovery the p2 API (updated to Indigo)
Discovery the p2 API (updated to Indigo)Discovery the p2 API (updated to Indigo)
Discovery the p2 API (updated to Indigo)
Pascal Rapicault
 
Reverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android appsReverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android apps
Gaurav Lochan
 
Core Java
Core JavaCore Java
Core Java
NA
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
Tonny Madsen
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
Martin Toshev
 
PDE Good Practices
PDE Good PracticesPDE Good Practices
PDE Good Practices
Ankur Sharma
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Java Lover
 
Java Programming (M&M)
Java Programming (M&M)Java Programming (M&M)
Java Programming (M&M)
mafffffe19
 
Java notes
Java notesJava notes
Bn1005 demo ppt core java
Bn1005 demo ppt core javaBn1005 demo ppt core java
Bn1005 demo ppt core java
conline training
 
Programming
ProgrammingProgramming
Programming
mafffffe19
 
Java course-in-mumbai
Java course-in-mumbaiJava course-in-mumbai
Java course-in-mumbai
Unmesh Baile
 
Java
JavaJava
Java notes
Java notesJava notes
Java notes
Manish Swarnkar
 
core java
core javacore java
core java
Roushan Sinha
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
Elizabeth Thomas
 
Intoduction to java
Intoduction to javaIntoduction to java
Intoduction to java
jalinder123
 

What's hot (20)

Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Presentation on Core java
Presentation on Core javaPresentation on Core java
Presentation on Core java
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Discovery the p2 API (updated to Indigo)
Discovery the p2 API (updated to Indigo)Discovery the p2 API (updated to Indigo)
Discovery the p2 API (updated to Indigo)
 
Reverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android appsReverse engineering and instrumentation of android apps
Reverse engineering and instrumentation of android apps
 
Core Java
Core JavaCore Java
Core Java
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
 
PDE Good Practices
PDE Good PracticesPDE Good Practices
PDE Good Practices
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java Programming (M&M)
Java Programming (M&M)Java Programming (M&M)
Java Programming (M&M)
 
Java notes
Java notesJava notes
Java notes
 
Bn1005 demo ppt core java
Bn1005 demo ppt core javaBn1005 demo ppt core java
Bn1005 demo ppt core java
 
Programming
ProgrammingProgramming
Programming
 
Java course-in-mumbai
Java course-in-mumbaiJava course-in-mumbai
Java course-in-mumbai
 
Java
JavaJava
Java
 
Java notes
Java notesJava notes
Java notes
 
core java
core javacore java
core java
 
Basics of JAVA programming
Basics of JAVA programmingBasics of JAVA programming
Basics of JAVA programming
 
Intoduction to java
Intoduction to javaIntoduction to java
Intoduction to java
 

Similar to Gwt and JSR 269's Pluggable Annotation Processing API

Java and Related Technologies
Java and Related TechnologiesJava and Related Technologies
Java and Related Technologies
Qualys
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
Tom Johnson
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
Mikkel Flindt Heisterberg
 
Introduction to Groovy Monkey
Introduction to Groovy MonkeyIntroduction to Groovy Monkey
Introduction to Groovy Monkey
jervin
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
Zeeshan MIrza
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
DevaKumari Vijay
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
DrRajeshreeKhande
 
Core java slides
Core java slidesCore java slides
Core java slides
Abhilash Nair
 
String class
String classString class
String class
TharuniDiddekunta
 
Api tools overview
Api tools overviewApi tools overview
Api tools overview
Olivier Thomann
 
J introtojava1-pdf
J introtojava1-pdfJ introtojava1-pdf
J introtojava1-pdf
Emmanuel Alimpolos
 
Introducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con JavaIntroducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con Java
Facultad de Ciencias y Sistemas
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1
Qualys
 
Sybsc cs sem 3 core java
Sybsc cs sem 3 core javaSybsc cs sem 3 core java
Sybsc cs sem 3 core java
WE-IT TUTORIALS
 
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
Jorge Hidalgo
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 
Java presentation
Java presentationJava presentation
Java presentation
Karan Sareen
 
Java 5
Java 5Java 5
Java 5
mannut2001
 

Similar to Gwt and JSR 269's Pluggable Annotation Processing API (20)

Java and Related Technologies
Java and Related TechnologiesJava and Related Technologies
Java and Related Technologies
 
API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Introduction to Groovy Monkey
Introduction to Groovy MonkeyIntroduction to Groovy Monkey
Introduction to Groovy Monkey
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Unit1 introduction to Java
Unit1 introduction to JavaUnit1 introduction to Java
Unit1 introduction to Java
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 
Core java slides
Core java slidesCore java slides
Core java slides
 
String class
String classString class
String class
 
Api tools overview
Api tools overviewApi tools overview
Api tools overview
 
J introtojava1-pdf
J introtojava1-pdfJ introtojava1-pdf
J introtojava1-pdf
 
Introducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con JavaIntroducción a la progrogramación orientada a objetos con Java
Introducción a la progrogramación orientada a objetos con Java
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1
 
Sybsc cs sem 3 core java
Sybsc cs sem 3 core javaSybsc cs sem 3 core java
Sybsc cs sem 3 core java
 
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
JavaOne 2017 CON3282 - Code Generation with Annotation Processors: State of t...
 
Java basic
Java basicJava basic
Java basic
 
Java presentation
Java presentationJava presentation
Java presentation
 
Java 5
Java 5Java 5
Java 5
 

Recently uploaded

zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 

Recently uploaded (20)

zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 
Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 

Gwt and JSR 269's Pluggable Annotation Processing API

  • 1. PLUGGABLE ANNOTATION PROCESSING API GWT CON - 2015 - LTE CONSULTING
  • 2. ARNAUD TOURNIER Passionnate developper, trainer and architect at LTE Consulting. Speaker at Devoxx, GWT.create, Paris/Toulouse JUG, etc... Email : ltearno@gmail.com Twitter : @ltearno Website : www.lteconsulting.fr Full stack (x86_64 to JavaScript)
  • 3. PRESENTATION AVAILABLE ON lteconsulting.fr/annotation-processing And the demo project is available at github.com/ltearno/gwtcon-jsr269
  • 4. GWT 3 WILL DROP GENERATORS !
  • 5. JSR 269 TO THE RESCUE???
  • 6. PLUGGABLE ANNOTATION PROCESSING API Code generation in Java (source, byte-code and resource). Integrated with the Java compiler. Based on annotations. The developer's annotation processor receives most of the program's AST.
  • 7. USED FOR ? RPC stubs, Reflection stubs, UI generation, Configuration file generation, Code checkers, Build breakers, Dependency injection, Glue code generation, Your own needs !
  • 8. IN THE GWT CONTEXT GWT 3 will abandon generators because the functionality exists in standard Java : JSR 269. Even with GWT 2.8 it makes sense to use it. Causes migration problems, with most of the time quick resolution.
  • 9. GOOD POINTS API is easy to use. Generated code is visible and debuggable, Generated code is known before compilation so you can reference it directly (no GWT.create). No overhead at runtime. Does not depend on byte code : GWT compatible
  • 10. BAD POINTS Only annotated elements trigger processing. API makes it difficult to coordinate processing of multiple classes over multiple rounds (bad for incremental compilation). Dependency to external resource is not managed either.
  • 13. APT Introduced in JDK 5, was removed with Java 7 because it support new language elements. Annotation Processing Tool can't Runs outside of . API includes packages.
  • 14. PLUGGABLE ANNOTATION PROCESSING API Fixes the sins of the past. has been included since Java 6 (2006).JSR-269 Runs inside of . API is able to welcome new language features.
  • 15. HOW IT WORKS Annotation processors must be registered. Java source files are compiled during rounds. Each round, processors are activated and receive the program's AST. They can then generate files which will be part of the next round. When no file is generated during a round, real compilation happens.
  • 17. Let's say we want to develop a tool that automatically generates UIs from any POJO...
  • 19. WE WILL HAVE TO Write an annotation, Write an annotation processor, Register our processor through SPI, Package and use our library.
  • 20. ANNOTATION CREATION This is the annotation we use to trigger the custom annotation processing :
  • 22. REGISTERING THROUGH SPI Java compiler searches annotation processors through SPI. Add a file named META- INF/services/javax.annotation.processing.Processor containing the annotation processors' fqn list : Other ways to register : has special flags. The also has methods to set the processors to be used.
  • 23. PACKAGING The simplest way is to have the annotation and its processor in the same package. Maven tip: dont forget to use the<compilerArgument>- proc:none</compilerArgument> options
  • 24. USING THE PROCESSOR In a project with the processor's jar in the classpath, we can use the annotation... Eclipse tips : Eclipse uses its own java compiler, JDT. Use m2e-apt to configure your project if you work with maven. Don't forget to close the processor project to have it activated.
  • 28. HOW IS IT POSSIBLE ? Using the not yet generated file is possible because the java compiler deffers processing of the NotFoundSymbolException. The error is raised at the end of the parsing and annotation processing process if the symbol has not been generated.
  • 29. THE API : A BRIEF INTRODUCTION
  • 30. API OVERVIEW Filer class : generate files (source, byte-code, resource) Language Model classes : browse the program's structure, Messager class : to communicate with the user, Other tools : element and type tools see javadoc of the javax.annotation.processing and javax.lang.model packages.
  • 31. API : JAVA SOURCE REPRESENTATION Element : representation of a language construct (class declarations, methods, ...). Ex: , ... Supports all the language structures through the and methods. Hierarchical structure : , . TypeMirror : Type representation, almost like Class<?>
  • 32. API : ACCESSING ELEMENTS Elements are given as parameters in the method of the generator. Annotated elements are retrieved like this : . All the classes parsed during the current round can be obtained with : . Elements can also be retrieved with the utility methods : , and .
  • 33. API : FILER Creating a new Java source
  • 34. API : MESSAGER Outputs messages to the user. Can also generate errors and break the build. Very handy to assert things on the code. IDE integration : hints on the API for the user.
  • 35. API : TOOLS Many tools can be retrieved from the field of the Other static methods and classes are helpful :
  • 38. COMPILE-TESTING github.com/google/compile-testing Annotation Processor testing library developped by Google to help developping of the and projects.Auto Dagger
  • 42. LIMITATIONS Not a full access to the code's AST (instructions). Processors cannot depend one on the other. Incremental compilation is difficult when having dependencies to more than one element or to external files. on Eclipse : , on maven : have to disable incremental compilation. Most of the time those limitations are not embarassing.
  • 43. HACKING : based on JSR 269 and hacking both javac and jdt in order to acces to internal implementations and mutate the class AST. Technical explanations in Lombok The Hacker's guide to JavaC
  • 44. NOTE ON USING TEMPLATES Try to generate the minimal amount of code, and base it on generic implementations. This will ease debugging. Tools : Velocity, ... Java Poet, ... String.replaceAll()
  • 45. LIBRARIES KNOWN USING JSR-269 JPA meta-model generation (JSR-317), Dagger, Google Auto, Immutables, Lombok, GWT (RequestFactory), Hexa Binding...
  • 46. LINKS , , , , , , , , , , , javadoc for annotation processing javadoc for Java Language Model Hibernate Validation Lombok How Lombok works ? Lombok again... Hacking JavaC Coders Breakfast Angelika Langer presentation Dr. Macphail's trance Annotation processing history Save method parameter names
  • 48. SEE YOU ! Slides : lteconsulting.fr/annotation-processing Demo project : github.com/ltearno/gwtcon-jsr269 Twitter : LTE Consulting : lteconsulting.fr LinkedIn : fr.linkedin.com/in/lteconsulting