SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
CODE GENERATION
WITH JAVAC PLUGIN
Hello!
I am Oleksandr Radchykov
committed.chinchilla@gmail.com
belict
Agenda
1. Motivation
2. How to generate code?
3. How to create plugin
4. Demo
Motivation for
code generation
Getting rid of boilerplate
class MyService {
private final String name;
private final Integer version;
public MyService(String name, Integer version) {
this.name = name;
This.version = version;
}
public String getName() { return name; }
public Integer getVersion() { return version; }
}
@Getter
@RequiredArgsConstructor
class MyService {
private final String name;
private final Integer version;
}
6
Getting rid from annoying
code duplication
public String validate(Object input) {
if (income instanceof String
&& !((String) income).isEmpty()) {
return (String) income;
}
…
}
public String validate(Object input) {
if (income instanceof String && !income.isEmpty()) {
return income;
}
…
}
8
Two ways to
generate code
Annotation Processing
▷Java 5+
▷Takes java code and generates source files
▷You can not manipulate an existing java code
▷Use the model of processing rounds
Javac Plugin
▷Since Java 8
▷Can give us access to AST trees parsed from
source code
▷Can be used to add compile-time checks
▷Can run on different phases of compilation
process
How to create
javac plugin?
1. Implement Plugin interface
import com.sun.source.util.Plugin;
class MyPlugin implements Plugin {
@Override
public String getName() { return “pluginName”; }
@Override
public void init(JavacTask javacTask,
String… strings) {
/*...*/
}
}
2. Create provider-configuration file
MyPlugin.jar
- com/example
- MyPlugin.class
- META-INF/services
- com.sun.source.util.Plugin
Provider-configuration file should declare all plugins
you want to expose.
3. Compilation
$ javac -Xplugin:PluginName 
–cp /path/to/plugin 
Source.java
Demo
Questions?
Thanks
committed.chinchilla@gmail.com
belict

Contenu connexe

Tendances

jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) Microsoft
Jimmy Schementi
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 

Tendances (20)

C++ practical
C++ practicalC++ practical
C++ practical
 
Меняем javascript с помощью javascript
Меняем javascript с помощью javascriptМеняем javascript с помощью javascript
Меняем javascript с помощью javascript
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) Microsoft
 
[Question Paper] Advanced Java (60:40 Pattern) [October / 2013]
[Question Paper] Advanced Java (60:40 Pattern) [October / 2013][Question Paper] Advanced Java (60:40 Pattern) [October / 2013]
[Question Paper] Advanced Java (60:40 Pattern) [October / 2013]
 
Presentation about ClosureScript fraemework
Presentation about ClosureScript fraemeworkPresentation about ClosureScript fraemework
Presentation about ClosureScript fraemework
 
The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185The Ring programming language version 1.5.4 book - Part 82 of 185
The Ring programming language version 1.5.4 book - Part 82 of 185
 
The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196The Ring programming language version 1.7 book - Part 7 of 196
The Ring programming language version 1.7 book - Part 7 of 196
 
Introduction to kotlin
Introduction to kotlinIntroduction to kotlin
Introduction to kotlin
 
The Ring programming language version 1.5.3 book - Part 92 of 184
The Ring programming language version 1.5.3 book - Part 92 of 184The Ring programming language version 1.5.3 book - Part 92 of 184
The Ring programming language version 1.5.3 book - Part 92 of 184
 
Lua Study Share
Lua Study ShareLua Study Share
Lua Study Share
 
The Ring programming language version 1.8 book - Part 17 of 202
The Ring programming language version 1.8 book - Part 17 of 202The Ring programming language version 1.8 book - Part 17 of 202
The Ring programming language version 1.8 book - Part 17 of 202
 
ITK Tutorial Presentation Slides-944
ITK Tutorial Presentation Slides-944ITK Tutorial Presentation Slides-944
ITK Tutorial Presentation Slides-944
 
The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196The Ring programming language version 1.7 book - Part 88 of 196
The Ring programming language version 1.7 book - Part 88 of 196
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
The Ring programming language version 1.9 book - Part 19 of 210
The Ring programming language version 1.9 book - Part 19 of 210The Ring programming language version 1.9 book - Part 19 of 210
The Ring programming language version 1.9 book - Part 19 of 210
 
The Ring programming language version 1.5.4 book - Part 81 of 185
The Ring programming language version 1.5.4 book - Part 81 of 185The Ring programming language version 1.5.4 book - Part 81 of 185
The Ring programming language version 1.5.4 book - Part 81 of 185
 
Cocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magicCocoaheads Meetup / Alex Zimin / Swift magic
Cocoaheads Meetup / Alex Zimin / Swift magic
 

