Package org.apache.bcel.generic
Class ClassGen
java.lang.Object
org.apache.bcel.classfile.AccessFlags
org.apache.bcel.generic.ClassGen
- All Implemented Interfaces:
Cloneable
Template class for building up a java class. May be initialized with an
existing java class (file).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static BCELComparator
private final List<AnnotationEntryGen>
private String
private int
private ConstantPoolGen
private final String
private int
private int
private List<ClassObserver>
private String
private int
Fields inherited from class org.apache.bcel.classfile.AccessFlags
access_flags
-
Constructor Summary
ConstructorsConstructorDescriptionClassGen
(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces) Convenience constructor to set up some important values initially.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.Initialize with existing class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
Add an attribute to this class.void
addEmptyConstructor
(int access_flags) Convenience method.void
Add a field to this class.void
addInterface
(String name) Add an interface to this class, i.e., this class has to implement it.void
Add a method to this class.void
Add observer for this object.clone()
containsField
(String name) boolean
containsMethod
(String name, String signature) boolean
Return value as defined by given BCELComparator strategy.int
static BCELComparator
Field[]
String[]
int[]
int
getMajor()
getMethodAt
(int pos) Method[]
int
getMinor()
int
int
hashCode()
Return value as defined by given BCELComparator strategy.void
Remove an attribute from this class.void
removeField
(Field f) Remove a field to this class.void
removeInterface
(String name) Remove an interface from this class.void
Remove a method from this class.void
Remove observer for this object.void
replaceField
(Field old, Field new_) Replace given field with new one.void
replaceMethod
(Method old, Method new_) Replace given method with new one.void
setClassName
(String name) void
setClassNameIndex
(int class_name_index) static void
setComparator
(BCELComparator comparator) void
setConstantPool
(ConstantPoolGen constant_pool) void
setMajor
(int major) Set major version number of class file, default value is 45 (JDK 1.1)void
setMethodAt
(Method method, int pos) void
setMethods
(Method[] methods) void
setMinor
(int minor) Set minor version number of class file, default value is 3 (JDK 1.1)void
setSuperclassName
(String name) void
setSuperclassNameIndex
(int superclass_name_index) private AnnotationEntryGen[]
unpackAnnotations
(Attribute[] attrs) Look for attributes representing annotations and unpack them.void
update()
Call notify() method on all observers.Methods inherited from class org.apache.bcel.classfile.AccessFlags
getAccessFlags, getModifiers, isAbstract, isAbstract, isAnnotation, isAnnotation, isEnum, isEnum, isFinal, isFinal, isInterface, isInterface, isNative, isNative, isPrivate, isPrivate, isProtected, isProtected, isPublic, isPublic, isStatic, isStatic, isStrictfp, isStrictfp, isSynchronized, isSynchronized, isSynthetic, isSynthetic, isTransient, isTransient, isVarArgs, isVarArgs, isVolatile, isVolatile, setAccessFlags, setModifiers
-
Field Details
-
class_name
-
super_class_name
-
file_name
-
class_name_index
private int class_name_index -
superclass_name_index
private int superclass_name_index -
major
private int major -
minor
private int minor -
cp
-
field_vec
-
method_vec
-
attribute_vec
-
interface_vec
-
annotation_vec
-
_cmp
-
observers
-
-
Constructor Details
-
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.- Parameters:
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(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces) Convenience constructor to set up some important values initially.- Parameters:
class_name
- fully qualified class namesuper_class_name
- fully qualified superclass namefile_name
- source file nameaccess_flags
- access qualifiersinterfaces
- implemented interfaces
-
ClassGen
Initialize with existing class.- Parameters:
clazz
- JavaClass object (e.g. read from file)
-
-
Method Details
-
unpackAnnotations
Look for attributes representing annotations and unpack them. -
getJavaClass
- Returns:
- the (finally) built up Java class object.
-
addInterface
Add an interface to this class, i.e., this class has to implement it.- Parameters:
name
- interface to implement (fully qualified class name)
-
removeInterface
Remove an interface from this class.- Parameters:
name
- interface to remove (fully qualified name)
-
getMajor
public int getMajor()- Returns:
- major version number of class file
-
setMajor
public void setMajor(int major) Set major version number of class file, default value is 45 (JDK 1.1)- Parameters:
major
- major version number
-
setMinor
public void setMinor(int minor) Set minor version number of class file, default value is 3 (JDK 1.1)- Parameters:
minor
- minor version number
-
getMinor
public int getMinor()- Returns:
- minor version number of class file
-
addAttribute
Add an attribute to this class.- Parameters:
a
- attribute to add
-
addAnnotationEntry
-
addMethod
Add a method to this class.- Parameters:
m
- method to add
-
addEmptyConstructor
public void addEmptyConstructor(int access_flags) Convenience method. Add an empty constructor to this class that does nothing but calling super().- Parameters:
access_flags
- rights for constructor
-
addField
Add a field to this class.- Parameters:
f
- field to add
-
containsField
-
containsField
- Returns:
- field object with given name, or null
-
containsMethod
- Returns:
- method object with given name and signature, or null
-
removeAttribute
Remove an attribute from this class.- Parameters:
a
- attribute to remove
-
removeMethod
Remove a method from this class.- Parameters:
m
- method to remove
-
replaceMethod
Replace given method with new one. If the old one does not exist add the new_ method to the class anyway. -
replaceField
Replace given field with new one. If the old one does not exist add the new_ field to the class anyway. -
removeField
Remove a field to this class.- Parameters:
f
- field to remove
-
getClassName
-
getSuperclassName
-
getFileName
-
setClassName
-
setSuperclassName
-
getMethods
-
setMethods
-
setMethodAt
-
getMethodAt
-
getInterfaceNames
-
getInterfaces
public int[] getInterfaces() -
getFields
-
getAttributes
-
getAnnotationEntries
-
getConstantPool
-
setConstantPool
-
setClassNameIndex
public void setClassNameIndex(int class_name_index) -
setSuperclassNameIndex
public void setSuperclassNameIndex(int superclass_name_index) -
getSuperclassNameIndex
public int getSuperclassNameIndex() -
getClassNameIndex
public int getClassNameIndex() -
addObserver
Add observer for this object. -
removeObserver
Remove observer for this object. -
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. -
clone
-
getComparator
- Returns:
- Comparison strategy object
-
setComparator
- Parameters:
comparator
- Comparison strategy object
-
equals
Return value as defined by given BCELComparator strategy. By default two ClassGen objects are said to be equal when their class names are equal. -
hashCode
public int hashCode()Return value as defined by given BCELComparator strategy. By default return the hashcode of the class name.
-