org.objectweb.fractal.julia.asm
Class MergeClassGenerator

java.lang.Object
  extended byorg.objectweb.fractal.julia.asm.MergeClassGenerator
All Implemented Interfaces:
ClassGenerator, Constants

public class MergeClassGenerator
extends Object
implements ClassGenerator, Constants

A class generator to merge several classes into a single one. This class generator copies all the non static fields and all the non static methods of the given classes (and of their super class, super super class, and so on) into a new class, with the following exceptions:

Notes: Except for the "weaveable" fields, and for the Controller method, the fields and methods of the classes to be merged should all be distinct: otherwise the generated class will not be valid, because of duplicated field or method declarations.

As an example, the merging of the B and C classes below:

 public class A {
   public int a;
   public void m () { ... }
 }

 public class B extends A implements I {
   private int b;
   private J weaveableJ;
   private K weaveableOptK;
   public void m () { super.m(); ... }
   public void n () { weaveableJ.o(weaveableOptK); }
 }

 public class C implement J {
   public void o (K k) { p(); }
   public static p () { q(); }
   private static q () { ... }
 }
 
is the following class:
 public class XYZ implements I, J, Generated {
   public int a;                  // copied from B's super class
   private int b;                 // copied from B
   // weaveableJ                  // NOT copied
   // weaveableOptK               // NOT copied
   private void m$0 () { ... }           // copied from B's super class
   public void m () { m$0(); ... }       // copied from B
   public void n () { o(null); }  // copied from B
   public void o (K k) { C.p(); } // copied from C
   // p                           // NOT copied (static)
   // q                           // NOT copied (static)
   public String getFcGeneratorParameters () {
     return "(...MergeClassGenerator java.lang.Object B C)";
   }
 }
 


Field Summary
 Loader loader
          The class whose class loader must be used to generate the class.
 String parameters
          The parameters used to generate the merged class.
 
Fields inherited from interface org.objectweb.asm.Constants
AALOAD, AASTORE, ACC_ABSTRACT, 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
 
Constructor Summary
MergeClassGenerator()
           
 
Method Summary
 byte[] generateClass(String name, Tree args, Loader loader)
          Generates a class by merging the given classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loader

public Loader loader
The class whose class loader must be used to generate the class. May be null.


parameters

public String parameters
The parameters used to generate the merged class.

Constructor Detail

MergeClassGenerator

public MergeClassGenerator()
Method Detail

generateClass

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

Specified by:
generateClass in interface ClassGenerator
Parameters:
name - the name of the class to be generated.
args - a tree of the form "(objectDescriptor superClassName className1 ... classNameN)", where className1 ... classNameN are the names of the classes to be merged, and superClassName is the name of the super class to be used for the merged class.
loader - the loader to be used to load or generate auxiliary classes, if needed.
Returns:
a class constructed by merging the given classes.
Throws:
ClassGenerationException - if a problem occurs during the generation of the class.