org.springsource.loaded
Class Utils

java.lang.Object
  extended by org.springsource.loaded.Utils
All Implemented Interfaces:
org.objectweb.asm.Opcodes, Constants

public class Utils
extends java.lang.Object
implements org.objectweb.asm.Opcodes, Constants

Utility functions for use throughout SpringLoaded

Since:
0.5.0

Nested Class Summary
static class Utils.ReturnType
           
 
Field Summary
static java.lang.String[] NO_STRINGS
           
 
Fields inherited from interface org.springsource.loaded.Constants
ACC_PRIVATE_PROTECTED, ACC_PRIVATE_STATIC, ACC_PRIVATE_STATIC_FINAL, ACC_PUBLIC_ABSTRACT, ACC_PUBLIC_INTERFACE, ACC_PUBLIC_PRIVATE_PROTECTED, ACC_PUBLIC_PROTECTED, ACC_PUBLIC_STATIC, ACC_PUBLIC_STATIC_FINAL, ACC_PUBLIC_STATIC_SYNTHETIC, ACC_PUBLIC_SYNTHETIC, DEFAULT_BOOLEAN, DEFAULT_BYTE, DEFAULT_CHAR, DEFAULT_DOUBLE, DEFAULT_FLOAT, DEFAULT_INT, DEFAULT_LONG, DEFAULT_SHORT, descriptorChangedForInvokeSpecialName, executorClassNamePattern, fInstanceFieldsName, fReloadableTypeFieldName, fStaticFieldsName, JLC_GETCONSTRUCTOR, JLC_GETDECLAREDCONSTRUCTOR, JLC_GETDECLAREDFIELD, JLC_GETDECLAREDFIELDS, JLC_GETDECLAREDMETHOD, JLC_GETDECLAREDMETHODS, JLC_GETFIELD, JLC_GETMETHOD, JLC_GETMETHODS, JLC_GETMODIFIERS, jlcgc, jlcgcDescriptor, jlcgdc, jlcgdcDescriptor, jlcgdf, jlcgdfDescriptor, jlcgdfs, jlcgdfsDescriptor, jlcgdm, jlcgdmDescriptor, jlcgdms, jlcgdmsDescriptor, jlcgf, jlcgfDescriptor, jlcgm, jlcgmDescriptor, jlcgmods, jlcgmodsDescriptor, jlcgms, jlcgmsDescriptor, jlObject, lDynamicallyDispatchable, lInstanceStateManager, lRegistryType, lReloadableType, lStaticStateManager, magicDescriptorForGeneratedCtors, mChangedForConstructorName, mChangedForInvocationName, mChangedForInvokeInterfaceName, mChangedForInvokeSpecialName, mChangedForInvokeStaticName, mChangedForInvokeVirtualName, mDynamicDispatchDescriptor, mDynamicDispatchName, methodSuffixSuperDispatcher, mInitializerName, mInstanceFieldGetterDescriptor, mInstanceFieldGetterName, mInstanceFieldInterceptionRequired, mInstanceFieldSetterDescriptor, mInstanceFieldSetterName, mStaticFieldGetterName, mStaticFieldInterceptionRequired, mStaticFieldSetterDescriptor, mStaticFieldSetterName, mStaticInitializerName, NO_FIELDS, NO_METHODS, PREFIX, tDynamicallyDispatchable, tInstanceStateManager, tRegistryType, tReloadableType, tStaticStateManager, WAS_INVOKESTATIC, WAS_INVOKEVIRTUAL
 
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
Utils()
           
 
Method Summary
static void addCorrectReturnInstruction(org.objectweb.asm.MethodVisitor mv, Utils.ReturnType returnType, boolean createCast)
          Depending on the signature of the return type, add the appropriate instructions to the method visitor.
static java.lang.String annotationNodeFormat(org.objectweb.asm.tree.AnnotationNode o)
           
static void appendDescriptor(java.lang.Class<?> p, java.lang.StringBuilder s)
           
static
<T> T[]
arrayCopyOf(T[] array, int newSize)
          Utility method similar to Java 1.6 Arrays.copyOf, used instead of that method to stick to Java 1.5 only API.
static void assertDotted(java.lang.String name)
           
static void assertSlashed(java.lang.String name)
           
static void assertTrue(boolean condition, java.lang.String detail)
           
static java.lang.Object checkCompatibility(TypeRegistry registry, java.lang.Object result, java.lang.String expectedTypeDescriptor)
          Check that the value we have discovered is of the right type.
