Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
APT               Annotation Processing Tool                         TOPGATE            2011/04/082011   4   9
@vvakame               ↓2011   4   9
Annotation2011   4   9
Annotation                            @JsonModel                            public class Message {       • Annotation =   ...
APT2011   4   9
APT               • Annotation Processing Tool               •               •                   •                   •2011...
Slim3        APT               • Entity ⇔ Model                • Map<String, Object>                    POJO              ...
←                   →       •           Reflection   •       •                       •       •                       •     ...
APT   Version2011   4   9
APT       Version               •                   • com.sun.mirror                   • Java5                   • Slim320...
APT           Version               • JSR 269                • javax.lang.model                • Java6 (JSR270)           ...
JsonPullParser                  →2011   4   9
Annotation               • @interface               • Retention (                   Annotation           )               •...
AbstractProcessor               •                   @SupportedSourceVersion(SourceVersion.RELEASE_6)                   @Su...
RoundEnviroment               •              Element               •                   •                   •              ...
Element               •                                   Element               •                   •       Annotation    ...
TypeMirror               •               •           Element→TypeMirror→                              Element             ...
Annotation                  • Annotation                                                                                 A...
Message                  •                  •                     Element         |       JsonKey key = el.getAnnotation(J...
JavaFileObject               • Java               • ProcessingEnvironment        Filer               •                    ...
• Util                • Elements                  Element                • Types                • TypeMirror              ...
•       APT         jar               • META-INF/services/                  javax.annotation.processing.Processor         ...
2011   4   9
• Aptina                • UnitTest               • TemplateEngine (MVEL)                •               • Eclipse         ...
Aptina               • Aptina                •       Processor   JUnit                •                      Try&Error    ...
TemplateEngine(MVEL)               •                   •                   •               • Javadoc               •      ...
maven               • jar               •               •       Eclipse               •               •                   ...
Formatter...?               • Java               •                                      (                            )    ...
• core                •        jar               • apt                • APT          jar                • APT             ...
Eclipse           •            1               • MVEL2011   4   9
2011   4   9
JsonPullParser               • https://github.com/vvakame/JSONPullParser                • APT Json→POJO                Jav...
2011   4   9
• Android Slim3                • HamsterDB..? → GPL...                • SQLite..? →    KVS      ...               • Msgpac...
Minecraft2011   4   9
Upcoming SlideShare
Loading in …5
×

僕の考えるAPT開発の常識

2011/04/08 トップゲート社内で実施した勉強会の発表資料

  • Login to see the comments

僕の考えるAPT開発の常識

  1. 1. APT Annotation Processing Tool TOPGATE 2011/04/082011 4 9
  2. 2. @vvakame ↓2011 4 9
  3. 3. Annotation2011 4 9
  4. 4. Annotation @JsonModel public class Message { • Annotation = @JsonKey String id; • @JsonKey String room; • @JsonKey String text; • @Override @JsonKey String timestamp;2011 4 9
  5. 5. APT2011 4 9
  6. 6. APT • Annotation Processing Tool • • • •2011 4 9
  7. 7. Slim3 APT • Entity ⇔ Model • Map<String, Object> POJO • • Reflection2011 4 9
  8. 8. ← → • Reflection • • • • • • • • •2011 4 9
  9. 9. APT Version2011 4 9
  10. 10. APT Version • • com.sun.mirror • Java5 • Slim32011 4 9
  11. 11. APT Version • JSR 269 • javax.lang.model • Java6 (JSR270) • JsonPullParser • Project Coin(JSR334)2011 4 9
  12. 12. JsonPullParser →2011 4 9
  13. 13. 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
  14. 14. AbstractProcessor • @SupportedSourceVersion(SourceVersion.RELEASE_6) @SupportedAnnotationTypes("net.vvakame.util.jsonpullparser.annotation.*") public class JsonAnnotationProcessor extends AbstractProcessor { • EntryPoint • process • RoundEnviroment Element JsonAnnotationProcessor2011 4 9
  15. 15. RoundEnviroment • Element • • • • Retention SOURCE Annotation …2011 4 9
  16. 16. Element • Element • • Annotation Element • • (ex setter, getter ) • ClassGenerateHelper#ValueExtractVisitor2011 4 9
  17. 17. TypeMirror • • Element→TypeMirror→ Element • … • Element …2011 4 9
  18. 18. 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
  19. 19. Message • • Element | JsonKey key = el.getAnnotation(JsonKey.class); String setter = getElementSetter(el); if (key.in() && setter == null) { Log.e("cant find setter method", el); encountError = true; return defaultAction(t, el); } Log2011 4 9
  20. 20. JavaFileObject • Java • ProcessingEnvironment Filer • ClassGenerateHelper#write2011 4 9
  21. 21. • Util • Elements Element • Types • TypeMirror • Visitor • Annotation, Element, TypeMirror ClassGenerateHelper#ValueExtractVisitor2011 4 9
  22. 22. • APT jar • META-INF/services/ javax.annotation.processing.Processor • Processor FQN FQN = package + /src/main/resources/2011 4 9
  23. 23. 2011 4 9
  24. 24. • Aptina • UnitTest • TemplateEngine (MVEL) • • Eclipse • maven • jar2011 4 9
  25. 25. Aptina • Aptina • Processor JUnit • Try&Error • UnitTest … • • … JsonAnnotationProcessorTest2011 4 9
  26. 26. TemplateEngine(MVEL) • • • • Javadoc • ( ) MvelTemplate, JsonModelGen.java.mvel2011 4 9
  27. 27. maven • jar • • Eclipse • • ... pom.xml2011 4 9
  28. 28. 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
  29. 29. • core • jar • apt • APT jar • APT UnitTest • usage • APT UnitTest •2011 4 9
  30. 30. Eclipse • 1 • MVEL2011 4 9
  31. 31. 2011 4 9
  32. 32. JsonPullParser • https://github.com/vvakame/JSONPullParser • APT Json→POJO Java • Android http://bit.ly/hFTbtP • Tweet →1Tweet • SengokuDroid server-side2011 4 9
  33. 33. 2011 4 9
  34. 34. • Android Slim3 • HamsterDB..? → GPL... • SQLite..? → KVS ... • MsgpackParser • Java Formatter2011 4 9
  35. 35. Minecraft2011 4 9

×