En vedette

что такое модель оон
что такое модель оончто такое модель оон
что такое модель оон
Natali_lady
 
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit AriacaH:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
Jordi Clopés
 
Judicial Process Syllabus
Judicial Process SyllabusJudicial Process Syllabus
Judicial Process Syllabus
Bernard Moore
 
Collaboration tools features to consider
Collaboration tools   features to considerCollaboration tools   features to consider
Collaboration tools features to consider
Tom Mighell
 

En vedette (20)

что такое модель оон
что такое модель оончто такое модель оон
что такое модель оон
 
Diapositivas
DiapositivasDiapositivas
Diapositivas
 
Pr10 new technologies
Pr10 new technologiesPr10 new technologies
Pr10 new technologies
 
Vladimir Milov and Andrey Savchenko - Classification of Dangerous Situations...
Vladimir Milov and  Andrey Savchenko - Classification of Dangerous Situations...Vladimir Milov and  Andrey Savchenko - Classification of Dangerous Situations...
Vladimir Milov and Andrey Savchenko - Classification of Dangerous Situations...
 
MKYoumans.Portfolio
MKYoumans.PortfolioMKYoumans.Portfolio
MKYoumans.Portfolio
 
Final Project in U of T
Final Project in U of TFinal Project in U of T
Final Project in U of T
 
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit AriacaH:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
H:\Documents And Settings\Pc\Mis Documentos\Jordi\Bordons\Poema Judit Ariaca
 
Judicial Process Syllabus
Judicial Process SyllabusJudicial Process Syllabus
Judicial Process Syllabus
 
Collaboration tools features to consider
Collaboration tools   features to considerCollaboration tools   features to consider
Collaboration tools features to consider
 
Connecting Cabrils
Connecting CabrilsConnecting Cabrils
Connecting Cabrils
 
Communiqué de presse - CooLifting pour homme
Communiqué de presse - CooLifting pour hommeCommuniqué de presse - CooLifting pour homme
Communiqué de presse - CooLifting pour homme
 
Fechamento de área
Fechamento de áreaFechamento de área
Fechamento de área
 
QA Audit 060315
QA Audit 060315QA Audit 060315
QA Audit 060315
 
Александр Москвичев, EveResearch - Алгоритмы анализа данных в маркетинговых и...
Александр Москвичев, EveResearch - Алгоритмы анализа данных в маркетинговых и...Александр Москвичев, EveResearch - Алгоритмы анализа данных в маркетинговых и...
Александр Москвичев, EveResearch - Алгоритмы анализа данных в маркетинговых и...
 
OOP design patterns
OOP design patternsOOP design patterns
OOP design patterns
 
Spring Web flow. A little flow of happiness
Spring Web flow. A little flow of happinessSpring Web flow. A little flow of happiness
Spring Web flow. A little flow of happiness
 
Componentes geográficos y aprendizajes esperados de exploración y conocimient...
Componentes geográficos y aprendizajes esperados de exploración y conocimient...Componentes geográficos y aprendizajes esperados de exploración y conocimient...
Componentes geográficos y aprendizajes esperados de exploración y conocimient...
 
Cara Mendaftar Google Map
Cara Mendaftar Google MapCara Mendaftar Google Map
Cara Mendaftar Google Map
 
Swimming sahal
Swimming sahalSwimming sahal
Swimming sahal
 
A coding fool design patterns
A coding fool design patternsA coding fool design patterns
A coding fool design patterns
 

Similaire à Java day 2016.pptx

Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Carol McDonald
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
knight1128
 

Similaire à Java day 2016.pptx (20)

Code generation with javac plugin
Code generation with javac pluginCode generation with javac plugin
Code generation with javac plugin
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, TuningJava 5 6 Generics, Concurrency, Garbage Collection, Tuning
Java 5 6 Generics, Concurrency, Garbage Collection, Tuning
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
Java ppt Gandhi Ravi (gandhiri@gmail.com)
Java ppt  Gandhi Ravi  (gandhiri@gmail.com)Java ppt  Gandhi Ravi  (gandhiri@gmail.com)
Java ppt Gandhi Ravi (gandhiri@gmail.com)
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
.gradle 파일 정독해보기
.gradle 파일 정독해보기.gradle 파일 정독해보기
.gradle 파일 정독해보기
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
Core Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCore Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th May
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
Java practical
Java practicalJava practical
Java practical
 
Scala at Netflix
Scala at NetflixScala at Netflix
Scala at Netflix
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Linq intro
Linq introLinq intro
Linq intro
 
Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 

Dernier

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Dernier (20)

2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 

Java day 2016.pptx