static int collapseStackToArray(org.objectweb.asm.MethodVisitor mv, java.lang.String desc)
          Produce the bytecode that will collapse the stack entries into an array - the descriptor describes what is being packed.
static void createLoadsBasedOnDescriptor(org.objectweb.asm.MethodVisitor mv, java.lang.String descriptor, int startindex)
          Create the set of LOAD instructions to load the method parameters.
static long decode(java.lang.String s)
          Decode a base62 encoded string into a number (base10).
static java.lang.String[] discoverInterfaces(byte[] classbytes)
          Determine the interfaces implemented by a given class (supplied as bytes)
static java.lang.String dump(java.lang.String slashname, byte[] bytesLoaded)
          Dump the specified bytes under the specified name in the filesystem.
static void dumpClass(java.lang.String file, byte[] bytes)
          Dump some bytes into the specified file.
static java.lang.String encode(long number)
          Convert a number (base10) to base62 encoded string
static java.lang.String fieldNodeFormat(java.util.Collection<org.objectweb.asm.tree.FieldNode> fieldNodes)
           
static java.lang.String fieldNodeFormat(org.objectweb.asm.tree.FieldNode fieldNode)
           
static void formatAnnotationNodeNameValuePairValue(java.lang.Object value, java.lang.StringBuilder s)
           
static void generateInstructionsToUnpackArrayAccordingToDescriptor(org.objectweb.asm.MethodVisitor mv, java.lang.String toCallDescriptor, int arrayVariableIndex)
          Generate the instructions in the specified method visitor to unpack an assumed array (on top of the stack) according to the specified descriptor.
static java.lang.String getDispatcherName(java.lang.String name, java.lang.String versionstamp)
           
static java.lang.String getExecutorName(java.lang.String name, java.lang.String versionstamp)
          Generate the name for the executor class.
static java.lang.String getInterfaceName(java.lang.String owner)
           
static int getParameterCount(java.lang.String methodDescriptor)
          Return the number of parameters in the descriptor.
static java.lang.String getParamSequence(java.lang.String descriptor)
          Return a simple sequence for the descriptor where type references are collapsed to 'O', so (IILjava/lang/String;Z) will return IIOZ.
static java.lang.String getProtectedFieldGetterName(java.lang.String fieldname)
           
static java.lang.String getProtectedFieldSetterName(java.lang.String fieldname)
           
static Utils.ReturnType getReturnTypeDescriptor(java.lang.String methodDescriptor)
          Discover the descriptor for the return type.
static int getSize(java.lang.String descriptor)
          Compute the size required for a specific method descriptor.
static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv, char ch)
           
static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv, java.lang.String type)
           
static java.lang.String insertExtraParameter(java.lang.String classname, java.lang.String descriptor)
           
static int insertPopsForAllParameters(org.objectweb.asm.MethodVisitor mv, java.lang.String desc)
          Looks at the supplied descriptor and inserts enough pops to remove all parameters.
static void insertUnboxInsns(org.objectweb.asm.MethodVisitor mv, char ch, boolean isObject)
           
static void insertUnboxInsnsIfNecessary(org.objectweb.asm.MethodVisitor mv, java.lang.String type, boolean isObject)
           
static boolean isAssignableFrom(java.lang.String lookingFor, TypeDescriptor candidate)
          Determine if the type specified in lookingFor is a supertype (class/interface) of the specified typedescriptor, i.e.
static boolean isAssignableFrom(TypeRegistry reg, java.lang.Class<?> clazz, java.lang.String lookingFor)
           
static boolean isConvertableFrom(java.lang.Class<?> targetType, java.lang.Class<?> sourceType)
           
static boolean isInitializer(java.lang.String membername)
           
static boolean isObjectIsUnboxableTo(java.lang.Class<?> possiblyBoxedType, char primitive)
           
static byte[] load(java.io.File file)
           
static byte[] loadBytesFromStream(java.io.InputStream stream)
          Load all the byte data from an input stream.
static byte[] loadDottedClassAsBytes(java.lang.ClassLoader loader, java.lang.String dottedclassname)
          Access the specified class as a resource accessible through the specified loader and return the bytes.
static byte[] loadFromStream(java.io.InputStream stream)
          Load the contents of an input stream.
static byte[] loadSlashedClassAsBytes(java.lang.ClassLoader loader, java.lang.String slashedclassname)
          Access the specified class as a resource accessible through the specified loader and return the bytes.
