20120618, rgf

org.rexxla.bsf.engines.rexx
Class RexxExtendClass

java.lang.Object
  extended by org.objectweb.asm.ClassAdapter
      extended by org.rexxla.bsf.engines.rexx.RexxExtendClass
All Implemented Interfaces:
org.objectweb.asm.ClassVisitor, org.objectweb.asm.Opcodes

public class RexxExtendClass
extends org.objectweb.asm.ClassAdapter
implements org.objectweb.asm.ClassVisitor, org.objectweb.asm.Opcodes

Extends a supplied class and creates proxy methods (dispatching to RexxProxy objects), if the Java methods are defined as abstract or if a list of Java methods to proxy gets supplied in the constructor. All public constructors in the extended class expect a RexxProxy object as the first argument, followed by all the arguments in the defined order, if arguments are defined in the original class.

The extended class supplies the static public methods setDefaultHandler(RexxProxy rp) and RexxProxy getDefaultHandler() to set and get the default RexxProxy handler, which is used for forwarding static methods and when creating instances of the class and superclass constructors invoke instance methods.

An instance of the extended class has the methods RexxProxy getTargetRexxProxy() and setTargetRexxProxy(RexxProxy rp) implemented, which allow to retrieve or set the RexxProxy object to which method invocations get forwarded to.

If concrete instance methods of a class are generated in the extended class, then a method named "forwardToSuper" and one named "forwardToSuperStrict" will be created which allow the Rexx programmer to explicitly invoke masked methods in the super (extended) class.

If concrete static methods of a class are generated in the extended class, then a method named "forwardToSuperStatic" and one named "forwardToSuperStaticStrict" will be created which allow the Rexx programmer to explicitly invoke masked methods in the super (extended) class.

------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2009 Rony G. Flatscher

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ----------------------------------------------------------------------------- 

Since:
2009-07-29
Version:
1.0
Author:
Rony G. Flatscher (WU Vienna , http://www.wu-wien.ac.at/english)

Field Summary
(package private) static int[] arr_ICONST
           
protected static boolean bDebugClassVisitor
           
protected static boolean bDebugMethodVisitor
           
protected  org.objectweb.asm.ClassVisitor cv
          The ClassVisitor to which this adapter delegates calls.
(package private) static java.lang.String FORWARD_TO_SUPER_APPEND_STRING
           
(package private) static java.util.HashSet primitiveTypes
           
(package private) static java.lang.String rexxExceptionName
           
(package private) static java.lang.String rexxProxyName
           
(package private) static java.lang.String thisPgmName
           
(package private)  TransformationData tranData
           
(package private) static java.util.HashMap type2getPrimitiveValue
           
(package private) static java.util.HashMap type2initDesc
           
(package private) static java.util.HashMap type2syntheticWrapperFields
           
(package private) static java.util.HashMap type2valueOfDesc
           
(package private) static java.util.HashMap type2wrapperClass
           
 
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, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, 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, INTEGER, INVOKEDYNAMIC, INVOKEDYNAMIC_OWNER, 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, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, 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, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7
 
Constructor Summary
RexxExtendClass(org.objectweb.asm.ClassVisitor cv)
          Constructs a new ClassAdapter object.
RexxExtendClass(org.objectweb.asm.ClassVisitor cv, java.lang.String newClassName, int newClassVersion)
          Constructs a new ClassAdapter object.
RexxExtendClass(org.objectweb.asm.ClassVisitor cv, java.lang.String newClassName, int newClassVersion, java.lang.String[] methodNamesToAdd)
          Constructs a new ClassAdapter object.
 
Method Summary
static java.lang.String getMethodAccessAsString(int access)
           
(package private) static java.lang.String getPlainMethodSignature(TransformationData td)
          Create and return a string with the method's "desc" delimited with " | " and followed by the method's signature as one would have to give it in a Java program.
(package private) static java.lang.String getPlainValueSignature(org.objectweb.asm.Type t)
          Turn a desc type into the plain Java style; arrays like "[Z" or "[[java.lang.String" into "boolean []" resp.
 TransformationData getTranData()
           
(package private) static java.lang.String pp(java.lang.Object o)
           
 void visit(int version, int access, java.lang.String name, java.lang.String signature, java.lang.String superName, java.lang.String[] interfaces)
           
 org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String desc, boolean visible)
           
 void visitAttribute(org.objectweb.asm.Attribute attr)
           
 void visitEnd()
           
 org.objectweb.asm.FieldVisitor visitField(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.Object value)
           
 void visitInnerClass(java.lang.String name, java.lang.String outerName, java.lang.String innerName, int access)
           
 org.objectweb.asm.MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
           
 void visitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String desc)
           
 void visitSource(java.lang.String source, java.lang.String debug)
           
