Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to APT

Introduction to APT

【第19回】potatotips(iOS/Android開発Tips共有会) 発表資料 http://connpass.com/event/16295/

Masayuki Izumi

July 14, 2015
Tweet

More Decks by Masayuki Izumi

Other Decks in Technology

Transcript

  1. Ƅ Rekimoto Lab. at the University of Tokyo (2008-2015: Akashi-NCT)

    Ɠ Enginner at Wantedly, Inc. (2014.9-2015.2: Dmetlabel, Inc.) 2
  2. APT (Annotation Processor Tool) Note: The apt tool and its

    associated API contaiined in the pakcage com.sun.mirror have been deprecated since Java SE 7. Use the options available in the javac tool and the APIs contained in the packages javax.annotation.processing and javax.lang.model to process annotations[1] . [1] http://docs.oracle.com/javase/7/docs/technotes/guides/apt/
  3. APT (Annotation Processor Tool) Note: The apt tool and its

    associated API contaiined in the pakcage com.sun.mirror have been deprecated since Java SE 7. Use the options available in the javac tool and the APIs contained in the packages javax.annotation.processing and javax.lang.model to process annotations[1] . [1] http://docs.oracle.com/javase/7/docs/technotes/guides/apt/
  4. APT (Annotation Processor Tool) This functionality is accessed through new

    options to the javac command; by including JSR 269 support, javac now acts analogously to the apt command in JDK 5[1] . [1] http://docs.oracle.com/javase/7/docs/technotes/guides/apt/
  5. APT (Annotation Processor Tool) This functionality is accessed through new

    options to the javac command; by including JSR 269 support, javac now acts analogously to the apt command in JDK 5[1] . [1] http://docs.oracle.com/javase/7/docs/technotes/guides/apt/
  6. ライブラリの構成 * api: 利用者が触るやつ - annotations - クラスとか生成したりするやつ(e.g. RestAdapter) *

    processor: コンパイラが触るやつ - AbstractProcessor のサブクラス - その他コード生成のロジック
  7. Processor @AutoService(javax.annotation.processing.Processor.class) public class Processor extends AbstractProcessor { @Override public

    boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // do something... return true; } // do something... }
  8. Processor @AutoService(javax.annotation.processing.Processor.class) public class Processor extends AbstractProcessor { @Override public

    boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // do something... return true; } // do something... }
  9. Processor @AutoService(javax.annotation.processing.Processor.class) public class Processor extends AbstractProcessor { @Override public

    boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // do something... return true; } // do something... }
  10. Processor @AutoService(javax.annotation.processing.Processor.class) public class Processor extends AbstractProcessor { @Override public

    boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { // do something... return true; } // do something... }
  11. test: Compile Testing[3] public ProcessorTest { @Test public void testProcessor()

    { assert_().about(javaSource()) .that(JavaFileObjects.forSourceString("PyonPyon", "final class PyonPyon {}")) .processedWith(new MyAnnotationProcessor()) .compilesWithoutError(); } } [3] https://github.com/google/compile-testing
  12. test: Compile Testing public ProcessorTest { @Test public void testProcessor()

    { assert_().about(javaSource()) .that(JavaFileObjects.forSourceString("PyonPyon", "final class PyonPyon {}")) .processedWith(new MyAnnotationProcessor()) .compilesWithoutError(); } }
  13. test: Compile Testing public ProcessorTest { @Test public void testProcessor()

    { assert_().about(javaSource()) .that(JavaFileObjects.forSourceString("PyonPyon", "final class PyonPyon {}")) .processedWith(new MyAnnotationProcessor()) .compilesWithoutError(); } }
  14. Conclusion * Annotation は API と Processor から成る - API:

    ユーザが触る - Processor: javac が触る * Google と Square に足を向けて寝られない - AutoService - Compile Testing - JavaPoet