Andrew Bwogi

A Meta-Metaprogramming Approach for Java

Abstract
Metaprogramming is used to abstract away complicated code by offering a more intuitive interface which automatically generates that code. Spoon and ASM are two metaprogram libraries for Java that operate on programs at source code and bytecode level respectively. The thesis investigates what subset of Spoon metaprograms can be transformed to functionally equivalent ASM metaprograms, how Spoon works as an interface to ASM and how the generated ASM metaprograms work. The metaprogram transformer combines code templates with the output from the code generation tool ASMifier. The method which verifies equivalence runs semantically equivalent test programs through Spoon metaprograms and generated ASM metaprograms, and compares the outputs with the code clone detection program SootDiff. Results show that there exists a subset of transformable Spoon metaprograms that insert an invocation together with its corresponding definition in the beginning of a chosen method or replace all return expressions of the method with the invocation if the return types match. Spoon itself can be abstracted away to leave a basic Java class as an interface for generating bytecode level metaprograms. The generated ASM metaprograms use the visitor design pattern and Java Reflection API to modify the input programs.