(package private)  void workAddClinitMethod(org.objectweb.asm.ClassVisitor cv)
          Create class initializer method.
(package private)  void workAddFields(org.objectweb.asm.ClassVisitor cv)
          Create instance and static fields we need.
(package private)  void workAddMethods(org.objectweb.asm.ClassVisitor cv)
          Create instance and static fields we need.
(package private)  void workConstructor(org.objectweb.asm.MethodVisitor mv)
          Creates the bytecode for processing arguments.
(package private)  void workProcessArgsAndInvoke(org.objectweb.asm.MethodVisitor mv)
          Creates the bytecode for processing arguments.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cv

protected org.objectweb.asm.ClassVisitor cv
The ClassVisitor to which this adapter delegates calls.


bDebugClassVisitor

protected static final boolean bDebugClassVisitor
See Also:
Constant Field Values

bDebugMethodVisitor

protected static final boolean bDebugMethodVisitor
See Also:
Constant Field Values

thisPgmName

static final java.lang.String thisPgmName
See Also:
Constant Field Values

rexxExceptionName

static final java.lang.String rexxExceptionName
See Also:
Constant Field Values

rexxProxyName

static final java.lang.String rexxProxyName
See Also:
Constant Field Values

FORWARD_TO_SUPER_APPEND_STRING

static final java.lang.String FORWARD_TO_SUPER_APPEND_STRING
See Also:
Constant Field Values

type2wrapperClass

static final java.util.HashMap type2wrapperClass

type2valueOfDesc

static final java.util.HashMap type2valueOfDesc

type2initDesc

static final java.util.HashMap type2initDesc

type2getPrimitiveValue

static final java.util.HashMap type2getPrimitiveValue

type2syntheticWrapperFields

static final java.util.HashMap type2syntheticWrapperFields

primitiveTypes

static final java.util.HashSet primitiveTypes

arr_ICONST

static final int[] arr_ICONST

tranData

TransformationData tranData
Constructor Detail

RexxExtendClass

public RexxExtendClass(org.objectweb.asm.ClassVisitor cv)
Constructs a new ClassAdapter object. This mode of operation will only implement abstract methods which will be executed by the RexxProxy.

Parameters:
cv - the class visitor to which this adapter must delegate calls.

RexxExtendClass

public RexxExtendClass(org.objectweb.asm.ClassVisitor cv,
                       java.lang.String newClassName,
                       int newClassVersion)
Constructs a new ClassAdapter object. This mode of operation will implement public abstract methods which will be executed by the RexxProxy. In addition it creates proxy methods for each Java method that carries a name as supplied in the methodNamesToAdd array.

This constructor will only create proxy methods for public abstract methods.

Parameters:
cv - the class visitor to which this adapter must delegate calls.
newClassName - determines new name of the class, if null, an attempt to create a unique name is undertaken
newClassVersion - if >0 overrides the source class' version

RexxExtendClass

public RexxExtendClass(org.objectweb.asm.ClassVisitor cv,
                       java.lang.String newClassName,
                       int newClassVersion,
                       java.lang.String[] methodNamesToAdd)
Constructs a new ClassAdapter object. This mode of operation will implement public abstract methods which will be executed by the RexxProxy. In addition it creates proxy methods for each Java method that carries a name as supplied in the methodNamesToAdd array. If the methodNamesToAdd array is null or empty, then all public methods will have a proxy method created for.

Parameters:
cv - the class visitor to which this adapter must delegate calls.
newClassName - determines new name of the class, if null, an attempt to create a unique name is undertaken
newClassVersion - if >0 overrides the source class' version
methodNamesToAdd - a String array containing (caseless) method names for which proxy methods should be created; if callbacks to the RexxProxy are desired from constructors, then they need to be added to this String array under the name "" (the Java internal name of constructors).
Method Detail

