Meta-AspectJ

David Zook, Shan Shan Huang, Yannis Smaragdakis

Unquote Splice

Unquote splice comes in handy when you have a dynamic array of elements you would like to include in a quoted piece of code. The entry points that can be used for unquote splice are:

You can then put the variable of the above type anywhere that might be gramatically correct. For example:

    // Method m is declared
    ...
    Class[] mParms = m.getParameterTypes();

    FormalDec[] formals = new FormalDec[mParms.length];
    JavaExpr[] arguments = new JavaExpr[mParms.length];
    for ( int j=0; j < formals.length; j++) {
        formals[j] = `[#[mParms[j].getName()] #["arg"+i]];
	arguments[j] = `[#[mParms[j].getName()]];
    }

    ...

    String mName = m.getName();
    infer aMethod =
        `[
	     public void #mName ( #formals ) {
                 #["super." + mName] ( #arguments );
	     }
         ];    
The above piece of code utilizes unquote splice for Formal Declaration and Expression, to produce a new method (infer aMethod).