org.datanucleus.enhancer.bcel
Class BCELUtils

java.lang.Object
  extended by org.datanucleus.enhancer.bcel.BCELUtils

public final class BCELUtils
extends java.lang.Object

Enhancer utility class for BCEL.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages.
 
Method Summary
static void addSynthetic(org.apache.bcel.classfile.FieldOrMethod m, org.apache.bcel.generic.ConstantPoolGen constantPoolGen)
          add synthetic attribute
static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.generic.ClassGen targetClasGen, java.lang.String name, java.lang.String signature)
          find method
static java.lang.String firstUpper(java.lang.String s)
          convert string to first upper string.
static java.lang.String getBcelType2JavaTypeString(org.apache.bcel.generic.Type t)
           
static org.apache.bcel.generic.Type getBCELTypeFromJavaType(java.lang.String typeName)
          Provide the BCEL Type given the java class name.
static org.apache.bcel.generic.Instruction getBIPUSH(int i)
          return perfect for instruction of type for const int push operand.
static org.apache.bcel.generic.ClassGen getClassByFieldByName(java.lang.String fieldName, org.apache.bcel.generic.ClassGen classGen)
          find Field object by name
static org.apache.bcel.generic.ClassGen getClassByFieldByName(java.lang.String fieldName, org.apache.bcel.classfile.JavaClass classGen)
          find Field object by name
static org.apache.bcel.classfile.Field getFieldByName(java.lang.String fieldName, org.apache.bcel.generic.ClassGen classGen)
          find Field object by name
static org.apache.bcel.classfile.Field getFieldByName(java.lang.String fieldName, org.apache.bcel.classfile.JavaClass classGen)
          find Field object by name
static org.apache.bcel.classfile.Method getGetterByName(java.lang.String fieldName, org.apache.bcel.generic.ClassGen classGen)
          find Field object by name
static java.lang.String getGetterName(org.apache.bcel.classfile.Field f)
          create getter name from Field
static java.lang.String getGetterName(java.lang.String fieldName)
          create getter name from Field
static java.lang.String getJDOMethodName(org.apache.bcel.classfile.Field f)
           
static java.lang.String getJDOMethodName(org.apache.bcel.generic.Type t)
          return JDO method type name by type.
static org.apache.bcel.generic.Type getJDOMethodType(org.apache.bcel.generic.Type t)
          Return JDO method BCEL's type from BCEL's field type.
static org.apache.bcel.generic.ObjectType getPrimitiveWrapperType(org.apache.bcel.generic.BasicType bt)
          return primitive wraper type.
static java.lang.String getSetterName(org.apache.bcel.classfile.Field f)
          create setter name from Field
static java.lang.String getSetterName(java.lang.String fieldName)
          create setter name from Field
static boolean isInstanceof(org.apache.bcel.classfile.JavaClass targetClass, java.lang.Class interfaceClass)
          Same result targetClass.newInstance instanceof interfaceClass
static boolean isSynthetic(org.apache.bcel.classfile.Attribute[] attrs)
          Check method or field is synthetic.
static boolean isSynthetic(org.apache.bcel.classfile.FieldOrMethod m)
          Check method or field is synthetic.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static org.datanucleus.util.Localiser LOCALISER
Localiser for messages.

Method Detail

firstUpper

public static java.lang.String firstUpper(java.lang.String s)
convert string to first upper string. test -> Test

Parameters:
s - original string
Returns:
first upper string

getSetterName

public static java.lang.String getSetterName(org.apache.bcel.classfile.Field f)
create setter name from Field

Parameters:
f - field
Returns:
setter name

getSetterName

public static java.lang.String getSetterName(java.lang.String fieldName)
create setter name from Field

Parameters:
fieldName - Name of field
Returns:
setter name

getGetterName

public static java.lang.String getGetterName(org.apache.bcel.classfile.Field f)
create getter name from Field

Parameters:
f - field
Returns:
getter name

getGetterName

public static java.lang.String getGetterName(java.lang.String fieldName)
create getter name from Field

Parameters:
fieldName - field
Returns:
getter name

findMethod

public static org.apache.bcel.classfile.Method findMethod(org.apache.bcel.generic.ClassGen targetClasGen,
                                                          java.lang.String name,
                                                          java.lang.String signature)
find method

Parameters:
targetClasGen - target class
name - method name
signature - method signature
Returns:
target method. return null if method not found.

getJDOMethodType