static void logAndThrow(java.util.logging.Logger log, java.lang.String message)
           
static int makePublicNonFinal(int access)
          Modify visibility to be public.
static int promoteDefaultOrPrivateOrProtectedToPublic(int access)
           
static int promoteDefaultOrProtectedToPublic(int access)
          If the flags indicate it is not public, private or protected, then it is default and make it public.
static int promoteDefaultOrProtectedToPublic(int access, boolean isEnum)
           
static int sizeOf(java.lang.String typeDescriptor)
          Return the size of a type.
static java.lang.Class<?>[] slashedNamesToClasses(java.lang.String[] slashedNames, java.lang.ClassLoader classLoader)
           
static java.lang.Class<?> slashedNameToClass(java.lang.String slashedName, java.lang.ClassLoader classLoader)
           
static java.lang.String stripFirstParameter(java.lang.String descriptor)
          Strip the first parameter out of a method descriptor and return the shortened method descriptor.
static java.lang.Class<?> toClass(ReloadableType rtype)
           
static java.lang.Class<?> toClass(org.objectweb.asm.Type type, java.lang.ClassLoader classLoader)
          Convert an asm Type into a corresponding Class object, requires a reference to a ClassLoader to be able to convert classnames to class objects.
static int toCombined(int typeRegistryId, int classId)
           
static java.lang.String toConstructorDescriptor(java.lang.Class<?>... params)
           
static java.lang.String toMethodDescriptor(java.lang.reflect.Method m)
           
static java.lang.String toMethodDescriptor(java.lang.reflect.Method method, boolean ignoreFirstParameter)
          Construct the method descriptor for a method.
static java.lang.String toOpcodeString(int opcode)
           
static java.lang.String toPaddedNumber(int value, int width)
          Create the string representation of an integer and pad it to a particular width using leading zeroes.
static java.lang.Class<?>[] toParamClasses(java.lang.String methodDescriptor, java.lang.ClassLoader classLoader)
          Given a method descriptor, extract the parameter descriptor and convert into corresponding Class objects.
static java.lang.String toParamDescriptor(java.lang.Class<?>... params)
          Create a descriptor for some set of parameter types.
static java.lang.Object toResultCheckIfNull(java.lang.Object value, java.lang.String desc)
          Convert a value to the requested descriptor.
static java.lang.String toSuperAccessor(java.lang.String typename, java.lang.String name)
           
static void write(java.io.File file, byte[] data)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_STRINGS

public static final java.lang.String[] NO_STRINGS
Constructor Detail

Utils

public Utils()
Method Detail

encode

public static java.lang.String encode(long number)
Convert a number (base10) to base62 encoded string

Parameters:
number - the number to convert
Returns:
the base 62 encoded string

decode

public static long decode(java.lang.String s)
Decode a base62 encoded string into a number (base10). (More expensive than encoding)

Parameters:
the - string to decode
Returns:
the number

addCorrectReturnInstruction

public static void addCorrectReturnInstruction(org.objectweb.asm.MethodVisitor mv,
                                               Utils.ReturnType returnType,
                                               boolean createCast)
Depending on the signature of the return type, add the appropriate instructions to the method visitor.

Parameters:
mv - where to visit to append the instructions
returnType - return type descriptor

getParameterCount

public static int getParameterCount(java.lang.String methodDescriptor)
Return the number of parameters in the descriptor. Copes with primitives and arrays and reference types.

