Did you know that you can access and modify the complete AST of a Java program through the Pluggable Annotation Processing API? In this session, I hope to provide some inspiration by describing how this is done and by sharing lessons learned from building a generator feature (think yield) for Java.
Did you know that you can access and modify the complete AST of a Java program through the Pluggable Annotation Processing API? There are numerous projects that leverage this to add various interesting language features, such as implicitly typed variables. In this session, I will describe how this is done and share lessons learned from building a generator feature (think yield) for Java. I will touch upon subjects such as constraints imposed by compiler phases, AST rewriting, coding in unsupported API land and AST changes between Java versions, integration testing across Java versions, javac versus other compilers and IDE support. The purpose of the session is to inspire some fun Java hacking, and a fair amount of Java knowledge is assumed.