getTranData

public TransformationData getTranData()

visit

public void visit(int version,
                  int access,
                  java.lang.String name,
                  java.lang.String signature,
                  java.lang.String superName,
                  java.lang.String[] interfaces)
Specified by:
visit in interface org.objectweb.asm.ClassVisitor
Overrides:
visit in class org.objectweb.asm.ClassAdapter

visitSource

public void visitSource(java.lang.String source,
                        java.lang.String debug)
Specified by:
visitSource in interface org.objectweb.asm.ClassVisitor
Overrides:
visitSource in class org.objectweb.asm.ClassAdapter

visitOuterClass

public void visitOuterClass(java.lang.String owner,
                            java.lang.String name,
                            java.lang.String desc)
Specified by:
visitOuterClass in interface org.objectweb.asm.ClassVisitor
Overrides:
visitOuterClass in class org.objectweb.asm.ClassAdapter

visitAnnotation

public org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String desc,
                                                           boolean visible)
Specified by:
visitAnnotation in interface org.objectweb.asm.ClassVisitor
Overrides:
visitAnnotation in class org.objectweb.asm.ClassAdapter

visitAttribute

public void visitAttribute(org.objectweb.asm.Attribute attr)
Specified by:
visitAttribute in interface org.objectweb.asm.ClassVisitor
Overrides:
visitAttribute in class org.objectweb.asm.ClassAdapter

visitInnerClass

public void visitInnerClass(java.lang.String name,
                            java.lang.String outerName,
                            java.lang.String innerName,
                            int access)
Specified by:
visitInnerClass in interface org.objectweb.asm.ClassVisitor
Overrides:
visitInnerClass in class org.objectweb.asm.ClassAdapter

visitField

public org.objectweb.asm.FieldVisitor visitField(int access,
                                                 java.lang.String name,
                                                 java.lang.String desc,
                                                 java.lang.String signature,
                                                 java.lang.Object value)
Specified by:
visitField in interface org.objectweb.asm.ClassVisitor
Overrides:
visitField in class org.objectweb.asm.ClassAdapter

visitMethod

public org.objectweb.asm.MethodVisitor visitMethod(int access,
                                                   java.lang.String name,
                                                   java.lang.String desc,
                                                   java.lang.String signature,
                                                   java.lang.String[] exceptions)
Specified by:
visitMethod in interface org.objectweb.asm.ClassVisitor
Overrides:
visitMethod in class org.objectweb.asm.ClassAdapter

visitEnd

public void visitEnd()
Specified by:
visitEnd in interface org.objectweb.asm.ClassVisitor
Overrides:
visitEnd in class org.objectweb.asm.ClassAdapter

workConstructor

void workConstructor(org.objectweb.asm.MethodVisitor mv)
Creates the bytecode for processing arguments.


workProcessArgsAndInvoke

void workProcessArgsAndInvoke(org.objectweb.asm.MethodVisitor mv)
Creates the bytecode for processing arguments.

Parameters:
mv - MethodVisitor object to interact with

workAddFields

void workAddFields(org.objectweb.asm.ClassVisitor cv)
Create instance and static fields we need.


workAddMethods

void workAddMethods(org.objectweb.asm.ClassVisitor cv)
Create instance and static fields we need.


workAddClinitMethod

void workAddClinitMethod(org.objectweb.asm.ClassVisitor cv)
Create class initializer method.


getMethodAccessAsString

public static java.lang.String getMethodAccessAsString(int access)

getPlainMethodSignature

static java.lang.String getPlainMethodSignature(TransformationData td)
Create and return a string with the method's "desc" delimited with " | " and followed by the method's signature as one would have to give it in a Java program.


getPlainValueSignature

static java.lang.String getPlainValueSignature(org.objectweb.asm.Type t)
Turn a desc type into the plain Java style; arrays like "[Z" or "[[java.lang.String" into "boolean []" resp. "java.lang.String [][][]".


pp

static java.lang.String pp(java.lang.Object o)

20120618, rgf