public final class BcelUtil
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static boolean |
skipChecks
Controls whether the checks in checkMgen are actually performed.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
addLineNumbers(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList il)
Builds an array of line numbers for the specified instruction list.
|
static void |
addToStart(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList nl)
Adds code in nl to start of method mg.
|
static org.apache.bcel.generic.Type[] |
addType(org.apache.bcel.generic.Type[] types,
org.apache.bcel.generic.Type newType)
|
static void |
checkMgen(org.apache.bcel.generic.MethodGen mgen)
Checks the specific method for consistency.
|
static void |
checkMgens(org.apache.bcel.generic.ClassGen gen)
Checks all of the methods in gen for consistency.
|
static java.lang.Class<?> |
classForName(java.lang.String className)
Like
Class.forName(String), but also works when the string represents a primitive type
or a fully-qualified name (as opposed to a binary name). |
static org.apache.bcel.generic.Type |
classnameToType(java.lang.String classname)
Return the type corresponding to a given class name.
|
static void |
dump(org.apache.bcel.classfile.JavaClass jc,
java.io.File dumpDir)
Dumps the contents of the specified class to the specified directory.
|
static void |
dump(org.apache.bcel.classfile.JavaClass jc,
java.lang.String dumpDir)
Dumps the contents of the specified class to the specified directory.
|
static void |
emptyMethod(org.apache.bcel.generic.MethodGen mg)
Empties the method of all code (except for a return).
|
static java.lang.String |
getAttributeName(org.apache.bcel.classfile.Attribute a)
Return the attribute name for the specified attribute.
|
static java.lang.String |
getAttributeName(org.apache.bcel.classfile.Attribute a,
org.apache.bcel.generic.ConstantPoolGen pool)
Return the attribute name for the specified attribute.
|
static java.lang.String |
getConstantStr(org.apache.bcel.classfile.ConstantPool pool,
int index)
Returns the constant string at the specified offset.
|
static java.lang.String |
getMethodDeclaration(org.apache.bcel.classfile.Method m)
Returns a string describing a method declaration.
|
static boolean |
inJdk(org.apache.bcel.generic.ClassGen gen)
Returns whether or not the class is part of the JDK (rt.jar).
|
static boolean |
inJdk(java.lang.String classname)
Returns whether or not the class is part of the JDK (rt.jar).
|
static boolean |
inJdkInternalform(java.lang.String classname)
Returns whether or not the class is part of the JDK (rt.jar).
|
static org.apache.bcel.generic.Type[] |
insertType(org.apache.bcel.generic.Type newType,
org.apache.bcel.generic.Type[] types)
|
static java.lang.String |
instructionDescr(org.apache.bcel.generic.InstructionList il,
org.apache.bcel.generic.ConstantPoolGen pool) |
static boolean |
isClinit(org.apache.bcel.classfile.Method m)
Returns whether or not the method is a class initializer.
|
static boolean |
isClinit(org.apache.bcel.generic.MethodGen mg)
Returns whether or not the method is a class initializer.
|
static boolean |
isConstructor(org.apache.bcel.classfile.Method m)
Returns whether or not the method is a constructor.
|
static boolean |
isConstructor(org.apache.bcel.generic.MethodGen mg)
Returns whether or not the method is a constructor.
|
static boolean |
isLocalVariableTypeTable(org.apache.bcel.classfile.Attribute a,
org.apache.bcel.generic.ConstantPoolGen pool)
Returns whether or not the specified attribute is a local variable type table.
|
static boolean |
isMain(org.apache.bcel.generic.MethodGen mg)
Returns whether or not this is a standard main method (static, name is 'main', and one argument
of string array).
|
static java.lang.String |
localVarDescr(org.apache.bcel.generic.MethodGen mg)
Return a description of the local variables (one per line).
|
static org.apache.bcel.generic.Type[] |
postpendToArray(org.apache.bcel.generic.Type[] types,
org.apache.bcel.generic.Type newType)
Returns a copy of the given type array, with newType added to the end.
|
static org.apache.bcel.generic.Type[] |
prependToArray(org.apache.bcel.generic.Type newType,
org.apache.bcel.generic.Type[] types)
Returns a copy of the given type array, with newType inserted at the beginning.
|
static void |
removeLocalVariableTypeTables(org.apache.bcel.generic.MethodGen mg)
Remove the local variable type table attribute (LVTT) from mg.
|
static void |
setupInitLocals(org.apache.bcel.generic.MethodGen mg)
Sets the locals to 'this' and each of the arguments.
|
static java.lang.Class<?> |
typeToClass(org.apache.bcel.generic.Type type)
Returns the class that corresponds to type.
|
static java.lang.String |
typeToClassgetname(org.apache.bcel.generic.Type type)
Returns the Java class name, in the format of
Class.getName(), that corresponds to
type. |
public static boolean skipChecks
public static java.lang.String getMethodDeclaration(org.apache.bcel.classfile.Method m)
m - the methodpublic static java.lang.String getAttributeName(org.apache.bcel.classfile.Attribute a)
a - the attributepublic static java.lang.String getConstantStr(org.apache.bcel.classfile.ConstantPool pool,
int index)
pool - the constant poolindex - the index in the constant poolpublic static boolean isConstructor(org.apache.bcel.generic.MethodGen mg)
mg - the method to testpublic static boolean isConstructor(org.apache.bcel.classfile.Method m)
m - the method to testpublic static boolean isClinit(org.apache.bcel.generic.MethodGen mg)
mg - the method to testpublic static boolean isClinit(org.apache.bcel.classfile.Method m)
m - the method to testpublic static boolean inJdk(org.apache.bcel.generic.ClassGen gen)
gen - the class to testpublic static boolean inJdk(java.lang.String classname)
classname - the class to test, in the format of Class.getName(); the class should not be
an arraypublic static boolean inJdkInternalform(java.lang.String classname)
classname - the class to test, in internal formpublic static void checkMgen(org.apache.bcel.generic.MethodGen mgen)
mgen - the class to checkpublic static void checkMgens(org.apache.bcel.generic.ClassGen gen)
gen - the class to checkpublic static void addToStart(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList nl)
mg - method to be augmentednl - instructions to prepend to the methodpublic static void dump(org.apache.bcel.classfile.JavaClass jc,
java.lang.String dumpDir)
jc - javaclass to dumpdumpDir - directory in which to write the filedump(JavaClass, File)public static void dump(org.apache.bcel.classfile.JavaClass jc,
java.io.File dumpDir)
jc - javaclass to dumpdumpDir - directory in which to write the filepublic static java.lang.String instructionDescr(org.apache.bcel.generic.InstructionList il,
org.apache.bcel.generic.ConstantPoolGen pool)
public static java.lang.String localVarDescr(org.apache.bcel.generic.MethodGen mg)
mg - the method whose local variables to describepublic static void addLineNumbers(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList il)
mg - the method whose line numbers to extractil - the instruction list to augment with line numberspublic static void setupInitLocals(org.apache.bcel.generic.MethodGen mg)
mg - the method whose locals to setpublic static void emptyMethod(org.apache.bcel.generic.MethodGen mg)
mg - the method to clear outpublic static void removeLocalVariableTypeTables(org.apache.bcel.generic.MethodGen mg)
mg - the method to clear outpublic static boolean isLocalVariableTypeTable(org.apache.bcel.classfile.Attribute a,
org.apache.bcel.generic.ConstantPoolGen pool)
a - the attributepool - the constant poolpublic static java.lang.String getAttributeName(org.apache.bcel.classfile.Attribute a,
org.apache.bcel.generic.ConstantPoolGen pool)
a - the attributepool - the constant poolpublic static boolean isMain(org.apache.bcel.generic.MethodGen mg)
mg - the method to checkpublic static java.lang.String typeToClassgetname(org.apache.bcel.generic.Type type)
Class.getName(), that corresponds to
type.type - the typepublic static java.lang.Class<?> typeToClass(org.apache.bcel.generic.Type type)
type - the typepublic static org.apache.bcel.generic.Type[] postpendToArray(org.apache.bcel.generic.Type[] types,
org.apache.bcel.generic.Type newType)
types - the array to extendnewType - the element to add to the end of the array@Deprecated
public static org.apache.bcel.generic.Type[] addType(org.apache.bcel.generic.Type[] types,
org.apache.bcel.generic.Type newType)
types - the array to extendnewType - the element to add to the end of the arraypublic static org.apache.bcel.generic.Type[] prependToArray(org.apache.bcel.generic.Type newType,
org.apache.bcel.generic.Type[] types)
types - the array to extendnewType - the element to add to the beginning of the array@Deprecated
public static org.apache.bcel.generic.Type[] insertType(org.apache.bcel.generic.Type newType,
org.apache.bcel.generic.Type[] types)
types - the array to extendnewType - the element to add to the beginning of the arraypublic static org.apache.bcel.generic.Type classnameToType(java.lang.String classname)
classname - the binary name of a class (= fully-qualified name, except for inner classes)public static java.lang.Class<?> classForName(java.lang.String className)
throws java.lang.ClassNotFoundException
Class.forName(String), but also works when the string represents a primitive type
or a fully-qualified name (as opposed to a binary name).
If the given name can't be found, this method changes the last '.' to a dollar sign ($) and tries again. This accounts for inner classes that are incorrectly passed in in fully-qualified format instead of binary format. (It should try multiple dollar signs, not just at the last position.)
Recall the rather odd specification for Class.forName(String): the argument is a
binary name for non-arrays, but a field descriptor for arrays. This method uses the same rules,
but additionally handles primitive types and, for non-arrays, fully-qualified names.
className - name of the classjava.lang.ClassNotFoundException - if the class is not found