public static org.apache.bcel.generic.Type getJDOMethodType(org.apache.bcel.generic.Type t)
Return JDO method BCEL's type from BCEL's field type.
Original TypeReturn Type
Type.BOOLEAN Type.BOOLEAN
Type.BYTE Type.BYTE
Type.CHAR Type.CHAR
Type.DOUBLE Type.DOUBLE
Type.FLOAT Type.FLOAT
Type.INT Type.INT
Type.LONG Type.LONG
Type.SHORT Type.SHORT
Type.STRING Type.STRING
[OTHER] Type.OBJECT

Parameters:
t - original type
Returns:
method type

getJDOMethodName

public static java.lang.String getJDOMethodName(org.apache.bcel.classfile.Field f)

getJDOMethodName

public static java.lang.String getJDOMethodName(org.apache.bcel.generic.Type t)
return JDO method type name by type.

Original TypeReturn String
Type.BOOLEAN Boolean
Type.BYTE Byte
Type.CHAR Char
Type.DOUBLE Double
Type.FLOAT Float
Type.INT Int
Type.LONG Long
Type.SHORT Short
Type.STRING String
[OTHER] Object

Parameters:
t - original type
Returns:
method type name

getBCELTypeFromJavaType

public static org.apache.bcel.generic.Type getBCELTypeFromJavaType(java.lang.String typeName)
Provide the BCEL Type given the java class name.

Parameters:
typeName - The type of the field
Returns:
The ObjectType

getBIPUSH

public static org.apache.bcel.generic.Instruction getBIPUSH(int i)
return perfect for instruction of type for const int push operand.

Parameters:
i - push num
Returns:
push instruction

getPrimitiveWrapperType

public static org.apache.bcel.generic.ObjectType getPrimitiveWrapperType(org.apache.bcel.generic.BasicType bt)
return primitive wraper type.

Parameters:
bt - original type
Returns:
wrapper type

getBcelType2JavaTypeString

public static java.lang.String getBcelType2JavaTypeString(org.apache.bcel.generic.Type t)

getFieldByName

public static org.apache.bcel.classfile.Field getFieldByName(java.lang.String fieldName,
                                                             org.apache.bcel.generic.ClassGen classGen)
find Field object by name

Parameters:
fieldName - field name
classGen - class gen
Returns:
field object. return null if field not found.

getGetterByName

public static org.apache.bcel.classfile.Method getGetterByName(java.lang.String fieldName,
                                                               org.apache.bcel.generic.ClassGen classGen)
find Field object by name

Parameters:
fieldName - field name
classGen - class gen
Returns:
field object. return null if field not found.

getFieldByName

public static org.apache.bcel.classfile.Field getFieldByName(java.lang.String fieldName,
                                                             org.apache.bcel.classfile.JavaClass classGen)
find Field object by name

Parameters:
fieldName - field name
classGen - class gen
Returns:
field object. return null if field not found.

getClassByFieldByName

public static org.apache.bcel.generic.ClassGen getClassByFieldByName(java.lang.String fieldName,
                                                                     org.apache.bcel.generic.ClassGen classGen)
find Field object by name

Parameters:
fieldName - field name
classGen - class gen
Returns:
field object. return null if field not found.

getClassByFieldByName

public static org.apache.bcel.generic.ClassGen getClassByFieldByName(java.lang.String fieldName,
                                                                     org.apache.bcel.classfile.JavaClass classGen)
find Field object by name

Parameters:
fieldName - field name
classGen - class gen
Returns:
field object. return null if field not found.

addSynthetic

public static void addSynthetic(org.apache.bcel.classfile.FieldOrMethod m,
                                org.apache.bcel.generic.ConstantPoolGen constantPoolGen)
add synthetic attribute

Parameters:
m - method or field
constantPoolGen - target ConstantPoolGen instance

isSynthetic

public static boolean isSynthetic(org.apache.bcel.classfile.FieldOrMethod m)
Check method or field is synthetic.

Parameters:
m - field or method
Returns:
Return true if method or field is synthetic.

isSynthetic

public static boolean isSynthetic(org.apache.bcel.classfile.Attribute[] attrs)
Check method or field is synthetic.

Parameters:
attrs - Attributes of Field or Method
Returns:
Return true if method or field is synthetic.

isInstanceof

public static boolean isInstanceof(org.apache.bcel.classfile.JavaClass targetClass,
                                   java.lang.Class interfaceClass)
                            throws java.lang.ClassNotFoundException
Same result targetClass.newInstance instanceof interfaceClass

Parameters:
targetClass - Target class instance
interfaceClass - Check class instance
Returns:
return true if targetInstance.newInstance() instanceof interfaseClass.
Throws:
java.lang.ClassNotFoundException


Copyright © 2009. All Rights Reserved.