public final class BcelUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static int |
javaVersion
The major version number of the Java runtime.
|
static boolean |
skipChecks
Controls whether the checks in
checkMgen(org.apache.bcel.generic.MethodGen) are performed. |
private static org.apache.bcel.generic.Type |
stringArray
The type that represents String[].
|
| Modifier | Constructor and Description |
|---|---|
private |
BcelUtil()
This class is a collection of methods; it does not represent anything.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) static String |
accessFlagsToString(org.apache.bcel.classfile.Method m)
Return a string representation of the access flags of method m.
|
static void |
addToStart(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList newList)
Adds instructions to the start of a method.
|
static String |
attributeNameToString(org.apache.bcel.classfile.Attribute a)
Return the attribute name for the specified attribute, looked up in the original class file
ConstantPool.
|
static String |
attributeNameToString(org.apache.bcel.classfile.Attribute a,
org.apache.bcel.generic.ConstantPoolGen pool)
Return the attribute name for the specified attribute, looked up in the given ConstantPoolGen.
|
static org.apache.bcel.generic.Type |
binaryNameToType(@BinaryNameOrPrimitiveType String classname)
Return the type corresponding to a given binary name or primitive type name.
|
static void |
checkMgen(org.apache.bcel.generic.MethodGen mgen)
Checks the specified method for consistency.
|
static void |
checkMgens(org.apache.bcel.generic.ClassGen gen)
Checks all of the methods in gen for consistency.
|
static org.apache.bcel.generic.Type |
classnameToType(@BinaryNameOrPrimitiveType String classname)
Deprecated.
|
static void |
dump(org.apache.bcel.classfile.JavaClass jc,
File dumpDir)
Dumps the contents of the specified class to the specified directory.
|
static void |
dump(org.apache.bcel.classfile.JavaClass jc,
String dumpDir)
Dumps the contents of the specified class to the specified directory.
|
(package private) static void |
dumpMethods(org.apache.bcel.generic.ClassGen gen)
Print the methods in the class, to standard output.
|
static void |
dumpStackTrace()
Print the current java call stack.
|
static org.apache.bcel.generic.Type |
fqBinaryNameToType(@FqBinaryName String classname)
Return the type corresponding to a given fully-qualified binary name.
|
static String |
getConstantString(org.apache.bcel.classfile.ConstantPool pool,
int index)
Returns the constant string at the specified offset.
|
private static int |
getJavaVersion()
Extract the major version number from the "java.version" system property.
|
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(@ClassGetName String classname)
Returns whether or not the class is part of the JDK (rt.jar).
|
static boolean |
inJdkInternalform(@InternalForm String classname)
Returns whether or not the class is part of the JDK (rt.jar).
|
static String |
instructionListToString(org.apache.bcel.generic.InstructionList il,
org.apache.bcel.generic.ConstantPoolGen pool)
Return a printed description of the given instructions.
|
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, void, name is 'main', and one
formal parameter: a string array).
|
static String |
localVariablesToString(org.apache.bcel.generic.MethodGen mg)
Return a description of the local variables (one per line).
|
static void |
makeMethodBodyEmpty(org.apache.bcel.generic.MethodGen mg)
Empties the method of all code (except for a return).
|
static String |
methodDeclarationToString(org.apache.bcel.classfile.Method m)
Returns a string describing a method declaration.
|
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 |
resetLocalsToFormals(org.apache.bcel.generic.MethodGen mg)
Sets the locals to be the formal parameters.
|
static Class<?> |
typeToClass(org.apache.bcel.generic.Type type)
Returns the class that corresponds to type.
|
static @ClassGetName 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
checkMgen(org.apache.bcel.generic.MethodGen) are performed.private static final org.apache.bcel.generic.Type stringArray
public static final int javaVersion
private BcelUtil()
private static int getJavaVersion()
public static String methodDeclarationToString(org.apache.bcel.classfile.Method m)
For example, if the orignal Java source declarationwas: private final String constantToString (int index) Then the output of methodDeclarationToString would be: private final java.lang.String constantToString (int)
m - the methodstatic String accessFlagsToString(org.apache.bcel.classfile.Method m)
m - the method whose access flags to retrievepublic static String instructionListToString(org.apache.bcel.generic.InstructionList il, org.apache.bcel.generic.ConstantPoolGen pool)
il - the instructions to describepool - the constant pool the instructions refer toilpublic static String localVariablesToString(org.apache.bcel.generic.MethodGen mg)
mg - the method whose local variables to describepublic static String attributeNameToString(org.apache.bcel.classfile.Attribute a)
a - the attributepublic static String attributeNameToString(org.apache.bcel.classfile.Attribute a, org.apache.bcel.generic.ConstantPoolGen pool)
a - the attributepool - the constant poolpublic static boolean isConstructor(org.apache.bcel.generic.MethodGen mg)
mg - the MethodGen 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(@ClassGetName String classname)
classname - the class to test, in the format of Class.getName(); the class should not be
an arraypublic static boolean inJdkInternalform(@InternalForm String classname)
classname - the class to test, in internal formpublic static boolean isLocalVariableTypeTable(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 void checkMgen(org.apache.bcel.generic.MethodGen mgen)
Does nothing if skipChecks is false.
mgen - the class to checkpublic static void checkMgens(org.apache.bcel.generic.ClassGen gen)
gen - the class to checkpublic static void dumpStackTrace()
static void dumpMethods(org.apache.bcel.generic.ClassGen gen)
gen - the class whose methods to printpublic static void dump(org.apache.bcel.classfile.JavaClass jc,
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,
File dumpDir)
jc - JavaClass to dumpdumpDir - directory in which to write the filepublic static void addToStart(org.apache.bcel.generic.MethodGen mg,
org.apache.bcel.generic.InstructionList newList)
mg - method to be augmentednewList - instructions to prepend to the methodpublic static String getConstantString(org.apache.bcel.classfile.ConstantPool pool, int index)
pool - the constant poolindex - the index in the constant poolpublic static void resetLocalsToFormals(org.apache.bcel.generic.MethodGen mg)
mg - the method whose locals to setpublic static void makeMethodBodyEmpty(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 @ClassGetName String typeToClassgetname(org.apache.bcel.generic.Type type)
Class.getName(), that corresponds to
type.type - the typepublic static 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 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 classnameToType(@BinaryNameOrPrimitiveType String classname)
binaryNameToType(java.lang.String)classname - the binary name of a class (= fully-qualified name, except for inner classes),
or a primitive type name, but not an arrayfqBinaryNameToType(java.lang.String)public static org.apache.bcel.generic.Type binaryNameToType(@BinaryNameOrPrimitiveType String classname)
classname - the binary name of a class (= fully-qualified name, except for inner classes),
or a primitive type name, but not an arrayfqBinaryNameToType(java.lang.String)public static org.apache.bcel.generic.Type fqBinaryNameToType(@FqBinaryName String classname)
classname - the fully-qualified binary name of a type, which uses "$" rather than "." for
nested classes