Meta-AspectJ, MAJ, is a language tool for generating
syntactically correct AspectJ (and Java) programs. MAJ can be used to:
MAJ extends Java with 3 keywords:
MAJ guarantees the syntactic correctness of all generated code by
type-checking the generator. A
research paper
("Generating AspectJ Programs with Meta-AspectJ"--GPCE'04 Best Paper award) describes
MAJ in detail.
Meta-AspectJ combines AspectJ with code-generation. The
value of MAJ is thus found in the reasons why neither AspectJ nor
code-generation alone is sufficient.
AspectJ is a great tool for addressing cross-cutting
concerns such as security and persistence. While it provides some
syntax for dealing with the dynamic creation of aspects, such as
wildcard (*) characters in specifying names,
it does not provide any support for adapting an application based on
characteristics not evident in the names. For example, you cannot
create an aspect that only applies to classes that do not already
implement a particular interface. Using MAJ, a user can leverage the
full power of Java to create complex joinpoints that AspectJ does not
support.
Why then, can we not use code-generation alone? We
could, but AspectJ provides a convenient and mature vocabulary for
talking about many commonly used program transformations. It is a
sufficient abstraction that code generation can work on top of to
provide the extra flexibility.
MAJ as Meta-Java
MAJ can also be used to generate plain Java programs. In
fact, MAJ is possibly the most advanced meta-programming tool for Java.
MAJ's inference capabilities make it very user-friendly because the user
does not need to remember the types of syntax tree entities.
We have used MAJ to reimplement GOTECH, a framework
used for turning existing Java classes into EJB's with minimum user
guidance. The original GOTECH framework uses XDoclet, which is a
text-based tool, to generate AspectJ. A complete GOTECH package
implemented with MAJ will be posted here.
See also a recent paper describing possible uses of MAJ for implementing
small, annotation-based languages.