Code generation on the Java VM 2019-12-05

99d4c0ed3c8027ea1c37b53d6441d042?s=47 sullis
December 05, 2019

Code generation on the Java VM 2019-12-05

December 5, 2019

#java
#scala
#OpenAPI
#ApiBuilder

99d4c0ed3c8027ea1c37b53d6441d042?s=128

sullis

December 05, 2019
Tweet

Transcript

  1. 5.

    class names parameter names method names exception names Consistency error

    handling logging JSON serialization network I/O
  2. 21.

    “Unlike Spring which relies exclusively on runtime reflection and proxies,

    Micronaut uses compile time data to implement dependency injection” micronaut https://docs.micronaut.io/latest/guide/ioc.html
  3. 22.

    “This goal is achieved through the use of Java’s annotation

    processors" micronaut https://docs.micronaut.io/latest/guide/index.html
  4. 25.
  5. 27.

    “Mockito switched from CGLIB to the great library ByteBuddy to

    make mocks” https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2 mockito 2.x
  6. 39.
  7. 41.

    package com.example.helloworld; public final class HelloWorld { public static void

    main(String[] args) { System.out.println("Hello, JavaPoet!"); } } JavaPoet
  8. 42.

    import com.squareup.javapoet.*; MethodSpec main = MethodSpec.methodBuilder("main") .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .returns(void.class) .addParameter(String[].class,

    "args") .addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!") .build(); TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld") .addModifiers(Modifier.PUBLIC, Modifier.FINAL) .addMethod(main) .build(); JavaFile javaFile = JavaFile.builder("com.example.helloworld", helloWorld) .build(); javaFile.writeTo(System.out); JavaPoet method builder class builder file builder
  9. 44.

    AWS SDK for Java v2 “To provide SDK support for

    the many services that AWS owns, the AWS SDKs make extensive use of code generation” https://aws.amazon.com/blogs/developer/aws-sdk-for-java-2-x-released/
  10. 47.
  11. 48.

    “Dagger 2 is the first to implement the full stack

    with generated code” Dagger 2.x “Dependency injection frameworks have existed for years with a whole variety of APIs for configuring and injecting” https://dagger.dev/users-guide.html
  12. 69.

    Final thoughts code generation is a powerful technique use a

    code generator to generate client libraries contribute to open source projects
  13. 71.