org.objectweb.fractal.julia.asm
Class MixinClassGenerator

java.lang.Object
  extended by org.objectweb.fractal.julia.asm.MixinClassGenerator
All Implemented Interfaces:
Opcodes, ClassGenerator

public class MixinClassGenerator
extends Object
implements ClassGenerator, Opcodes

A class generator to mix several mixin classes into a single class. A mixin class is a class of the following form:

 public abstract class XMixin implements I {

   // private constructor
   private XMixin () {}

   // fields and methods added or overriden by the mixin class
   public int i;
   public void m (String s) {
     _this_n();
     _super_m(_this_header + s + i);
   }
   // ...

   // fields and methods required by the mixin class in other mixins
   String _this_header;
   abstract void _this_n ();
   // original methods, overriden in this mixin class
   abstract void _super_m (String s);
   // ...
 }
 
The mix of several mixin classes M1 ... Mn, in this order, is a class that is equivalent to a class Mn subclassing Mn-1 ... sub classing M1. For example, if YMixin is a mixin of the following form:
 public abstract class YMixin {

   // private constructor
   private YMixin () {}

   // fields and methods added or overriden by the mixin class
   public String header;
   public void n () { ... }
   public void m (String s) {
     return header + s;
   }
 }
 
then the mix of YMixin and XMixin, in this order, is the following class:
 public class XYZ implements I, Generated {
   // from XMixin:
   public int i;
   public void m (String s) {
     n();
     return m$$0(header + s + i);
   }
   // from YMixin:
   public String header;
   public void n () { ... }
   private void m$$0 (String s) {
     return header + s;
   }
   // other methods
   public String getFcGeneratorParameters () {
     return "(...MixinClassGenerator source YMixin XMixin)";
   }
 }
 
As can be seen, the code of the mixin classes is copied into the mixed class, with some small transformations: fields and methods that are static or whose name begins with _this_ or _super_ are not copied, and overriden methods are renamed with a "$$n" suffix to avoid name clashes.

Several mixin classes can be mixed, in a specific order, only if the fields and methods required by each mixin class are provided by previous mixins classes in the mixin class list. For example, the XMixin can only be used if one or more previous mixin classes, in the mixed class list, provide a header field, a void n () method, and a void m (String s) method.

Notes:


Field Summary
 
Fields inherited from interface org.objectweb.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, V1_1, V1_2, V1_3, V1_4, V1_5
 
Constructor Summary
MixinClassGenerator()
           
 
Method Summary
 byte[] generateClass(String name, Tree args, Loader loader, ClassLoader classLoader)
          Generates a class by adding mixin classes to the given class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MixinClassGenerator

public MixinClassGenerator()
Method Detail

generateClass

public byte[] generateClass(String name,
                            Tree args,
                            Loader loader,
                            ClassLoader classLoader)
                     throws ClassGenerationException
Generates a class by adding mixin classes to the given class.

Specified by:
generateClass in interface ClassGenerator
Parameters:
name - the name of the class to be generated.
args - the descriptor of the class to be generated. This descriptor must be of the form (object descriptor source mixinClass1 ... mixinClassN), where source is a symbolic name to designate the mixed class - this name appears in stack traces, and where mixinClass1 ... mixinClassN are the class descriptors of the classes to be mixed.
loader - the loader to be used to load or generate auxiliary classes, if needed.
classLoader - the class loader to be used to load auxiliary classes, if needed.
Returns:
a sub class of the given class constructed by adding the applicable mixins classes to it.
Throws:
ClassGenerationException - if any other problem occurs.