SlideShare a Scribd company logo
1 of 37
Download to read offline
APT
               Annotation Processing Tool




                                     ( ╹ω╹ )   2011/04/09
2011   4   9
@vvakame


               ↓


2011   4   9
APT



2011   4   9
※5




2011   4   9
Annotation



2011   4   9
Annotation
                            @JsonModel
                            public class Message {
       • Annotation =
                            	 @JsonKey
                            	 String id;
       •
                            	 @JsonKey
                            	 String room;
       •
                            	 @JsonKey
                            	 String text;
       • @Override
                            	 @JsonKey
                            	 String timestamp;



2011   4   9
APT



2011   4   9
APT
               • Annotation Processing Tool

               •

               •

                   •


                   •

2011   4   9
APT
               • JSON ⇔ Model

                • Map<String, Object>
                    POJO

                •

                • Reflection


2011   4   9
←                   →
       •           Reflection   •


       •                       •


       •                       •


       •                       •


       •                       •

2011   4   9
APT   Version



2011   4   9
APT       Version

               •

                   • com.sun.mirror
                   • Java5

                   • Slim3



2011   4   9
APT           Version
               • JSR 269
                • javax.lang.model
                • Java6 (JSR270)

                • JsonPullParser

                • Project Coin(JSR334)


2011   4   9
JsonPullParser
                  →




2011   4   9
Annotation
               • @interface

               • Retention (                   Annotation           )

               • Target (          Annotation                   )
                 @Retention(RetentionPolicy.SOURCE)
                 @Target({
                 	 ElementType.FIELD
                 })                                             JsonModel
                 public @interface JsonKey {
                                                                  JsonKey
                 	 public String value() default "";
                 	 public boolean in() default true;
                 	 public boolean out() default true;
                 	 public boolean decamelize() default false;
                 }

2011   4   9
AbstractProcessor
               •
                   @SupportedSourceVersion(SourceVersion.RELEASE_6)
                   @SupportedAnnotationTypes("net.vvakame.util.jsonpullparser.annotation.*")
                   public class JsonAnnotationProcessor extends AbstractProcessor {



               • EntryPoint
                   • process

                   • RoundEnviroment                             Element

                                                      JsonAnnotationProcessor

2011   4   9
RoundEnviroment
               •              Element

               •

                   •

                   •

               •                        Retention
                   SOURCE Annotation        …

2011   4   9
Element
               •
                                   Element
               •
                   •       Annotation       Element
                   •
                       •                 (ex setter, getter              )

                       •
                               ClassGenerateHelper#ValueExtractVisitor

2011   4   9
TypeMirror
               •

               •           Element→TypeMirror→
                              Element

                   •            …

               • Element            …


2011   4   9
Annotation
                  • Annotation


                                                                                 APT
   @JsonModel(treatUnknownKeyAsError = true,           	   String getElementKeyString(Element element) {
               decamelize = true)                      	   	   JsonKey key = element.getAnnotation(JsonKey.class);
   public class Hoge extends RecvGeoInfoLog {          	   	   JsonModel model = element.getEnclosingElement()
                                                                                     .getAnnotation(JsonModel.class);
   	       @JsonKey("foga")                            	   	   String keyStr;
   	       String piyo;                                	   	   if (!"".equals(key.value())) {
                                                       	   	   	    keyStr = key.value();
   	       @JsonKey(converter = DateConverter.class)   	   	   } else if ("".equals(key.value()) && key.decamelize()) {
   	       Date at;                                    	   	   	    keyStr = decamelize(element.toString());
   }                                                   	   	   } else if ("".equals(key.value()) && model.decamelize()) {
                                                       	   	   	    keyStr = decamelize(element.toString());
                                                       	   	   } else {
                                                       	   	   	    keyStr = element.toString();
                                                       	   	   }
                                                       	   	   return keyStr;
                                                       	   }


2011   4   9
Message
                  •

                  •                     Element         |
       JsonKey key = el.getAnnotation(JsonKey.class);

       String setter = getElementSetter(el);
       if (key.in() && setter == null) {
       	    Log.e("can't find setter method", el);
       	    encountError = true;
       	    return defaultAction(t, el);
       }




                                                            Log
2011   4   9
JavaFileObject
               • Java

               • ProcessingEnvironment        Filer



               •



                                  ClassGenerateHelper#write

2011   4   9
• Util
                • Elements
                  Element

                • Types
                • TypeMirror

               • Visitor
                • Annotation, Element, TypeMirror
                             ClassGenerateHelper#ValueExtractVisitor

2011   4   9
•       APT         jar

               • META-INF/services/
                  javax.annotation.processing.Processor

                   •             Processor               FQN
                              FQN = package               +

                                  /src/main/resources/

2011   4   9
2011   4   9
• Aptina
                • UnitTest

               • TemplateEngine (MVEL)
                •

               • Eclipse
               • maven
                • jar

2011   4   9
Aptina
               • Aptina

                •       Processor   JUnit

                •                      Try&Error

                • UnitTest                           …

                    •

                    •                                             …
                                    JsonAnnotationProcessorTest

2011   4   9
TemplateEngine(MVEL)
               •
                   •
                   •
               • Javadoc
               •

                   (                                       )
                           MvelTemplate, JsonModelGen.java.mvel

2011   4   9
maven
               • jar
               •


               •       Eclipse
               •
               •                           ...

                                 pom.xml

2011   4   9
Formatter...?
               • Java
               •                                      (                            )
               •
                                  UnitTest                             …
               •                      FQN                  import                  …
                   } else
                   if ("place".equals(key)) {

                   	   net.vvakame.sample.twitter.Place tmp =
                          net.vvakame.sample.twitter.PlaceGenerated.get(parser);
                   	   obj.setPlace(tmp);
                   	   if (listener != null) {
                   	   	 listener.onAdd(tmp);
                   	   }
2011   4   9
• core
                •        jar
               • apt
                • APT          jar
                • APT                UnitTest
               • usage
                • APT                    UnitTest
                •
2011   4   9
Eclipse


           •            1

               • MVEL




2011   4   9
2011   4   9
JsonPullParser

               • https://github.com/vvakame/JSONPullParser

                • APT Json→POJO                Java

                • Android              http://bit.ly/hFTbtP

                  • Tweet           →1Tweet

                • SengokuDroid server-side



2011   4   9
2011   4   9
• Android Slim3

                • HamsterDB..? → GPL...
                • SQLite..? →    KVS      ...

               • MsgpackParser

               • Java     Formatter


2011   4   9
Minecraft




2011   4   9

More Related Content

What's hot

Lecture02 class -_templatev2
Lecture02 class -_templatev2Lecture02 class -_templatev2
Lecture02 class -_templatev2
Hariz Mustafa
 

What's hot (12)

Lecture02 class -_templatev2
Lecture02 class -_templatev2Lecture02 class -_templatev2
Lecture02 class -_templatev2
 
Modul Praktek Java OOP
Modul Praktek Java OOP Modul Praktek Java OOP
Modul Praktek Java OOP
 
Java2
Java2Java2
Java2
 
Exploring type level programming in Scala
Exploring type level programming in ScalaExploring type level programming in Scala
Exploring type level programming in Scala
 
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
JS Fest 2019. Max Koretskiy. A sneak peek into super optimized code in JS fra...
 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 
Java 7 New Features
Java 7 New FeaturesJava 7 New Features
Java 7 New Features
 
Java SE 8 best practices
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practices
 
Database handling with room
Database handling with roomDatabase handling with room
Database handling with room
 
Java Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and PitfallsJava Generics Introduction - Syntax Advantages and Pitfalls
Java Generics Introduction - Syntax Advantages and Pitfalls
 

Similar to 僕の考えるAPT開発の常識 ぐだ生 2011/04/09版

appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
Shinichi Ogawa
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
techtalkdwango
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
Takuya Fujimura
 
Interface result set
Interface result setInterface result set
Interface result set
myrajendra
 
2011 JavaOne EJB with Meta Annotations
2011 JavaOne EJB with Meta Annotations2011 JavaOne EJB with Meta Annotations
2011 JavaOne EJB with Meta Annotations
David Blevins
 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
Shinichi Ogawa
 

Similar to 僕の考えるAPT開発の常識 ぐだ生 2011/04/09版 (20)

僕の考えるAPT開発の常識
僕の考えるAPT開発の常識僕の考えるAPT開発の常識
僕の考えるAPT開発の常識
 
CPython 3.2 SourceCodeReading
CPython 3.2 SourceCodeReadingCPython 3.2 SourceCodeReading
CPython 3.2 SourceCodeReading
 
2011 july-nyc-gtug-go
2011 july-nyc-gtug-go2011 july-nyc-gtug-go
2011 july-nyc-gtug-go
 
appengine java night #1
appengine java night #1appengine java night #1
appengine java night #1
 
みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」みゆっき☆Think#7 「本気で学ぶJavascript」
みゆっき☆Think#7 「本気で学ぶJavascript」
 
第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript第7回みゆっき☆Think 本気で学ぶ JavaScript
第7回みゆっき☆Think 本気で学ぶ JavaScript
 
Javascript Basics - part 1
Javascript Basics - part 1Javascript Basics - part 1
Javascript Basics - part 1
 
コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門
 
Interface result set
Interface result setInterface result set
Interface result set
 
Serializing EMF models with Xtext
Serializing EMF models with XtextSerializing EMF models with Xtext
Serializing EMF models with Xtext
 
2011 JavaOne EJB with Meta Annotations
2011 JavaOne EJB with Meta Annotations2011 JavaOne EJB with Meta Annotations
2011 JavaOne EJB with Meta Annotations
 
ERRest and Dojo
ERRest and DojoERRest and Dojo
ERRest and Dojo
 
Appengine Java Night #2a
Appengine Java Night #2aAppengine Java Night #2a
Appengine Java Night #2a
 
About Python
About PythonAbout Python
About Python
 
Domänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit XtextDomänenspezifische Sprachen mit Xtext
Domänenspezifische Sprachen mit Xtext
 
Java Annotations and Pre-processing
Java  Annotations and Pre-processingJava  Annotations and Pre-processing
Java Annotations and Pre-processing
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
State of GeoTools 2012
State of GeoTools 2012State of GeoTools 2012
State of GeoTools 2012
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platforms
 
When?, Why? and What? of MongoDB
When?, Why? and What? of MongoDBWhen?, Why? and What? of MongoDB
When?, Why? and What? of MongoDB
 

More from Masahiro Wakame

Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
Google Glassでできること XE12版 最新開発情報 Mirror API & GDKGoogle Glassでできること XE12版 最新開発情報 Mirror API & GDK
Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
Masahiro Wakame
 
コンパイラ指向ReVIEW
コンパイラ指向ReVIEWコンパイラ指向ReVIEW
コンパイラ指向ReVIEW
Masahiro Wakame
 
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
Google Glassでできること XE11版 最新開発情報 Mirror API & GDKGoogle Glassでできること XE11版 最新開発情報 Mirror API & GDK
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
Masahiro Wakame
 
ReVIEW & CI - ChefでCI環境構築
ReVIEW & CI - ChefでCI環境構築ReVIEW & CI - ChefでCI環境構築
ReVIEW & CI - ChefでCI環境構築
Masahiro Wakame
 
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例までBuildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
Masahiro Wakame
 
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作ったDatastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
Masahiro Wakame
 

More from Masahiro Wakame (20)

GoCon2016 spring 自作Webフレームワーク uconを作った話
GoCon2016 spring 自作Webフレームワーク uconを作った話GoCon2016 spring 自作Webフレームワーク uconを作った話
GoCon2016 spring 自作Webフレームワーク uconを作った話
 
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作るGoCon 2015 Summer GoのASTをいじくって新しいツールを作る
GoCon 2015 Summer GoのASTをいじくって新しいツールを作る
 
ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3ng-japan 2015 TypeScript+AngularJS 1.3
ng-japan 2015 TypeScript+AngularJS 1.3
 
TypeScriptは明日から使うべき
TypeScriptは明日から使うべきTypeScriptは明日から使うべき
TypeScriptは明日から使うべき
 
TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部
TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部
TypeScript 型定義ファイルのある開発 TypeScript勉強会 VSハッカソン倶楽部
 
Google Glass XE17版
Google Glass XE17版Google Glass XE17版
Google Glass XE17版
 
Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
Google Glassでできること XE12版 最新開発情報 Mirror API & GDKGoogle Glassでできること XE12版 最新開発情報 Mirror API & GDK
Google Glassでできること XE12版 最新開発情報 Mirror API & GDK
 
コンパイラ指向ReVIEW
コンパイラ指向ReVIEWコンパイラ指向ReVIEW
コンパイラ指向ReVIEW
 
20ヶ月を取り戻す Dart flight school
20ヶ月を取り戻す Dart flight school20ヶ月を取り戻す Dart flight school
20ヶ月を取り戻す Dart flight school
 
TypeScript 独習会
TypeScript 独習会TypeScript 独習会
TypeScript 独習会
 
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
Google Glassでできること XE11版 最新開発情報 Mirror API & GDKGoogle Glassでできること XE11版 最新開発情報 Mirror API & GDK
Google Glassでできること XE11版 最新開発情報 Mirror API & GDK
 
CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例
CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例
CEATEC Glassware(Google Glassアプリ)開発の指南と開発事例
 
ReVIEW & CI - ChefでCI環境構築
ReVIEW & CI - ChefでCI環境構築ReVIEW & CI - ChefでCI環境構築
ReVIEW & CI - ChefでCI環境構築
 
Firefox OS勉強会 2nd TypeScript+AngularJS
Firefox OS勉強会 2nd TypeScript+AngularJSFirefox OS勉強会 2nd TypeScript+AngularJS
Firefox OS勉強会 2nd TypeScript+AngularJS
 
AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会AngularJS+TypeScript - AngularJS 1周年記念勉強会
AngularJS+TypeScript - AngularJS 1周年記念勉強会
 
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例までBuildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
Buildinsider OFFLINE TypeScriptの基礎から実践・利用事例まで
 
俺とお前とGoogleware
俺とお前とGoogleware俺とお前とGoogleware
俺とお前とGoogleware
 
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作ったDatastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
Datastoreへのアクセスを楽してMemcacheアクセスに置き換えるライブラリ作った
 
TypeScript 勉強会
TypeScript 勉強会TypeScript 勉強会
TypeScript 勉強会
 
TypeScript Hands-on
TypeScript Hands-onTypeScript Hands-on
TypeScript Hands-on
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

僕の考えるAPT開発の常識 ぐだ生 2011/04/09版

  • 1. APT Annotation Processing Tool ( ╹ω╹ ) 2011/04/09 2011 4 9
  • 2. @vvakame ↓ 2011 4 9
  • 3. APT 2011 4 9
  • 4. ※5 2011 4 9
  • 6. Annotation @JsonModel public class Message { • Annotation = @JsonKey String id; • @JsonKey String room; • @JsonKey String text; • @Override @JsonKey String timestamp; 2011 4 9
  • 7. APT 2011 4 9
  • 8. APT • Annotation Processing Tool • • • • 2011 4 9
  • 9. APT • JSON ⇔ Model • Map<String, Object> POJO • • Reflection 2011 4 9
  • 10. → • Reflection • • • • • • • • • 2011 4 9
  • 11. APT Version 2011 4 9
  • 12. APT Version • • com.sun.mirror • Java5 • Slim3 2011 4 9
  • 13. APT Version • JSR 269 • javax.lang.model • Java6 (JSR270) • JsonPullParser • Project Coin(JSR334) 2011 4 9
  • 14. JsonPullParser → 2011 4 9
  • 15. Annotation • @interface • Retention ( Annotation ) • Target ( Annotation ) @Retention(RetentionPolicy.SOURCE) @Target({ ElementType.FIELD }) JsonModel public @interface JsonKey { JsonKey public String value() default ""; public boolean in() default true; public boolean out() default true; public boolean decamelize() default false; } 2011 4 9
  • 16. AbstractProcessor • @SupportedSourceVersion(SourceVersion.RELEASE_6) @SupportedAnnotationTypes("net.vvakame.util.jsonpullparser.annotation.*") public class JsonAnnotationProcessor extends AbstractProcessor { • EntryPoint • process • RoundEnviroment Element JsonAnnotationProcessor 2011 4 9
  • 17. RoundEnviroment • Element • • • • Retention SOURCE Annotation … 2011 4 9
  • 18. Element • Element • • Annotation Element • • (ex setter, getter ) • ClassGenerateHelper#ValueExtractVisitor 2011 4 9
  • 19. TypeMirror • • Element→TypeMirror→ Element • … • Element … 2011 4 9
  • 20. Annotation • Annotation APT @JsonModel(treatUnknownKeyAsError = true, String getElementKeyString(Element element) { decamelize = true) JsonKey key = element.getAnnotation(JsonKey.class); public class Hoge extends RecvGeoInfoLog { JsonModel model = element.getEnclosingElement() .getAnnotation(JsonModel.class); @JsonKey("foga") String keyStr; String piyo; if (!"".equals(key.value())) { keyStr = key.value(); @JsonKey(converter = DateConverter.class) } else if ("".equals(key.value()) && key.decamelize()) { Date at; keyStr = decamelize(element.toString()); } } else if ("".equals(key.value()) && model.decamelize()) { keyStr = decamelize(element.toString()); } else { keyStr = element.toString(); } return keyStr; } 2011 4 9
  • 21. Message • • Element | JsonKey key = el.getAnnotation(JsonKey.class); String setter = getElementSetter(el); if (key.in() && setter == null) { Log.e("can't find setter method", el); encountError = true; return defaultAction(t, el); } Log 2011 4 9
  • 22. JavaFileObject • Java • ProcessingEnvironment Filer • ClassGenerateHelper#write 2011 4 9
  • 23. • Util • Elements Element • Types • TypeMirror • Visitor • Annotation, Element, TypeMirror ClassGenerateHelper#ValueExtractVisitor 2011 4 9
  • 24. APT jar • META-INF/services/ javax.annotation.processing.Processor • Processor FQN FQN = package + /src/main/resources/ 2011 4 9
  • 25. 2011 4 9
  • 26. • Aptina • UnitTest • TemplateEngine (MVEL) • • Eclipse • maven • jar 2011 4 9
  • 27. Aptina • Aptina • Processor JUnit • Try&Error • UnitTest … • • … JsonAnnotationProcessorTest 2011 4 9
  • 28. TemplateEngine(MVEL) • • • • Javadoc • ( ) MvelTemplate, JsonModelGen.java.mvel 2011 4 9
  • 29. maven • jar • • Eclipse • • ... pom.xml 2011 4 9
  • 30. Formatter...? • Java • ( ) • UnitTest … • FQN import … } else if ("place".equals(key)) { net.vvakame.sample.twitter.Place tmp = net.vvakame.sample.twitter.PlaceGenerated.get(parser); obj.setPlace(tmp); if (listener != null) { listener.onAdd(tmp); } 2011 4 9
  • 31. • core • jar • apt • APT jar • APT UnitTest • usage • APT UnitTest • 2011 4 9
  • 32. Eclipse • 1 • MVEL 2011 4 9
  • 33. 2011 4 9
  • 34. JsonPullParser • https://github.com/vvakame/JSONPullParser • APT Json→POJO Java • Android http://bit.ly/hFTbtP • Tweet →1Tweet • SengokuDroid server-side 2011 4 9
  • 35. 2011 4 9
  • 36. • Android Slim3 • HamsterDB..? → GPL... • SQLite..? → KVS ... • MsgpackParser • Java Formatter 2011 4 9