20091031, 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)
          Visits the header of the class.
 org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String desc, boolean visible)
          Visits an annotation of the class.
 void visitAttribute(org.objectweb.asm.Attribute attr)
          Visits a non standard attribute of the class.
 void visitEnd()
          Visits the end of the class.
 org.objectweb.asm.FieldVisitor visitField(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.Object value)
          Visits a field of the class.
 void visitInnerClass(java.lang.String name, java.lang.String outerName, java.lang.String innerName, int access)
          Visits information about an inner class.
 org.objectweb.asm.MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
          Visits a method of the class.
 void visitOuterClass(java.lang.String owner, java.lang.String name, java.lang.String desc)
          Visits the enclosing class of the class.
 void visitSource(java.lang.String source, java.lang.String debug)
          Visits the source of the class.
(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)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits the header of the class.

Specified by:
visit in interface org.objectweb.asm.ClassVisitor
Overrides:
visit in class org.objectweb.asm.ClassAdapter
Parameters:
version - the class version.
access - the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated.
name - the internal name of the class (see getInternalName).
signature - the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
superName - the internal of name of the super class (see getInternalName). For interfaces, the super class is Object. May be null, but only for the Object class.
interfaces - the internal names of the class's interfaces (see getInternalName). May be null.

visitSource

public void visitSource(java.lang.String source,
                        java.lang.String debug)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits the source of the class.

Specified by:
visitSource in interface org.objectweb.asm.ClassVisitor
Overrides:
visitSource in class org.objectweb.asm.ClassAdapter
Parameters:
source - the name of the source file from which the class was compiled. May be null.
debug - additional debug information to compute the correspondance between source and compiled elements of the class. May be null.

visitOuterClass

public void visitOuterClass(java.lang.String owner,
                            java.lang.String name,
                            java.lang.String desc)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits the enclosing class of the class. This method must be called only if the class has an enclosing class.

Specified by:
visitOuterClass in interface org.objectweb.asm.ClassVisitor
Overrides:
visitOuterClass in class org.objectweb.asm.ClassAdapter
Parameters:
owner - internal name of the enclosing class of the class.
name - the name of the method that contains the class, or null if the class is not enclosed in a method of its enclosing class.
desc - the descriptor of the method that contains the class, or null if the class is not enclosed in a method of its enclosing class.

visitAnnotation

public org.objectweb.asm.AnnotationVisitor visitAnnotation(java.lang.String desc,
                                                           boolean visible)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits an annotation of the class.

Specified by:
visitAnnotation in interface org.objectweb.asm.ClassVisitor
Overrides:
visitAnnotation in class org.objectweb.asm.ClassAdapter
Parameters:
desc - the class descriptor of the annotation class.
visible - true if the annotation is visible at runtime.
Returns:
a visitor to visit the annotation values, or null if this visitor is not interested in visiting this annotation.

visitAttribute

public void visitAttribute(org.objectweb.asm.Attribute attr)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits a non standard attribute of the class.

Specified by:
visitAttribute in interface org.objectweb.asm.ClassVisitor
Overrides:
visitAttribute in class org.objectweb.asm.ClassAdapter
Parameters:
attr - an attribute.

visitInnerClass

public void visitInnerClass(java.lang.String name,
                            java.lang.String outerName,
                            java.lang.String innerName,
                            int access)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits information about an inner class. This inner class is not necessarily a member of the class being visited.

Specified by:
visitInnerClass in interface org.objectweb.asm.ClassVisitor
Overrides:
visitInnerClass in class org.objectweb.asm.ClassAdapter
Parameters:
name - the internal name of an inner class (see getInternalName).
outerName - the internal name of the class to which the inner class belongs (see getInternalName). May be null for not member classes.
innerName - the (simple) name of the inner class inside its enclosing class. May be null for anonymous inner classes.
access - the access flags of the inner class as originally declared in the enclosing class.

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)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits a field of the class.

Specified by:
visitField in interface org.objectweb.asm.ClassVisitor
Overrides:
visitField in class org.objectweb.asm.ClassAdapter
Parameters:
access - the field's access flags (see Opcodes). This parameter also indicates if the field is synthetic and/or deprecated.
name - the field's name.
desc - the field's descriptor (see Type).
signature - the field's signature. May be null if the field's type does not use generic types.
value - the field's initial value. This parameter, which may be null if the field does not have an initial value, must be an Integer, a Float, a Long, a Double or a String (for int, float, long or String fields respectively). This parameter is only used for static fields. Its value is ignored for non static fields, which must be initialized through bytecode instructions in constructors or methods.
Returns:
a visitor to visit field annotations and attributes, or null if this class visitor is not interested in visiting these annotations and attributes.

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)
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits a method of the class. This method must return a new MethodVisitor instance (or null) each time it is called, i.e., it should not return a previously returned visitor.

Specified by:
visitMethod in interface org.objectweb.asm.ClassVisitor
Overrides:
visitMethod in class org.objectweb.asm.ClassAdapter
Parameters:
access - the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
name - the method's name.
desc - the method's descriptor (see Type).
signature - the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
exceptions - the internal names of the method's exception classes (see getInternalName). May be null.
Returns:
an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

visitEnd

public void visitEnd()
Description copied from interface: org.objectweb.asm.ClassVisitor
Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all the fields and methods of the class have been visited.

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)

20091031, rgf