Parameters:
methodDescriptor - a method descriptor of the form (Ljava/lang/String;I[[Z)I
Returns:
number of parameters in the descriptor

createLoadsBasedOnDescriptor

public static void createLoadsBasedOnDescriptor(org.objectweb.asm.MethodVisitor mv,
                                                java.lang.String descriptor,
                                                int startindex)
Create the set of LOAD instructions to load the method parameters. Take into account the size and type.

Parameters:
mv - the method visitor to recieve the load instructions
descriptor - the complete method descriptor (eg. "(ILjava/lang/String;)V") - params and return type are skipped
startindex - the initial index in which to assume the first parameter is stored

insertUnboxInsnsIfNecessary

public static void insertUnboxInsnsIfNecessary(org.objectweb.asm.MethodVisitor mv,
                                               java.lang.String type,
                                               boolean isObject)

insertUnboxInsns

public static void insertUnboxInsns(org.objectweb.asm.MethodVisitor mv,
                                    char ch,
                                    boolean isObject)

getParamSequence

public static java.lang.String getParamSequence(java.lang.String descriptor)
Return a simple sequence for the descriptor where type references are collapsed to 'O', so (IILjava/lang/String;Z) will return IIOZ.

Parameters:
descriptor - method descriptor, for example (IILjava/lang/String;Z)V
Returns:
sequence where all parameters are represented by a single character - or null if no parameters

insertBoxInsns

public static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv,
                                  java.lang.String type)

insertBoxInsns

public static void insertBoxInsns(org.objectweb.asm.MethodVisitor mv,
                                  char ch)

getInterfaceName

public static java.lang.String getInterfaceName(java.lang.String owner)

assertSlashed

public static void assertSlashed(java.lang.String name)

assertDotted

public static void assertDotted(java.lang.String name)

toOpcodeString

public static java.lang.String toOpcodeString(int opcode)

toParamDescriptor

public static java.lang.String toParamDescriptor(java.lang.Class<?>... params)
Create a descriptor for some set of parameter types. The descriptor will be of the form "([Ljava/lang/String;)"

Parameters:
params - the (possibly null) list of parameters for which to create the descriptor
Returns:
a descriptor or "()" for no parameters

toParamClasses

public static java.lang.Class<?>[] toParamClasses(java.lang.String methodDescriptor,
                                                  java.lang.ClassLoader classLoader)
                                           throws java.lang.ClassNotFoundException
Given a method descriptor, extract the parameter descriptor and convert into corresponding Class objects. This requires a reference to a class loader to convert type names into Class objects.

Throws:
java.lang.ClassNotFoundException

toClass

public static java.lang.Class<?> toClass(org.objectweb.asm.Type type,
                                         java.lang.ClassLoader classLoader)
                                  throws java.lang.ClassNotFoundException
Convert an asm Type into a corresponding Class object, requires a reference to a ClassLoader to be able to convert classnames to class objects.

Throws:
java.lang.ClassNotFoundException

toMethodDescriptor

public static java.lang.String toMethodDescriptor(java.lang.reflect.Method method,
                                                  boolean ignoreFirstParameter)
Construct the method descriptor for a method. For example 'String bar(int)' would return '(I)Ljava/lang/String;'. If the first parameter is skipped, the leading '(' is also skipped (the caller is expect to build the right prefix).

Parameters:
method - method for which the descriptor should be created
ignoreFirstParameter - whether to include the first parameter in the output descriptor
Returns:
a method descriptor

appendDescriptor

public static void appendDescriptor(java.lang.Class<?> p,
                                    java.lang.StringBuilder s)

toPaddedNumber

public static java.lang.String toPaddedNumber(int value,
                                              int width)
Create the string representation of an integer and pad it to a particular width using leading zeroes.

Parameters:
value - the value to convert to a string
width - the width (in chars) that the resultant string should be
Returns:
the padded string

toMethodDescriptor

public static java.lang.String toMethodDescriptor(java.lang.reflect.Method m)

loadDottedClassAsBytes

public static byte[] loadDottedClassAsBytes(java.lang.ClassLoader loader,
                                            java.lang.String dottedclassname)
Access the specified class as a resource accessible through the specified loader and return the bytes. The classname should be 'dot' separated (eg. com.foo.Bar) and not suffixed .class

Parameters:
loader - the classloader against which getResourceAsStream() will be invoked
dottedclassname - the dot separated classname without .class suffix
Returns:
the byte data defining that class

loadSlashedClassAsBytes

public static byte[] loadSlashedClassAsBytes(java.lang.ClassLoader loader,
                                             java.lang.String slashedclassname)
Access the specified class as a resource accessible through the specified loader and return the bytes. The classname should be 'dot' separated (eg. com.foo.Bar) and not suffixed .class

Parameters:
loader - the classloader against which getResourceAsStream() will be invoked
slashedclassname - the dot separated classname without .class suffix
Returns:
the byte data defining that class

load

public static byte[] load(java.io.File file)

write

public static void write(java.io.File file,
                         byte[] data)

loadBytesFromStream

public static byte[] loadBytesFromStream(java.io.InputStream stream)
Load all the byte data from an input stream.

Parameters:
stream - thr input stream from which to read
Returns:
a byte array containing all the data from the stream

assertTrue

public static void assertTrue(boolean condition,
                              java.lang.String detail)

getDispatcherName

public static java.lang.String getDispatcherName(java.lang.String name,
                                                 java.lang.String versionstamp)

getExecutorName

public static java.lang.String getExecutorName(java.lang.String name,
                                               java.lang.String versionstamp)
Generate the name for the executor class. Must use '$' so that it is considered by some code (eclipse debugger for example) to be an inner type of the original class (thus able to consider itself as being from the same source file).


stripFirstParameter

public static java.lang.String stripFirstParameter(java.lang.String descriptor)
Strip the first parameter out of a method descriptor and return the shortened method descriptor. Since primitive types cannot be reloadable, there is no need to handle that case - it should always be true that the first parameter will exist and will end with a semi-colon. For example: (Ljava/lang/String;II)V becomes (IIV)

Parameters:
descriptor - method descriptor to be shortened
Returns:
new version of input descriptor with first parameter taken out

getReturnTypeDescriptor

public static Utils.ReturnType getReturnTypeDescriptor(java.lang.String methodDescriptor)
Discover the descriptor for the return type. It may be a primitive (so one char) or a reference type (so a/b/c, with no 'L' or ';') or it may be an array descriptor ([Ljava/lang/String;).

Parameters:
methodDescriptor - method descriptor
Returns:
return type descriptor (with any 'L' or ';' trimmed off)

insertExtraParameter

public static java.lang.String insertExtraParameter(java.lang.String classname,
                                                    java.lang.String descriptor)

generateInstructionsToUnpackArrayAccordingToDescriptor

public static void generateInstructionsToUnpackArrayAccordingToDescriptor(org.objectweb.asm.MethodVisitor mv,
                                                                          java.lang.String toCallDescriptor,
                                                                          int arrayVariableIndex)
Generate the instructions in the specified method visitor to unpack an assumed array (on top of the stack) according to the specified descriptor. For example, if the descriptor is (I)V then the array contains a single Integer that must be unloaded from the array then unboxed to an int.

Parameters:
mv - the method visitor to receive the unpack instructions
toCallDescriptor - the descriptor for the method whose parameters describe the array contents

isInitializer

public static boolean isInitializer(java.lang.String membername)

toCombined

public static int toCombined(int typeRegistryId,
                             int classId)

logAndThrow

public static void logAndThrow(java.util.logging.Logger log,
                               java.lang.String message)

dump

public static java.lang.String dump(java.lang.String slashname,
                                    byte[] bytesLoaded)
Dump the specified bytes under the specified name in the filesystem. If the location hasn't been configured then File.createTempFile() is used to determine where the file will be put.

Parameters:
slashname -
bytesLoaded -
Returns:
the path to the file

sizeOf

public static int sizeOf(java.lang.String typeDescriptor)
Return the size of a type. The size is usually 1 except for double and long which are of size 2. The descriptor passed in is the full descriptor, including any leading 'L' and trailing ';'.

Parameters:
typeDescriptor - the descriptor for a single type, may be primitive. For example: I, J, Z, Ljava/lang/String;
Returns:
the size of the descriptor (number of slots it will consume), either 1 or 2

dumpClass

public static void dumpClass(java.lang.String file,
                             byte[] bytes)
Dump some bytes into the specified file.

Parameters:
file - full filename for where to dump the stuff (e.g. c:/temp/Foo.class)
bytes - the bytes to write to the file

toSuperAccessor

public static java.lang.String toSuperAccessor(java.lang.String typename,
                                               java.lang.String name)

getSize

public static int getSize(java.lang.String descriptor)
Compute the size required for a specific method descriptor.

Parameters:
descriptor - a method descriptor, for example (Ljava/lang/String;ZZ)V
Returns:
number of stack/var entries necessary for that descriptor

slashedNamesToClasses

public static java.lang.Class<?>[] slashedNamesToClasses(java.lang.String[] slashedNames,
                                                         java.lang.ClassLoader classLoader)
                                                  throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

slashedNameToClass

public static java.lang.Class<?> slashedNameToClass(java.lang.String slashedName,
                                                    java.lang.ClassLoader classLoader)
                                             throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

fieldNodeFormat

public static java.lang.String fieldNodeFormat(org.objectweb.asm.tree.FieldNode fieldNode)

annotationNodeFormat

public static java.lang.String annotationNodeFormat(org.objectweb.asm.tree.AnnotationNode o)

formatAnnotationNodeNameValuePairValue

public static void formatAnnotationNodeNameValuePairValue(java.lang.Object value,
                                                          java.lang.StringBuilder s)

fieldNodeFormat

public static java.lang.String fieldNodeFormat(java.util.Collection<org.objectweb.asm.tree.FieldNode> fieldNodes)

loadFromStream

public static byte[] loadFromStream(java.io.InputStream stream)
Load the contents of an input stream.


promoteDefaultOrProtectedToPublic

public static int promoteDefaultOrProtectedToPublic(int access)
If the flags indicate it is not public, private or protected, then it is default and make it public. Default visibility needs promoting because package visibility is determined by classloader+package, not just package.


promoteDefaultOrProtectedToPublic

public static int promoteDefaultOrProtectedToPublic(int access,
                                                    boolean isEnum)

promoteDefaultOrPrivateOrProtectedToPublic

public static int promoteDefaultOrPrivateOrProtectedToPublic(int access)

arrayCopyOf

public static <T> T[] arrayCopyOf(T[] array,
                                  int newSize)
Utility method similar to Java 1.6 Arrays.copyOf, used instead of that method to stick to Java 1.5 only API.


makePublicNonFinal

public static int makePublicNonFinal(int access)
Modify visibility to be public.


toClass

public static java.lang.Class<?> toClass(ReloadableType rtype)

isObjectIsUnboxableTo

public static boolean isObjectIsUnboxableTo(java.lang.Class<?> possiblyBoxedType,
                                            char primitive)
Returns:
true if the possiblyBoxedType is the boxed form of the primitive

toResultCheckIfNull

public static java.lang.Object toResultCheckIfNull(java.lang.Object value,
                                                   java.lang.String desc)
Convert a value to the requested descriptor. For null values where the caller needs a primitive, this returns the appropriate (boxed) default. This method will not attempt conversion, it is basically checking what to do if the result is null - and ensuring the caller gets back what they expect (the appropriate primitive default).

Parameters:
value - the value
desc - the type the caller would like it to be

checkCompatibility

public static java.lang.Object checkCompatibility(TypeRegistry registry,
                                                  java.lang.Object result,
                                                  java.lang.String expectedTypeDescriptor)
Check that the value we have discovered is of the right type. It may not be if the field has changed type during a reload. When this happens we will default the value for the new field and forget the one we were holding onto. note: array forms are not compatible (e.g. int[] and Integer[])

Parameters:
result - the result we have discovered and are about to return - this is never null
expectedTypeDescriptor - the type we are looking for (will be primitive or Ljava/lang/String style)
Returns:
the result we can return, or null if it is not compatible

isAssignableFrom

public static boolean isAssignableFrom(TypeRegistry reg,
                                       java.lang.Class<?> clazz,
                                       java.lang.String lookingFor)

isAssignableFrom

public static boolean isAssignableFrom(java.lang.String lookingFor,
                                       TypeDescriptor candidate)
Determine if the type specified in lookingFor is a supertype (class/interface) of the specified typedescriptor, i.e. can an object of type 'candidate' be assigned to a variable of typ 'lookingFor'.

Returns:
true if it is a supertype

collapseStackToArray

public static int collapseStackToArray(org.objectweb.asm.MethodVisitor mv,
                                       java.lang.String desc)
Produce the bytecode that will collapse the stack entries into an array - the descriptor describes what is being packed.

Parameters:
mv - the method visitor to receive the instructions to package the data
desc - the descriptor for the method that shows (through its parameters) the contents of the stack

insertPopsForAllParameters

public static int insertPopsForAllParameters(org.objectweb.asm.MethodVisitor mv,
                                             java.lang.String desc)
Looks at the supplied descriptor and inserts enough pops to remove all parameters. Should be used when about to avoid a method call.


toConstructorDescriptor

public static java.lang.String toConstructorDescriptor(java.lang.Class<?>... params)

isConvertableFrom

public static boolean isConvertableFrom(java.lang.Class<?> targetType,
                                        java.lang.Class<?> sourceType)

discoverInterfaces

public static java.lang.String[] discoverInterfaces(byte[] classbytes)
Determine the interfaces implemented by a given class (supplied as bytes)

Parameters:
classbytes - the classfile bytes
Returns:
array of interface names (slashed descriptors)

getProtectedFieldGetterName

public static java.lang.String getProtectedFieldGetterName(java.lang.String fieldname)

getProtectedFieldSetterName

public static java.lang.String getProtectedFieldSetterName(java.lang.String fieldname)