Meta-AspectJ

David Zook, Shan Shan Huang, Yannis Smaragdakis

Meta-AspectJ Tutorial

Entry Points

The first thing to know about MAJ is that there is a fixed set of entry points -- non-terminals in the AspectJ grammar -- that may be quoted and unquoted. Each of these entry points has a corresponding java class that represents its abstract syntax tree (AST). The table below lists the entry points, their corresponding AST classes, and sample usage:

Entry Point AST Class
(all paths prefixed by org.aspectj.compiler)
Example
Single Identifier base.ast.IDENT
IDENT foo = `[ MyClass ];
Identifier base.ast.Identifier
Identifer foo = `[ java.util.Vector ];
Identifier Pattern crosscuts.ast.NamePattern
NamePattern foo = `[ * ];
NamePattern bar = `[ java.lang.* ];
Modifiers base.ast.Modifiers
Modifiers foo = `[ public static ];
Import base.ast.Import
Import foo = `[ import java.lang.*; ];
Type Spec. base.ast.TypeD
TypeD foo = `[ MyClass ];
TypeD builtIn = `[ int ];
Formal Declaration base.ast.FormalDec
FormalDec foo = `[ int x ];
Variable Declaration base.ast.VarDec
VarDec foo = `[ int x = 0; ];
VarDec bar = `[ Object x, y; ];
Expression base.ast.JavaExpr
JavaExpr myInt = `[ 32 ];
JavaExpr myBool = `[ true && myInt == 32 ];
JavaExpr myMethCall = `[ a.foo(3, 5) ];
Statement base.ast.Stmt
Stmt myIncr = `[ x++; ];
Stmt myFor = `[ for ( int x=0; x++; x<5 ) {
                    foo(x);
                } ];
Stmt myEmpty = `[ {} ];
Method Declaration base.ast.MethodDec
MethodDec meth1 = `[ public void getY() { 
                         return y; 
                     } ];
Constructor Declaration base.ast.ConstructorDec
ConstructorDec myCons = `[ public Foo() {} ];
Class Declaration base.ast.ClassDec
ClassDec classFoo = 
    `[ public class Foo {
           public static final int x = 0;
       } ];
Interface Declaration base.ast.InterfaceDec
public interface myInterface {
    public void foo();
}
Compilation Unit Member (Java) base.ast.ClassMember This could be a Class Declaration or Interface Declaration
Compilation Unit Member (AspectJ) base.ast.AspectMember This could be Class Declaration, Interface Declaration, or Aspect Declaration
Compilation Unit base.ast.CompUnit
import java.lang.*;
import java.util.*;

public class Foo {
  private int m_iX = 0;

  public Foo() {   
  }
}
Intertype Declare crosscuts.ast.DeclareDec
DeclareDec d1 = 
    `[ declare parents : 
           myClass 
           implements java.io.Serializable ];
Advice Declaration crosscuts.ast.AdviceDec
AdviceDec myAdv = 
    `[ before():get(int Foo.y) {}];
Pointcut crosscuts.ast.Pcd
Pcd pcd1 = 
    `[ call (void Foo.m(int,int,...)) ];
Pcd pcd2 = 
    `[ execution (Foo.new(int)) ];
Pointcut Declaration crosscuts.ast.PointcutDec
PointcutDec pdec = 
    `[ private pointcut foo(Object o); ];
Aspect Declaration crosscuts.ast.AspectDec
AspectDec myAspect =
    `[ public aspect Foo {
           declare precedence: 
	       Security, Logging;

           before();get(int Foo.y) {}
       } ];