utilMDE
Class BCELUtil

Object
  extended by BCELUtil

public class BCELUtil
extends Object

Static utility methods for working with BCEL.


Field Summary
static boolean skip_checks
          Controls whether the checks in checkMgen are actually performed *
 
Constructor Summary
BCELUtil()
           
 
Method Summary
static void add_line_numbers(MethodGen mg, InstructionList il)
          Builds an array of line numbers for the specified instruction list.
static void add_to_start(MethodGen mg, InstructionList nl)
          Adds code in nl to start of method mg *
static Type[] add_type(Type[] types, Type new_type)
          Returns a type array with new_type added to the end of types
static void checkMgen(MethodGen mgen)
          Checks the specific method for consistency.
static void checkMgens(ClassGen gen)
          Checks all of the methods in gen for consistency.
static Type classname_to_type(String classname)
           
static void dump(JavaClass jc, File dump_dir)
          Dumps the contents of the specified class to the specified directory.
static void dump(JavaClass jc, String dump_dir)
           
static void empty_method(MethodGen mg)
          Empties the method of all code (except for a return).
static String get_attribute_name(Attribute a)
          Returns the attribute name for the specified attribute.
static String get_attribute_name(Attribute a, ConstantPoolGen pool)
          Returns the attribute name for the specified attribute.
static String get_constant_str(ConstantPool pool, int index)
          Returns the constant string at the specified offset
static String get_method_declaration(Method m)
          Returns a string describing a method declaration.
static boolean in_jdk(ClassGen gen)
          returns whether or not the class is part of the JDK (rt.jar) *
static boolean in_jdk(String classname)
          returns whether or not the classname is part of the JDK (rt.jar) *
static Type[] insert_type(Type new_type, Type[] types)
          Returns a type array with new_type inserted at the beginning
static String instruction_descr(InstructionList il, ConstantPoolGen pool)
           
static boolean is_clinit(Method m)
          returns whether or not the specified method is a class initializer
static boolean is_clinit(MethodGen mg)
          returns whether or not the specified method is a class initializer
static boolean is_constructor(Method m)
          returns whether or not the specified method is a constructor *
static boolean is_constructor(MethodGen mg)
          returns whether or not the specified method is a constructor *
static boolean is_local_variable_type_table(Attribute a, ConstantPoolGen pool)
          Returns whether or not the specified attribute is a local variable type table.
static boolean is_main(MethodGen mg)
          Returns whether or not this is a standard main method (static, name is 'main', and one argument of string array.
static String local_var_descr(MethodGen mg)
          Return a description of the local variables (one per line).
static void remove_local_variable_type_tables(MethodGen mg)
          Remove the local variable type table attribute (LVTT) from mg.
static void setup_init_locals(MethodGen mg)
          Sets the locals to 'this' and each of the arguments.
static Class type_to_class(Type type)
          Returns the class that corresponds to type
static String type_to_classname(Type type)
          Returns the java classname that corresponds to type
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

skip_checks

public static boolean skip_checks
Controls whether the checks in checkMgen are actually performed *

Constructor Detail

BCELUtil

public BCELUtil()
Method Detail

get_method_declaration

public static String get_method_declaration(Method m)
Returns a string describing a method declaration. It contains the access flags (public, private, static, etc), the return type, the method name, and the types of each of its arguments.


get_attribute_name

public static String get_attribute_name(Attribute a)
Returns the attribute name for the specified attribute.


get_constant_str

public static String get_constant_str(ConstantPool pool,
                                      int index)
Returns the constant string at the specified offset


is_constructor

public static boolean is_constructor(MethodGen mg)
returns whether or not the specified method is a constructor *


is_constructor

public static boolean is_constructor(Method m)
returns whether or not the specified method is a constructor *


is_clinit

public static boolean is_clinit(MethodGen mg)
returns whether or not the specified method is a class initializer


is_clinit

public static boolean is_clinit(Method m)
returns whether or not the specified method is a class initializer


in_jdk

public static boolean in_jdk(ClassGen gen)
returns whether or not the class is part of the JDK (rt.jar) *


in_jdk

public static boolean in_jdk(String classname)
returns whether or not the classname is part of the JDK (rt.jar) *


checkMgen

public static void checkMgen(MethodGen mgen)
Checks the specific method for consistency.


checkMgens

public static void checkMgens(ClassGen gen)
Checks all of the methods in gen for consistency.


add_to_start

public static void add_to_start(MethodGen mg,
                                InstructionList nl)
Adds code in nl to start of method mg *


dump

public static void dump(JavaClass jc,
                        String dump_dir)
See Also:
dump(JavaClass, File)

dump

public static void dump(JavaClass jc,
                        File dump_dir)
Dumps the contents of the specified class to the specified directory. The file is named dump_dir/[class].bcel. It contains a synopsis of the fields and methods followed by the jvm code for each method.

Parameters:
jc - javaclass to dump
dump_dir - directory in which to write the file

instruction_descr

public static String instruction_descr(InstructionList il,
                                       ConstantPoolGen pool)

local_var_descr

public static String local_var_descr(MethodGen mg)
Return a description of the local variables (one per line).


add_line_numbers

public static void add_line_numbers(MethodGen mg,
                                    InstructionList il)
Builds an array of line numbers for the specified instruction list. Each opcode is assigned the next source line number starting at 1000.


setup_init_locals

public static void setup_init_locals(MethodGen mg)
Sets the locals to 'this' and each of the arguments. Any other locals are removed. An instruction list with at least one instruction must exist.


empty_method

public static void empty_method(MethodGen mg)
Empties the method of all code (except for a return). This includes line numbers, exceptions, local variables, etc.


remove_local_variable_type_tables

public static void remove_local_variable_type_tables(MethodGen mg)
Remove the local variable type table attribute (LVTT) from mg. Evidently some changes require this to be updated, but without BCEL support that would be hard to do. It should be safe to just delete it since it is optional and really only of use to a debugger.


is_local_variable_type_table

public static boolean is_local_variable_type_table(Attribute a,
                                                   ConstantPoolGen pool)
Returns whether or not the specified attribute is a local variable type table.


get_attribute_name

public static String get_attribute_name(Attribute a,
                                        ConstantPoolGen pool)
Returns the attribute name for the specified attribute.


is_main

public static boolean is_main(MethodGen mg)
Returns whether or not this is a standard main method (static, name is 'main', and one argument of string array.


type_to_classname

public static String type_to_classname(Type type)
Returns the java classname that corresponds to type


type_to_class

public static Class type_to_class(Type type)
Returns the class that corresponds to type


add_type

public static Type[] add_type(Type[] types,
                              Type new_type)
Returns a type array with new_type added to the end of types


insert_type

public static Type[] insert_type(Type new_type,
                                 Type[] types)
Returns a type array with new_type inserted at the beginning


classname_to_type

public static Type classname_to_type(String classname)