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
Fields inherited from class AccessFlags
access_flags -
Constructor Summary
ConstructorsConstructorDescriptionClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces) Convenience constructor to set up some important values initially.ClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces, ConstantPoolGen cp) Convenience constructor to set up some important values initially.Constructs a new instance from an existing class. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds an annotation entry to this class.voidAdd an attribute to this class.voidaddEmptyConstructor(int accessFlags) Convenience method.voidAdd a field to this class.voidaddInterface(String name) Add an interface to this class, that is, this class has to implement it.voidAdd a method to this class.voidAdd observer for this object.clone()containsField(String name) Gets the field object with given name, or null.booleanChecks if this class contains the given field.containsMethod(String name, String signature) Gets the method object with given name and signature, or null.booleanReturn value as defined by given BCELComparator strategy.Gets the annotation entries.Gets the attributes.Gets the class name.intGets the class name index.static BCELComparator<ClassGen> Gets the comparison strategy object.Gets the constant pool.Field[]Gets the fields.Gets the file name.String[]Gets the interface names.int[]Gets the interfaces.Gets the (finally) built up Java class object.intgetMajor()Gets major version number of class file.getMethodAt(int pos) Gets the method at the given position.Method[]Gets the methods.intgetMinor()Gets minor version number of class file.Gets the superclass name.intGets the superclass name index.inthashCode()Return value as defined by given BCELComparator strategy.voidRemove an attribute from this class.voidremoveField(Field f) Remove a field to this class.voidremoveInterface(String name) Remove an interface from this class.voidRemove a method from this class.voidRemove observer for this object.voidreplaceField(Field old, Field newField) Replace given field with new one.voidreplaceMethod(Method old, Method newMethod) Replace given method with new one.voidsetClassName(String name) Sets the class name.voidsetClassNameIndex(int classNameIndex) Sets the class name index.static voidsetComparator(BCELComparator<ClassGen> comparator) Sets the comparison strategy object.voidsetConstantPool(ConstantPoolGen constantPool) Sets the constant pool.voidsetMajor(int major) Sets major version number of class file, default value is 45 (JDK 1.1).voidsetMethodAt(Method method, int pos) Sets the method at the given position.voidsetMethods(Method[] methods) Sets the methods.voidsetMinor(int minor) Sets minor version number of class file, default value is 3 (JDK 1.1).voidsetSuperclassName(String name) Sets the superclass name.voidsetSuperclassNameIndex(int superclassNameIndex) Sets the superclass name index.voidupdate()Call notify() method on all observers.Methods inherited from class 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
-
Constructor Details
-
ClassGen
-
ClassGen
public ClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces) Convenience constructor to set up some important values initially.- Parameters:
className- fully qualified class name.superClassName- fully qualified superclass name.fileName- source file name.accessFlags- access qualifiers.interfaces- implemented interfaces.
-
ClassGen
public ClassGen(String className, String superClassName, String fileName, int accessFlags, String[] interfaces, ConstantPoolGen cp) Convenience constructor to set up some important values initially.- Parameters:
className- fully qualified class name.superClassName- fully qualified superclass name.fileName- source file name.accessFlags- access qualifiers.interfaces- implemented interfaces.cp- constant pool to use.
-
-
Method Details
-
getComparator
Gets the comparison strategy object.- Returns:
- Comparison strategy object.
-
setComparator
Sets the comparison strategy object.- Parameters:
comparator- Comparison strategy object.
-
addAnnotationEntry
Adds an annotation entry to this class.- Parameters:
a- the annotation entry to add.
-
addAttribute
Add an attribute to this class.- Parameters:
a- attribute to add.
-
addEmptyConstructor
Convenience method. Add an empty constructor to this class that does nothing but calling super().- Parameters:
accessFlags- rights for constructor.
-
addField
-
addInterface
Add an interface to this class, that is, this class has to implement it.- Parameters:
name- interface to implement (fully qualified class name).
-
addMethod
-
addObserver
Add observer for this object.- Parameters:
o- the observer.
-
clone
-
containsField
Checks if this class contains the given field.- Parameters:
f- the field to check.- Returns:
- true if this class contains the field.
-
containsField
Gets the field object with given name, or null.- Parameters:
name- the field name.- Returns:
- field object with given name, or null.
-
containsMethod
Gets the method object with given name and signature, or null.- Parameters:
name- the method name.signature- the method signature.- Returns:
- method object with given name and signature, or null.
-
equals
-
getAnnotationEntries
Gets the annotation entries.- Returns:
- the annotation entries.
-
getAttributes
-
getClassName
-
getClassNameIndex
-
getConstantPool
-
getFields
-
getFileName
-
getInterfaceNames
-
getInterfaces
-
getJavaClass
Gets the (finally) built up Java class object.- Returns:
- the (finally) built up Java class object.
-
getMajor
Gets major version number of class file.- Returns:
- major version number of class file.
-
getMethodAt
Gets the method at the given position.- Parameters:
pos- the position.- Returns:
- the method at the given position.
-
getMethods
-
getMinor
Gets minor version number of class file.- Returns:
- minor version number of class file.
-
getSuperclassName
-
getSuperclassNameIndex
Gets the superclass name index.- Returns:
- the superclass name index.
-
hashCode
-
removeAttribute
Remove an attribute from this class.- Parameters:
a- attribute to remove.
-
removeField
-
removeInterface
Remove an interface from this class.- Parameters:
name- interface to remove (fully qualified name).
-
removeMethod
Remove a method from this class.- Parameters:
m- method to remove.
-
removeObserver
Remove observer for this object.- Parameters:
o- the observer to remove.
-
replaceField
Replace given field with new one. If the old one does not exist add the new_ field to the class anyway.- Parameters:
old- the old field.newField- the new field.
-
replaceMethod
Replace given method with new one. If the old one does not exist add the newMethod method to the class anyway.- Parameters:
old- the old method.newMethod- the new method.
-
setClassName
-
setClassNameIndex
Sets the class name index.- Parameters:
classNameIndex- the class name index.
-
setConstantPool
Sets the constant pool.- Parameters:
constantPool- the constant pool.
-
setMajor
Sets major version number of class file, default value is 45 (JDK 1.1).- Parameters:
major- major version number.
-
setMethodAt
Sets the method at the given position.- Parameters:
method- the method.pos- the position.
-
setMethods
-
setMinor
Sets minor version number of class file, default value is 3 (JDK 1.1).- Parameters:
minor- minor version number.
-
setSuperclassName
Sets the superclass name.- Parameters:
name- the superclass name.
-
setSuperclassNameIndex
Sets the superclass name index.- Parameters:
superclassNameIndex- the superclass name index.
-
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 they have finished editing the object.
-