Template class for building up a java class. May be initialized with an
existing java class (file).
attribute_vec
private List attribute_vec
class_name
private String class_name
class_name_index
private int class_name_index
field_vec
private List field_vec
file_name
private String file_name
interface_vec
private List interface_vec
method_vec
private List method_vec
observers
private ArrayList observers
super_class_name
private String super_class_name
superclass_name_index
private int superclass_name_index
ClassGen
public ClassGen(String class_name,
String super_class_name,
String file_name,
int access_flags,
String[] interfaces)
Convenience constructor to set up some important values initially.
class_name
- fully qualified class namesuper_class_name
- fully qualified superclass namefile_name
- source file nameaccess_flags
- access qualifiersinterfaces
- implemented interfaces
ClassGen
public ClassGen(String class_name,
String super_class_name,
String file_name,
int access_flags,
String[] interfaces,
ConstantPoolGen cp)
Convenience constructor to set up some important values initially.
class_name
- fully qualified class namesuper_class_name
- fully qualified superclass namefile_name
- source file nameaccess_flags
- access qualifiersinterfaces
- implemented interfacescp
- constant pool to use
ClassGen
public ClassGen(JavaClass clazz)
Initialize with existing class.
clazz
- JavaClass object (e.g. read from file)
addAttribute
public void addAttribute(Attribute a)
Add an attribute to this class.
addEmptyConstructor
public void addEmptyConstructor(int access_flags)
Convenience method.
Add an empty constructor to this class that does nothing but calling super().
access_flags
- rights for constructor
addField
public void addField(Field f)
Add a field to this class.
addInterface
public void addInterface(String name)
Add an interface to this class, i.e., this class has to implement it.
name
- interface to implement (fully qualified class name)
addMethod
public void addMethod(Method m)
Add a method to this class.
addObserver
public void addObserver(ClassObserver o)
Add observer for this object.
clone
public Object clone()
containsField
public Field containsField(String name)
- field object with given name, or null
containsField
public boolean containsField(Field f)
containsMethod
public Method containsMethod(String name,
String signature)
- method object with given name and signature, or null
equals
public boolean equals(Object obj)
Return value as defined by given BCELComparator strategy.
By default two ClassGen objects are said to be equal when
their class names are equal.
java.lang.Object.equals(java.lang.Object)
getAttributes
public Attribute[] getAttributes()
getClassName
public String getClassName()
getClassNameIndex
public int getClassNameIndex()
getComparator
public static BCELComparator getComparator()
- Comparison strategy object
getFields
public Field[] getFields()
getFileName
public String getFileName()
getInterfaceNames
public String[] getInterfaceNames()
getInterfaces
public int[] getInterfaces()
getJavaClass
public JavaClass getJavaClass()
- the (finally) built up Java class object.
getMajor
public int getMajor()
- major version number of class file
getMethodAt
public Method getMethodAt(int pos)
getMethods
public Method[] getMethods()
getMinor
public int getMinor()
- minor version number of class file
getSuperclassName
public String getSuperclassName()
getSuperclassNameIndex
public int getSuperclassNameIndex()
hashCode
public int hashCode()
Return value as defined by given BCELComparator strategy.
By default return the hashcode of the class name.
java.lang.Object.hashCode()
removeAttribute
public void removeAttribute(Attribute a)
Remove an attribute from this class.
removeField
public void removeField(Field f)
Remove a field to this class.
removeInterface
public void removeInterface(String name)
Remove an interface from this class.
name
- interface to remove (fully qualified name)
removeMethod
public void removeMethod(Method m)
Remove a method from this class.
removeObserver
public void removeObserver(ClassObserver o)
Remove observer for this object.
replaceField
public void replaceField(Field old,
Field new_)
Replace given field with new one. If the old one does not exist
add the new_ field to the class anyway.
replaceMethod
public void replaceMethod(Method old,
Method new_)
Replace given method with new one. If the old one does not exist
add the new_ method to the class anyway.
setClassName
public void setClassName(String name)
setClassNameIndex
public void setClassNameIndex(int class_name_index)
setComparator
public static void setComparator(BCELComparator comparator)
comparator
- Comparison strategy object
setMajor
public void setMajor(int major)
Set major version number of class file, default value is 45 (JDK 1.1)
major
- major version number
setMethodAt
public void setMethodAt(Method method,
int pos)
setMethods
public void setMethods(Method[] methods)
setMinor
public void setMinor(int minor)
Set minor version number of class file, default value is 3 (JDK 1.1)
minor
- minor version number
setSuperclassName
public void setSuperclassName(String name)
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclass_name_index)
update
public void update()
Call notify() method on all observers. This method is not called
automatically whenever the state has changed, but has to be
called by the user after he has finished editing the object.