Design and implementation of the @Java system

   Annotations are a recent feature introduced in languages such as Java,
C#, and other languages of the .NET family, which allow programmers
to attach arbitrary, structured and typed metadata to their code. These
languages run on top of so-called virtual execution environments, e.g. the
JVM for Java, and the CLR for .NET languages, which allow for the run-time
generation of executable code. In this report we explore how annotations
and the dynamic code generation capability can be used together to
provide programmers with high-level methods for dynamic generation and
modification of an application’s code — at run-time. The report describes
the framework @Java system, the Java libraries it is constituted by, and
the @Java language, which is an extension to Java allowing annotation
of arbitrary statements. The strategy we developed consists in parsing
a source file written using @Java language to produce a Java 5 compatible
source file. Once compiled, information about annotated statements,
such as their bytecode instructions, can be recovered at run-time. We
developed two libraries, one that works at low level to do generic bytecode
engineering called JDAsm, and one at high level called JCodeBrick.
Together, these two libraries allow type-safe and totally symbolic runtime
code modification and generation without any need to explicitly address
bytecode instructions, letting a programmer to easily manipulate exist-
ing classes or to synthesize new ones, by inserting, deleting or extruding
pieces of code.
   After an overview of the Annotations in Section 2, we address the
@Java language and its parser in Section 3. Then a full description of
the two libraries for bytecode engineering and code manipulation follows
in Section 4 and 5. We introduce then in Section 6 a few motivating examples
of applications of @Java, and provide a more developed case study in Section7.
The last section offers conclusions and ideas for future work. The
documentation of the two libraries is provided in Appendix A, completing the
report.