pnuts.compiler
Class JavaAdapter

java.lang.Object
  |
  +--pnuts.lang.Runtime
        |
        +--pnuts.compiler.JavaAdapter

public class JavaAdapter
extends Runtime
implements Constants, Opcode

This class provides a way to extends a Java class in Pnuts.


Fields inherited from interface pnuts.compiler.Constants
ACC_ABSTRACT, ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_Long, CONSTANT_Methodref, CONSTANT_NameAndType, CONSTANT_String, CONSTANT_Utf8
 
Fields inherited from interface pnuts.compiler.Opcode
AALOAD, AASTORE, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ANEWARRAY_QUICK, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, BALOAD, BASTORE, BIPUSH, BREAKPOINT, CALOAD, CASTORE, CHECKCAST, CHECKCAST_QUICK, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, 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, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETFIELD_QUICK, GETFIELD_QUICK_W, GETFIELD2_QUICK, GETSTATIC, GETSTATIC_QUICK, GETSTATIC2_QUICK, GOTO, GOTO_W, 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, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMPDEP1, IMPDEP2, IMUL, INEG, INSTANCEOF, INSTANCEOF_QUICK, INVOKEINTERFACE, INVOKEINTERFACE_QUICK, INVOKENONVIRTUAL_QUICK, INVOKESPECIAL, INVOKESTATIC, INVOKESTATIC_QUICK, INVOKESUPER_QUICK, INVOKEVIRTUAL, INVOKEVIRTUAL_QUICK, INVOKEVIRTUAL_QUICK_W, INVOKEVIRTUALOBJECT_QUICK, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, IUSHR, IXOR, JSR, JSR_W, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_QUICK, LDC_W, LDC_W_QUICK, LDC2_W, LDC2_W_QUICK, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, MULTIANEWARRAY_QUICK, NEW, NEW_QUICK, NEWARRAY, NOP, POP, POP2, PUTFIELD, PUTFIELD_QUICK, PUTFIELD_QUICK_W, PUTFIELD2_QUICK, PUTSTATIC, PUTSTATIC_QUICK, PUTSTATIC2_QUICK, RET, RETURN, SALOAD, SASTORE, SIPUSH, stackGrowth, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, WIDE
 
Constructor Summary
protected JavaAdapter()
           
 
Method Summary
static java.lang.Class generateEventAdapter(java.lang.Class listenerType, java.lang.String methodName)
          Generate an adapter class for bean events.
static java.lang.Class generateSubtype(java.lang.Class superClass, java.lang.Class[] interfaces, Package pkg, Context context)
          Generates a class that extends the superClass and implements the interfaces.
static ClassFile getClassFileForEventAdapter(java.lang.String className, java.lang.Class listenerType, java.lang.String methodName)
          Creates a class file of a event adapter that implements the specified listenerType.
static ClassFile getClassFileForSubtype(java.lang.String className, java.lang.Class superClass, java.lang.Class[] interfaces, Package pkg, Context context)
          Creates a class file image of a subtype of superClass (or some interfaces) and writes to the output stream.
 
Methods inherited from class pnuts.lang.Runtime
arrayType, assignRange, binary, call, callConstructor, callConstructor, callConstructor, callFunction, callMethod, callMethod, callMethod, cast, catchException, checkException, checkException, compareTo, escape, exec, execute, fileToURL, format, getBeginLine, getBottomType, getCompiledScript, getEndLine, getField, getFunction, getFunction, getFunctions, getIndex, getRuntime, getScriptSource, getScriptURL, getStaticField, isArray, jump, matchType, namespaceRefreshed, newInstance, parseChar, parseFloat, parseInt, parseString, primitive, printError, putField, putStaticField, quantity, range, readSymbolTable, setLine, setLine, setPackage, transform, unary, writeSymbolTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaAdapter

protected JavaAdapter()
Method Detail

generateSubtype

public static java.lang.Class generateSubtype(java.lang.Class superClass,
                                              java.lang.Class[] interfaces,
                                              Package pkg,
                                              Context context)
                                       throws java.lang.ClassNotFoundException
Generates a class that extends the superClass and implements the interfaces. Functions in the pkg are mapped to non-final/static public/protected methods with the same name and the same number of parameters. Note that this method may throw ClassFormatError.
Parameters:
superClass - super class that the generated class extends
interfaces - list of interfaces that the generated class implements
pkg - a Package that includes functions to be mapped to methods.
context - a Context in which functions are extracted from pkg
Returns:
the generated class

generateEventAdapter

public static java.lang.Class generateEventAdapter(java.lang.Class listenerType,
                                                   java.lang.String methodName)
Generate an adapter class for bean events. The generated class implements the the specified listenerType. The constructor has two arguments (PnutsFunction, Context). The method methodName calls a function which is specified as a parameter of the constructor.
Parameters:
listenerType - a Class object of a EventListener subclass
methodName - a method name of the listener type.
Returns:
a Class object of the generated class

getClassFileForSubtype

public static ClassFile getClassFileForSubtype(java.lang.String className,
                                               java.lang.Class superClass,
                                               java.lang.Class[] interfaces,
                                               Package pkg,
                                               Context context)
                                        throws java.lang.ClassNotFoundException
Creates a class file image of a subtype of superClass (or some interfaces) and writes to the output stream.
Parameters:
superClass - super class that the generated class extends
interfaces - list of interfaces that the generated class implements
pkg - a Package that includes functions to be mapped to methods.
context - a Context in which functions are extracted from pkg

getClassFileForEventAdapter

public static ClassFile getClassFileForEventAdapter(java.lang.String className,
                                                    java.lang.Class listenerType,
                                                    java.lang.String methodName)
Creates a class file of a event adapter that implements the specified listenerType. The constructor of the created class takes PnutsFunction and Context as the parameters. When the corresponding event is observed, the PnutsFunction is called in the Context.
Parameters:
className - the class name of the event adapter
listenerType - a Class object of a EventListener subclass
methodName - a method name of the listener type.